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