Java 类名:com.alibaba.alink.pipeline.recommendation.UserCfUsersPerItemRecommender
Python 类名:UserCfUsersPerItemRecommender
用UserCF模型 为item推荐user list。
名称 | 中文名称 | 描述 | 类型 | 是否必须? | 取值范围 | 默认值 |
---|---|---|---|---|---|---|
itemCol | Item列列名 | Item列列名 | String | ✓ | ||
recommCol | 推荐结果列名 | 推荐结果列名 | String | ✓ | ||
excludeKnown | 排除已知的关联 | 推荐结果中是否排除训练数据中已知的关联 | Boolean | false | ||
initRecommCol | 初始推荐列列名 | 初始推荐列列名 | String | 所选列类型为 [M_TABLE, STRING] | null | |
k | 推荐TOP数量 | 推荐TOP数量 | Integer | 10 | ||
modelFilePath | 模型的文件路径 | 模型的文件路径 | String | null | ||
overwriteSink | 是否覆写已有数据 | 是否覆写已有数据 | Boolean | false | ||
reservedCols | 算法保留列名 | 算法保留列 | String[] | null | ||
numThreads | 组件多线程线程个数 | 组件多线程线程个数 | Integer | 1 | ||
modelStreamFilePath | 模型流的文件路径 | 模型流的文件路径 | String | null | ||
modelStreamScanInterval | 扫描模型路径的时间间隔 | 描模型路径的时间间隔,单位秒 | Integer | 10 | ||
modelStreamStartTime | 模型流的起始时间 | 模型流的起始时间。默认从当前时刻开始读。使用yyyy-mm-dd hh:mm:ss.fffffffff格式,详见Timestamp.valueOf(String s) | String | null |
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 = UserCfUsersPerItemRecommender()\ .setItemCol("item")\ .setReservedCols(["item"])\ .setK(1)\ .setRecommCol("prediction_result")\ .setModelData(model) predictor.transform(data).print()
import org.apache.flink.types.Row; import com.alibaba.alink.operator.batch.BatchOperator; import com.alibaba.alink.operator.batch.recommendation.UserCfTrainBatchOp; import com.alibaba.alink.operator.batch.source.MemSourceBatchOp; import com.alibaba.alink.pipeline.recommendation.UserCfUsersPerItemRecommender; import org.junit.Test; import java.util.Arrays; import java.util.List; public class UserCfUsersPerItemRecommenderTest { @Test public void testUserCfUsersPerItemRecommender() 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); UserCfUsersPerItemRecommender predictor = new UserCfUsersPerItemRecommender() .setItemCol("item") .setReservedCols("item") .setK(1) .setRecommCol("prediction_result") .setModelData(model); predictor.transform(data).print(); } }
item | prediction_result |
---|---|
1 | {“user”:“[1]”,“score”:“[0.23046638387921276]”} |
2 | {“user”:“[4]”,“score”:“[0.2458308094711603]”} |
3 | {“user”:“[4]”,“score”:“[0.1843731071033702]”} |
1 | {“user”:“[1]”,“score”:“[0.23046638387921276]”} |
2 | {“user”:“[4]”,“score”:“[0.2458308094711603]”} |
3 | {“user”:“[4]”,“score”:“[0.1843731071033702]”} |