Skip to content
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
TST: classifier doesn't have weightCol
  • Loading branch information
facaiy committed Jul 19, 2017
commit 9ba0e2be0b6bb0b8012c6003984c307f569dda1e
Original file line number Diff line number Diff line change
Expand Up @@ -158,9 +158,12 @@ class OneVsRestSuite extends SparkFunSuite with MLlibTestSparkContext with Defau

test("SPARK-21306: OneVsRest should support setWeightCol") {
val dataset2 = dataset.withColumn("weight", lit(1))
// classifier inherits hasWeightCol
val ova = new OneVsRest().setWeightCol("weight").setClassifier(new LogisticRegression())
val ovaModel = ova.fit(dataset2)
assert(ovaModel !== null)
assert(ova.fit(dataset2) !== null)
// classifier doesn't inherit hasWeightCol
val ova2 = new OneVsRest().setWeightCol("weight").setClassifier(new DecisionTreeClassifier())
assert(ova2.fit(dataset2) !== null)
}

test("OneVsRest.copy and OneVsRestModel.copy") {
Expand Down
7 changes: 7 additions & 0 deletions python/pyspark/ml/tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -1260,11 +1260,18 @@ def test_support_for_weightCol(self):
(1.0, Vectors.sparse(2, [], []), 1.0),
(2.0, Vectors.dense(0.5, 0.5), 1.0)],
["label", "features", "weight"])
# classifier inherits hasWeightCol
lr = LogisticRegression(maxIter=5, regParam=0.01)
ovr = OneVsRest(classifier=lr, weightCol="weight")
self.assertIsNotNone(ovr.fit(df))
ovr2 = OneVsRest(classifier=lr).setWeightCol("weight")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Minor: We can remove test of ovr2 and ovr4, setting param in different way will run the same code at backend.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

cleaned.

self.assertIsNotNone(ovr2.fit(df))
# classifier doesn't inherit hasWeightCol
dt = DecisionTreeClassifier()
ovr3 = OneVsRest(classifier=dt, weightCol="weight")
self.assertIsNotNone(ovr3.fit(df))
ovr4 = OneVsRest(classifier=dt).setWeightCol("weight")
self.assertIsNotNone(ovr4.fit(df))


class HashingTFTest(SparkSessionTestCase):
Expand Down