use of com.alibaba.alink.operator.batch.recommendation.ItemCfTrainBatchOp 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);
}
Aggregations