Skip to content

Commit

Permalink
[MLlib] Minor: UDF style update.
Browse files Browse the repository at this point in the history
  • Loading branch information
rxin committed Feb 5, 2015
1 parent 84acd08 commit 5e068e3
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,9 @@ class LogisticRegressionModel private[ml] (
1.0 / (1.0 + math.exp(-margin))
} : Double)
val t = map(threshold)
val predictFunction = udf((score: Double) => { if (score > t) 1.0 else 0.0 } : Double)
val predictFunction = udf { score: Double =>
if (score > t) 1.0 else 0.0
}
dataset
.select($"*", scoreFunction(col(map(featuresCol))).as(map(scoreCol)))
.select($"*", predictFunction(col(map(scoreCol))).as(map(predictionCol)))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -129,13 +129,13 @@ class ALSModel private[ml] (

// Register a UDF for DataFrame, and then
// create a new column named map(predictionCol) by running the predict UDF.
val predict = udf((userFeatures: Seq[Float], itemFeatures: Seq[Float]) => {
val predict = udf { (userFeatures: Seq[Float], itemFeatures: Seq[Float]) =>
if (userFeatures != null && itemFeatures != null) {
blas.sdot(k, userFeatures.toArray, 1, itemFeatures.toArray, 1)
} else {
Float.NaN
}
} : Float)
}
dataset
.join(users, dataset(map(userCol)) === users("id"), "left")
.join(items, dataset(map(itemCol)) === items("id"), "left")
Expand Down

0 comments on commit 5e068e3

Please sign in to comment.