Search in sources :

Example 1 with AlsTrainBatchOp

use of com.alibaba.alink.operator.batch.recommendation.AlsTrainBatchOp 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)

Example 2 with AlsTrainBatchOp

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

the class Chap24 method c_4.

static void c_4() throws Exception {
    TsvSourceBatchOp train_set = new TsvSourceBatchOp().setFilePath(DATA_DIR + RATING_TRAIN_FILE).setSchemaStr(RATING_SCHEMA_STRING);
    TsvSourceBatchOp test_set = new TsvSourceBatchOp().setFilePath(DATA_DIR + RATING_TEST_FILE).setSchemaStr(RATING_SCHEMA_STRING);
    if (!new File(DATA_DIR + ALS_MODEL_FILE).exists()) {
        train_set.link(new AlsTrainBatchOp().setUserCol(USER_COL).setItemCol(ITEM_COL).setRateCol(RATING_COL).setLambda(0.1).setRank(10).setNumIter(10)).link(new AkSinkBatchOp().setFilePath(DATA_DIR + ALS_MODEL_FILE));
        BatchOperator.execute();
    }
    new PipelineModel(new AlsRateRecommender().setUserCol(USER_COL).setItemCol(ITEM_COL).setRecommCol(RECOMM_COL).setModelData(new AkSourceBatchOp().setFilePath(DATA_DIR + ALS_MODEL_FILE)), new Lookup().setSelectedCols(ITEM_COL).setOutputCols("item_name").setModelData(getSourceItems()).setMapKeyCols("item_id").setMapValueCols("title")).transform(test_set.filter("user_id=1")).select("user_id, rating, recomm, item_name").orderBy("rating, recomm", 1000).lazyPrint(-1);
    BatchOperator.execute();
    new AlsRateRecommender().setUserCol(USER_COL).setItemCol(ITEM_COL).setRecommCol(RECOMM_COL).setModelData(new AkSourceBatchOp().setFilePath(DATA_DIR + ALS_MODEL_FILE)).transform(test_set).link(new EvalRegressionBatchOp().setLabelCol(RATING_COL).setPredictionCol(RECOMM_COL).lazyPrintMetrics());
    BatchOperator.execute();
}
Also used : AkSourceBatchOp(com.alibaba.alink.operator.batch.source.AkSourceBatchOp) AlsTrainBatchOp(com.alibaba.alink.operator.batch.recommendation.AlsTrainBatchOp) EvalRegressionBatchOp(com.alibaba.alink.operator.batch.evaluation.EvalRegressionBatchOp) Lookup(com.alibaba.alink.pipeline.dataproc.Lookup) AkSinkBatchOp(com.alibaba.alink.operator.batch.sink.AkSinkBatchOp) TsvSourceBatchOp(com.alibaba.alink.operator.batch.source.TsvSourceBatchOp) File(java.io.File) PipelineModel(com.alibaba.alink.pipeline.PipelineModel)

Aggregations

AlsTrainBatchOp (com.alibaba.alink.operator.batch.recommendation.AlsTrainBatchOp)2 BatchOperator (com.alibaba.alink.operator.batch.BatchOperator)1 SplitBatchOp (com.alibaba.alink.operator.batch.dataproc.SplitBatchOp)1 EvalRegressionBatchOp (com.alibaba.alink.operator.batch.evaluation.EvalRegressionBatchOp)1 AlsRateRecommBatchOp (com.alibaba.alink.operator.batch.recommendation.AlsRateRecommBatchOp)1 AkSinkBatchOp (com.alibaba.alink.operator.batch.sink.AkSinkBatchOp)1 AkSourceBatchOp (com.alibaba.alink.operator.batch.source.AkSourceBatchOp)1 CsvSourceBatchOp (com.alibaba.alink.operator.batch.source.CsvSourceBatchOp)1 TsvSourceBatchOp (com.alibaba.alink.operator.batch.source.TsvSourceBatchOp)1 PipelineModel (com.alibaba.alink.pipeline.PipelineModel)1 Lookup (com.alibaba.alink.pipeline.dataproc.Lookup)1 File (java.io.File)1