Skip to content
Snippets Groups Projects
Commit 2931e89f authored by Yanbo Liang's avatar Yanbo Liang Committed by Xiangrui Meng
Browse files

[SPARK-10736] [ML] Use 1 for all ratings if $(ratingCol) = ""

For some implicit dataset, ratings may not exist in the training data. In this case, we can assume all observed pairs to be positive and treat their ratings as 1. This should happen when users set ```ratingCol``` to an empty string.

Author: Yanbo Liang <ybliang8@gmail.com>

Closes #8937 from yanboliang/spark-10736.
parent 4d5a005b
No related branches found
No related tags found
No related merge requests found
......@@ -315,9 +315,9 @@ class ALS(override val uid: String) extends Estimator[ALSModel] with ALSParams {
override def fit(dataset: DataFrame): ALSModel = {
import dataset.sqlContext.implicits._
val r = if ($(ratingCol) != "") col($(ratingCol)).cast(FloatType) else lit(1.0f)
val ratings = dataset
.select(col($(userCol)).cast(IntegerType), col($(itemCol)).cast(IntegerType),
col($(ratingCol)).cast(FloatType))
.select(col($(userCol)).cast(IntegerType), col($(itemCol)).cast(IntegerType), r)
.map { row =>
Rating(row.getInt(0), row.getInt(1), row.getFloat(2))
}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment