Search in sources :

Example 1 with Lookup

use of com.alibaba.alink.pipeline.dataproc.Lookup in project Alink by alibaba.

the class Chap24 method c_6.

static void c_6() throws Exception {
    MemSourceBatchOp test_data = new MemSourceBatchOp(new Long[] { 50L }, ITEM_COL);
    new ItemCfSimilarItemsRecommender().setItemCol(ITEM_COL).setRecommCol(RECOMM_COL).setModelData(new AkSourceBatchOp().setFilePath(DATA_DIR + ITEMCF_MODEL_FILE)).transform(test_data).print();
    LocalPredictor recomm_predictor = new ItemCfSimilarItemsRecommender().setItemCol(ITEM_COL).setRecommCol(RECOMM_COL).setK(10).setModelData(new AkSourceBatchOp().setFilePath(DATA_DIR + ITEMCF_MODEL_FILE)).collectLocalPredictor("item_id long");
    LocalPredictor kv_predictor = new Lookup().setSelectedCols(ITEM_COL).setOutputCols("item_name").setModelData(getSourceItems()).setMapKeyCols("item_id").setMapValueCols("title").collectLocalPredictor("item_id long");
    MTable recommResult = (MTable) recomm_predictor.map(Row.of(50L)).getField(1);
    System.out.println(recommResult);
}
Also used : MemSourceBatchOp(com.alibaba.alink.operator.batch.source.MemSourceBatchOp) AkSourceBatchOp(com.alibaba.alink.operator.batch.source.AkSourceBatchOp) MTable(com.alibaba.alink.common.MTable) LocalPredictor(com.alibaba.alink.pipeline.LocalPredictor) Lookup(com.alibaba.alink.pipeline.dataproc.Lookup)

Example 2 with Lookup

use of com.alibaba.alink.pipeline.dataproc.Lookup in project Alink by alibaba.

the class Chap24 method c_5.

static void c_5() throws Exception {
    if (!new File(DATA_DIR + ITEMCF_MODEL_FILE).exists()) {
        getSourceRatings().link(new ItemCfTrainBatchOp().setUserCol(USER_COL).setItemCol(ITEM_COL).setRateCol(RATING_COL)).link(new AkSinkBatchOp().setFilePath(DATA_DIR + ITEMCF_MODEL_FILE));
        BatchOperator.execute();
    }
    MemSourceBatchOp test_data = new MemSourceBatchOp(new Long[] { 1L }, "user_id");
    new ItemCfItemsPerUserRecommender().setUserCol(USER_COL).setRecommCol(RECOMM_COL).setModelData(new AkSourceBatchOp().setFilePath(DATA_DIR + ITEMCF_MODEL_FILE)).transform(test_data).print();
    LocalPredictor recomm_predictor = new ItemCfItemsPerUserRecommender().setUserCol(USER_COL).setRecommCol(RECOMM_COL).setK(20).setModelData(new AkSourceBatchOp().setFilePath(DATA_DIR + ITEMCF_MODEL_FILE)).collectLocalPredictor("user_id long");
    System.out.println(recomm_predictor.getOutputSchema());
    LocalPredictor kv_predictor = new Lookup().setSelectedCols(ITEM_COL).setOutputCols("item_name").setModelData(getSourceItems()).setMapKeyCols("item_id").setMapValueCols("title").collectLocalPredictor("item_id long");
    System.out.println(kv_predictor.getOutputSchema());
    MTable recommResult = (MTable) recomm_predictor.map(Row.of(1L)).getField(1);
    System.out.println(recommResult);
    new Lookup().setSelectedCols(ITEM_COL).setOutputCols("item_name").setModelData(getSourceItems()).setMapKeyCols("item_id").setMapValueCols("title").transform(getSourceRatings().filter("user_id=1 AND rating>4")).select("item_name").orderBy("item_name", 1000).lazyPrint(-1);
    LocalPredictor recomm_predictor_2 = new ItemCfItemsPerUserRecommender().setUserCol(USER_COL).setRecommCol(RECOMM_COL).setK(20).setExcludeKnown(true).setModelData(new AkSourceBatchOp().setFilePath(DATA_DIR + ITEMCF_MODEL_FILE)).collectLocalPredictor("user_id long");
    recommResult = (MTable) recomm_predictor_2.map(Row.of(1L)).getField(1);
    System.out.println(recommResult);
}
Also used : MemSourceBatchOp(com.alibaba.alink.operator.batch.source.MemSourceBatchOp) AkSourceBatchOp(com.alibaba.alink.operator.batch.source.AkSourceBatchOp) MTable(com.alibaba.alink.common.MTable) LocalPredictor(com.alibaba.alink.pipeline.LocalPredictor) Lookup(com.alibaba.alink.pipeline.dataproc.Lookup) AkSinkBatchOp(com.alibaba.alink.operator.batch.sink.AkSinkBatchOp) File(java.io.File) ItemCfTrainBatchOp(com.alibaba.alink.operator.batch.recommendation.ItemCfTrainBatchOp)

Example 3 with Lookup

use of com.alibaba.alink.pipeline.dataproc.Lookup 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

AkSourceBatchOp (com.alibaba.alink.operator.batch.source.AkSourceBatchOp)3 Lookup (com.alibaba.alink.pipeline.dataproc.Lookup)3 MTable (com.alibaba.alink.common.MTable)2 AkSinkBatchOp (com.alibaba.alink.operator.batch.sink.AkSinkBatchOp)2 MemSourceBatchOp (com.alibaba.alink.operator.batch.source.MemSourceBatchOp)2 LocalPredictor (com.alibaba.alink.pipeline.LocalPredictor)2 File (java.io.File)2 EvalRegressionBatchOp (com.alibaba.alink.operator.batch.evaluation.EvalRegressionBatchOp)1 AlsTrainBatchOp (com.alibaba.alink.operator.batch.recommendation.AlsTrainBatchOp)1 ItemCfTrainBatchOp (com.alibaba.alink.operator.batch.recommendation.ItemCfTrainBatchOp)1 TsvSourceBatchOp (com.alibaba.alink.operator.batch.source.TsvSourceBatchOp)1 PipelineModel (com.alibaba.alink.pipeline.PipelineModel)1