Skip to content

Commit bcac1ac

Browse files
committed
add two tests to ensure {Lasso, Ridge}.setIntercept will throw an exceptions
1 parent a104072 commit bcac1ac

File tree

2 files changed

+12
-6
lines changed

2 files changed

+12
-6
lines changed

mllib/src/test/scala/org/apache/spark/mllib/regression/LassoSuite.scala

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,11 +17,8 @@
1717

1818
package org.apache.spark.mllib.regression
1919

20-
21-
import org.scalatest.BeforeAndAfterAll
2220
import org.scalatest.FunSuite
2321

24-
import org.apache.spark.SparkContext
2522
import org.apache.spark.mllib.util.{LinearDataGenerator, LocalSparkContext}
2623

2724
class LassoSuite extends FunSuite with LocalSparkContext {
@@ -104,4 +101,10 @@ class LassoSuite extends FunSuite with LocalSparkContext {
104101
// Test prediction on Array.
105102
validatePrediction(validationData.map(row => model.predict(row.features)), validationData)
106103
}
104+
105+
test("do not support intercept") {
106+
intercept[UnsupportedOperationException] {
107+
new LassoWithSGD().setIntercept(true)
108+
}
109+
}
107110
}

mllib/src/test/scala/org/apache/spark/mllib/regression/RidgeRegressionSuite.scala

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,14 +17,11 @@
1717

1818
package org.apache.spark.mllib.regression
1919

20-
2120
import org.jblas.DoubleMatrix
22-
import org.scalatest.BeforeAndAfterAll
2321
import org.scalatest.FunSuite
2422

2523
import org.apache.spark.mllib.util.{LinearDataGenerator, LocalSparkContext}
2624

27-
2825
class RidgeRegressionSuite extends FunSuite with LocalSparkContext {
2926

3027
def predictionError(predictions: Seq[Double], input: Seq[LabeledPoint]) = {
@@ -74,4 +71,10 @@ class RidgeRegressionSuite extends FunSuite with LocalSparkContext {
7471
assert(ridgeErr < linearErr,
7572
"ridgeError (" + ridgeErr + ") was not less than linearError(" + linearErr + ")")
7673
}
74+
75+
test("do not support intercept") {
76+
intercept[UnsupportedOperationException] {
77+
new RidgeRegressionWithSGD().setIntercept(true)
78+
}
79+
}
7780
}

0 commit comments

Comments
 (0)