Github user mengxr commented on a diff in the pull request:
https://github.com/apache/spark/pull/8937#discussion_r40697270
--- Diff: mllib/src/main/scala/org/apache/spark/ml/recommendation/ALS.scala
---
@@ -315,12 +315,17 @@ class ALS(override val uid: String) extends
Estimator[ALSModel] with ALSParams {
override def fit(dataset: DataFrame): ALSModel = {
import dataset.sqlContext.implicits._
- val ratings = dataset
- .select(col($(userCol)).cast(IntegerType),
col($(itemCol)).cast(IntegerType),
- col($(ratingCol)).cast(FloatType))
- .map { row =>
- Rating(row.getInt(0), row.getInt(1), row.getFloat(2))
+ val ratings = if ($(ratingCol) != "") {
--- End diff --
It might be easier to define the rating col first:
~~~scale
val r = if ($(ratingCol) != "") col($(ratingCol)).cast(FloatType) else
lit(1.0f)
val ratings = dataset.select(..., ..., r).map { row =>
...
}
~~~
---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at [email protected] or file a JIRA ticket
with INFRA.
---
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]