Java 类名:com.alibaba.alink.operator.batch.recommendation.UserCfRateRecommBatchOp
Python 类名:UserCfRateRecommBatchOp
UserCF 打分是使用UserCF模型,于预测user对item的评分。
名称 | 中文名称 | 描述 | 类型 | 是否必须? | 取值范围 | 默认值 |
---|---|---|---|---|---|---|
itemCol | Item列列名 | Item列列名 | String | ✓ | ||
recommCol | 推荐结果列名 | 推荐结果列名 | String | ✓ | ||
userCol | User列列名 | User列列名 | String | ✓ | ||
reservedCols | 算法保留列名 | 算法保留列 | String[] | null | ||
numThreads | 组件多线程线程个数 | 组件多线程线程个数 | Integer | 1 |
from pyalink.alink import * import pandas as pd useLocalEnv(1) df_data = pd.DataFrame([ [1, 1, 0.6], [2, 2, 0.8], [2, 3, 0.6], [4, 1, 0.6], [4, 2, 0.3], [4, 3, 0.4], ]) data = BatchOperator.fromDataframe(df_data, schemaStr='user bigint, item bigint, rating double') model = UserCfTrainBatchOp()\ .setUserCol("user")\ .setItemCol("item")\ .setRateCol("rating").linkFrom(data); predictor = UserCfRateRecommBatchOp()\ .setUserCol("user")\ .setItemCol("item")\ .setRecommCol("prediction_result"); predictor.linkFrom(model, data).print()
import org.apache.flink.types.Row; import com.alibaba.alink.operator.batch.BatchOperator; import com.alibaba.alink.operator.batch.recommendation.UserCfRateRecommBatchOp; import com.alibaba.alink.operator.batch.recommendation.UserCfTrainBatchOp; import com.alibaba.alink.operator.batch.source.MemSourceBatchOp; import org.junit.Test; import java.util.Arrays; import java.util.List; public class UserCfRateRecommBatchOpTest { @Test public void testUserCfRateRecommBatchOp() throws Exception { List <Row> df_data = Arrays.asList( Row.of(1, 1, 0.6), Row.of(2, 2, 0.8), Row.of(2, 3, 0.6), Row.of(4, 1, 0.6), Row.of(4, 2, 0.3), Row.of(4, 3, 0.4) ); BatchOperator <?> data = new MemSourceBatchOp(df_data, "user int, item int, rating double"); BatchOperator <?> model = new UserCfTrainBatchOp() .setUserCol("user") .setItemCol("item") .setRateCol("rating").linkFrom(data); BatchOperator <?> predictor = new UserCfRateRecommBatchOp() .setUserCol("user") .setItemCol("item") .setRecommCol("prediction_result"); predictor.linkFrom(model, data).print(); } }
user | item | rating | prediction_result |
---|---|---|---|
1 | 1 | 0.6000 | 0.6000 |
2 | 2 | 0.8000 | 0.3000 |
2 | 3 | 0.6000 | 0.4000 |
4 | 1 | 0.6000 | 0.6000 |
4 | 2 | 0.3000 | 0.8000 |
4 | 3 | 0.4000 | 0.6000 |