Search in sources :

Example 1 with AlsRateRecommBatchOp

use of com.alibaba.alink.operator.batch.recommendation.AlsRateRecommBatchOp in project Alink by alibaba.

the class ALSExample method main.

public static void main(String[] args) throws Exception {
    String url = "https://alink-release.oss-cn-beijing.aliyuncs.com/data-files/movielens_ratings.csv";
    String schema = "userid bigint, movieid bigint, rating double, timestamp string";
    BatchOperator data = new CsvSourceBatchOp().setFilePath(url).setSchemaStr(schema);
    SplitBatchOp spliter = new SplitBatchOp().setFraction(0.8);
    spliter.linkFrom(data);
    BatchOperator trainData = spliter;
    BatchOperator testData = spliter.getSideOutput(0);
    AlsTrainBatchOp als = new AlsTrainBatchOp().setUserCol("userid").setItemCol("movieid").setRateCol("rating").setNumIter(10).setRank(10).setLambda(0.1);
    BatchOperator model = als.linkFrom(trainData);
    AlsRateRecommBatchOp predictor = new AlsRateRecommBatchOp().setUserCol("userid").setItemCol("movieid").setRecommCol("prediction_result");
    BatchOperator preditionResult = predictor.linkFrom(model, testData).select("rating, prediction_result");
    preditionResult.print();
}
Also used : AlsTrainBatchOp(com.alibaba.alink.operator.batch.recommendation.AlsTrainBatchOp) AlsRateRecommBatchOp(com.alibaba.alink.operator.batch.recommendation.AlsRateRecommBatchOp) BatchOperator(com.alibaba.alink.operator.batch.BatchOperator) CsvSourceBatchOp(com.alibaba.alink.operator.batch.source.CsvSourceBatchOp) SplitBatchOp(com.alibaba.alink.operator.batch.dataproc.SplitBatchOp)

Aggregations

BatchOperator (com.alibaba.alink.operator.batch.BatchOperator)1 SplitBatchOp (com.alibaba.alink.operator.batch.dataproc.SplitBatchOp)1 AlsRateRecommBatchOp (com.alibaba.alink.operator.batch.recommendation.AlsRateRecommBatchOp)1 AlsTrainBatchOp (com.alibaba.alink.operator.batch.recommendation.AlsTrainBatchOp)1 CsvSourceBatchOp (com.alibaba.alink.operator.batch.source.CsvSourceBatchOp)1