【发布时间】:2020-06-28 20:27:30
【问题描述】:
我正在尝试通过此链接在 spark 中复制 ALS 的基本示例:
https://rdrr.io/cran/sparklyr/man/ml_als.html
movies <- data.frame(
user = c(1, 2, 0, 1, 2, 0),
item = c(1, 1, 1, 2, 2, 0),
rating = c(3, 1, 2, 4, 5, 4)
)
movies_tbl <- sdf_copy_to(sc, movies)
model <- ml_als(movies_tbl, rating ~ user + item)
ml_predict(model, movies_tbl)
ml_recommend(model, type = "item", 1)
这段代码对我来说没有问题,问题是我无法操作 预测表中的值具有以下格式:
prediction = ml_recommend(model, type = "item", 1)
> prediction
# Source: spark<?> [?? x 4]
user recommendations item rating
<int> <list> <int> <dbl>
1 1 <list [2]> 2 3.98
2 2 <list [2]> 2 4.86
3 0 <list [2]> 0 3.88
我无法选择得到空响应的列
> prediction$prediction
NULL
也不过滤它们:
> prediction %>%
+ select (user)
Error in select(., user) : object 'user' not found
我什至无法以这种方式从原始数据框中读取数据:
movies_tbl %>%
select (user)
这将返回与上述相同的错误。
【问题讨论】:
-
prediction %>% select(user)和movies_tbl %>% select(user)为我工作。您是否正确执行了sc <- spark_connect(master = "local")并加载了 dplyr?
标签: r apache-spark sparkr sparklyr