Github user sethah commented on a diff in the pull request:
https://github.com/apache/spark/pull/18151#discussion_r119472374
--- Diff:
mllib/src/test/scala/org/apache/spark/ml/classification/LinearSVCSuite.scala ---
@@ -127,6 +127,27 @@ class LinearSVCSuite extends SparkFunSuite with
MLlibTestSparkContext with Defau
MLTestingUtils.checkCopyAndUids(lsvc, model)
}
+ test("LinearSVC threshold acts on rawPrediction") {
+ val lsvc =
+ new LinearSVCModel(uid = "myLSVCM", coefficients =
Vectors.dense(1.0), intercept = 0.0)
+ val df = spark.createDataFrame(Seq(
+ (1, Vectors.dense(1e-7)),
+ (0, Vectors.dense(0.0)),
+ (-1, Vectors.dense(-1e-7)))).toDF("id", "features")
+
+ def checkResults(threshold: Double, expected: Set[(Int, Double)]):
Unit = {
+ lsvc.setThreshold(threshold)
+ val results = lsvc.transform(df).select("id", "prediction").collect()
+ .map(r => (r.getInt(0), r.getDouble(1)))
+ .toSet
+ assert(results === expected, s"Failed for threshold = $threshold")
+ }
+
+ checkResults(0.0, Set((1, 1.0), (0, 0.0), (-1, 0.0)))
--- End diff --
It might be a good idea to additionally test the other code path, by
calling `lsvc.set(lsvc.rawPrediction, "")`. The way it is, we don't know if
`predict` works correctly (this is done in the logistic regression suite).
---
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]