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();
}
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]");
}
Aggregations