Search in sources :

Example 1 with ItemCfItemsPerUserRecommender

use of com.alibaba.alink.pipeline.recommendation.ItemCfItemsPerUserRecommender in project Alink by alibaba.

the class ItemCfTrainBatchOpTest method testPearson.

@Test
public void testPearson() {
    BatchOperator<?> emptyRate = BatchOperator.fromTable(MLEnvironmentFactory.getDefault().createBatchTable(rows, new String[] { "user", "item", "rate" }));
    BatchOperator<?> spliter = new LeaveTopKObjectOutBatchOp().setK(2).setObjectCol("item").setRateCol("rate").setOutputCol("label").setGroupCol("user");
    BatchOperator<?> test = spliter.linkFrom(emptyRate);
    BatchOperator<?> train = spliter.getSideOutput(0);
    ItemCfTrainBatchOp trainBatchOp = new ItemCfTrainBatchOp().setSimilarityType("PEARSON").setUserCol("user").setItemCol("item").setRateCol("rate").linkFrom(train);
    ItemCfItemsPerUserRecommender recommender = new ItemCfItemsPerUserRecommender().setUserCol("user").setRecommCol("recomm").setModelData(trainBatchOp);
    PipelineModel model = new Pipeline().add(recommender).fit(trainBatchOp);
    model.transform(test).collect();
}
Also used : ItemCfItemsPerUserRecommender(com.alibaba.alink.pipeline.recommendation.ItemCfItemsPerUserRecommender) PipelineModel(com.alibaba.alink.pipeline.PipelineModel) Pipeline(com.alibaba.alink.pipeline.Pipeline) Test(org.junit.Test)

Example 2 with ItemCfItemsPerUserRecommender

use of com.alibaba.alink.pipeline.recommendation.ItemCfItemsPerUserRecommender in project Alink by alibaba.

the class ItemCfTrainBatchOpTest method testLocalPredictor.

@Test
public void testLocalPredictor() throws Exception {
    BatchOperator<?> data = BatchOperator.fromTable(MLEnvironmentFactory.getDefault().createBatchTable(rows1, new String[] { "user", "item", "rate" }));
    ItemCfTrainBatchOp trainBatchOp = new ItemCfTrainBatchOp().setSimilarityType("COSINE").setUserCol("user").setItemCol("item").setRateCol("rate").linkFrom(data);
    ItemCfItemsPerUserRecommender recommender = new ItemCfItemsPerUserRecommender().setUserCol("user").setRecommCol("recomm").setModelData(trainBatchOp);
    Row res = recommender.collectLocalPredictor("user long, item long, rate double").map(rows1[0]);
    List<Row> rows = ((MTable) res.getField(3)).getRows();
    List<Long> recomm = new ArrayList<>(rows.size());
    for (Row row : rows) {
        recomm.add((long) row.getField(0));
    }
    Assert.assertEquals(JsonConverter.toJson(recomm), "[2,1,3]");
}
Also used : MTable(com.alibaba.alink.common.MTable) ArrayList(java.util.ArrayList) Row(org.apache.flink.types.Row) ItemCfItemsPerUserRecommender(com.alibaba.alink.pipeline.recommendation.ItemCfItemsPerUserRecommender) Test(org.junit.Test)

Aggregations

ItemCfItemsPerUserRecommender (com.alibaba.alink.pipeline.recommendation.ItemCfItemsPerUserRecommender)2 Test (org.junit.Test)2 MTable (com.alibaba.alink.common.MTable)1 Pipeline (com.alibaba.alink.pipeline.Pipeline)1 PipelineModel (com.alibaba.alink.pipeline.PipelineModel)1 ArrayList (java.util.ArrayList)1 Row (org.apache.flink.types.Row)1