Search in sources :

Example 1 with TsvSourceBatchOp

use of com.alibaba.alink.operator.batch.source.TsvSourceBatchOp in project Alink by alibaba.

the class Chap03 method c_2_2.

static void c_2_2() throws Exception {
    new TsvSourceBatchOp().setFilePath(LOCAL_DIR + "u.data").setSchemaStr("user_id long, item_id long, rating float, ts long").firstN(5).print();
    new TextSourceBatchOp().setFilePath(LOCAL_DIR + "iris.scale").firstN(5).print();
    new LibSvmSourceBatchOp().setFilePath(LOCAL_DIR + "iris.scale").firstN(5).lazyPrint(5, "< read by LibSvmSourceBatchOp >").link(new VectorNormalizeBatchOp().setSelectedCol("features")).print();
}
Also used : LibSvmSourceBatchOp(com.alibaba.alink.operator.batch.source.LibSvmSourceBatchOp) VectorNormalizeBatchOp(com.alibaba.alink.operator.batch.dataproc.vector.VectorNormalizeBatchOp) TsvSourceBatchOp(com.alibaba.alink.operator.batch.source.TsvSourceBatchOp) TextSourceBatchOp(com.alibaba.alink.operator.batch.source.TextSourceBatchOp)

Example 2 with TsvSourceBatchOp

use of com.alibaba.alink.operator.batch.source.TsvSourceBatchOp 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

TsvSourceBatchOp (com.alibaba.alink.operator.batch.source.TsvSourceBatchOp)2 VectorNormalizeBatchOp (com.alibaba.alink.operator.batch.dataproc.vector.VectorNormalizeBatchOp)1 EvalRegressionBatchOp (com.alibaba.alink.operator.batch.evaluation.EvalRegressionBatchOp)1 AlsTrainBatchOp (com.alibaba.alink.operator.batch.recommendation.AlsTrainBatchOp)1 AkSinkBatchOp (com.alibaba.alink.operator.batch.sink.AkSinkBatchOp)1 AkSourceBatchOp (com.alibaba.alink.operator.batch.source.AkSourceBatchOp)1 LibSvmSourceBatchOp (com.alibaba.alink.operator.batch.source.LibSvmSourceBatchOp)1 TextSourceBatchOp (com.alibaba.alink.operator.batch.source.TextSourceBatchOp)1 PipelineModel (com.alibaba.alink.pipeline.PipelineModel)1 Lookup (com.alibaba.alink.pipeline.dataproc.Lookup)1 File (java.io.File)1