1818package org .apache .spark .mllib .regression
1919
2020import org .apache .spark .mllib .linalg .Vectors
21- import org .apache .spark .mllib .regression .MonotonicityConstraint .MonotonicityConstraint .{Antitonic , Isotonic }
2221import org .apache .spark .mllib .util .{LocalClusterSparkContext , MLlibTestSparkContext }
2322import org .scalatest .{Matchers , FunSuite }
2423import WeightedLabeledPointConversions ._
@@ -37,7 +36,7 @@ class IsotonicRegressionSuite
3736 val testRDD = sc.parallelize(generateIsotonicInput(1 , 2 , 3 , 3 , 1 , 6 , 7 , 8 , 11 , 9 , 10 , 12 , 14 , 15 , 17 , 16 , 17 , 18 , 19 , 20 )).cache()
3837
3938 val alg = new PoolAdjacentViolators
40- val model = alg.run(testRDD, Isotonic )
39+ val model = alg.run(testRDD, true )
4140
4241 model.predictions should be(generateIsotonicInput(1 , 2 , 7d / 3 , 7d / 3 , 7d / 3 , 6 , 7 , 8 , 10 , 10 , 10 , 12 , 14 , 15 , 16.5 , 16.5 , 17 , 18 , 19 , 20 ))
4342 }
@@ -46,7 +45,7 @@ class IsotonicRegressionSuite
4645 val testRDD = sc.parallelize(List [WeightedLabeledPoint ]()).cache()
4746
4847 val alg = new PoolAdjacentViolators
49- val model = alg.run(testRDD, Isotonic )
48+ val model = alg.run(testRDD, true )
5049
5150 model.predictions should be(List ())
5251 }
@@ -55,7 +54,7 @@ class IsotonicRegressionSuite
5554 val testRDD = sc.parallelize(generateIsotonicInput(1 )).cache()
5655
5756 val alg = new PoolAdjacentViolators
58- val model = alg.run(testRDD, Isotonic )
57+ val model = alg.run(testRDD, true )
5958
6059 model.predictions should be(generateIsotonicInput(1 ))
6160 }
@@ -64,7 +63,7 @@ class IsotonicRegressionSuite
6463 val testRDD = sc.parallelize(generateIsotonicInput(1 , 2 , 3 , 4 , 5 )).cache()
6564
6665 val alg = new PoolAdjacentViolators
67- val model = alg.run(testRDD, Isotonic )
66+ val model = alg.run(testRDD, true )
6867
6968 model.predictions should be(generateIsotonicInput(1 , 2 , 3 , 4 , 5 ))
7069 }
@@ -73,7 +72,7 @@ class IsotonicRegressionSuite
7372 val testRDD = sc.parallelize(generateIsotonicInput(5 , 4 , 3 , 2 , 1 )).cache()
7473
7574 val alg = new PoolAdjacentViolators
76- val model = alg.run(testRDD, Isotonic )
75+ val model = alg.run(testRDD, true )
7776
7877 model.predictions should be(generateIsotonicInput(3 , 3 , 3 , 3 , 3 ))
7978 }
@@ -82,7 +81,7 @@ class IsotonicRegressionSuite
8281 val testRDD = sc.parallelize(generateIsotonicInput(1 , 2 , 3 , 4 , 2 )).cache()
8382
8483 val alg = new PoolAdjacentViolators
85- val model = alg.run(testRDD, Isotonic )
84+ val model = alg.run(testRDD, true )
8685
8786 model.predictions should be(generateIsotonicInput(1 , 2 , 3 , 3 , 3 ))
8887 }
@@ -91,7 +90,7 @@ class IsotonicRegressionSuite
9190 val testRDD = sc.parallelize(generateIsotonicInput(4 , 2 , 3 , 4 , 5 )).cache()
9291
9392 val alg = new PoolAdjacentViolators
94- val model = alg.run(testRDD, Isotonic )
93+ val model = alg.run(testRDD, true )
9594
9695 model.predictions should be(generateIsotonicInput(3 , 3 , 3 , 4 , 5 ))
9796 }
@@ -100,7 +99,7 @@ class IsotonicRegressionSuite
10099 val testRDD = sc.parallelize(generateIsotonicInput(- 1 , - 2 , 0 , 1 , - 1 )).cache()
101100
102101 val alg = new PoolAdjacentViolators
103- val model = alg.run(testRDD, Isotonic )
102+ val model = alg.run(testRDD, true )
104103
105104 model.predictions should be(generateIsotonicInput(- 1.5 , - 1.5 , 0 , 0 , 0 ))
106105 }
@@ -109,7 +108,7 @@ class IsotonicRegressionSuite
109108 val testRDD = sc.parallelize(generateIsotonicInput(1 , 2 , 3 , 4 , 5 ).reverse).cache()
110109
111110 val alg = new PoolAdjacentViolators
112- val model = alg.run(testRDD, Isotonic )
111+ val model = alg.run(testRDD, true )
113112
114113 model.predictions should be(generateIsotonicInput(1 , 2 , 3 , 4 , 5 ))
115114 }
@@ -118,7 +117,7 @@ class IsotonicRegressionSuite
118117 val testRDD = sc.parallelize(generateWeightedIsotonicInput(Seq (1 , 2 , 3 , 4 , 2 ), Seq (1 , 1 , 1 , 1 , 2 ))).cache()
119118
120119 val alg = new PoolAdjacentViolators
121- val model = alg.run(testRDD, Isotonic )
120+ val model = alg.run(testRDD, true )
122121
123122 model.predictions should be(generateWeightedIsotonicInput(Seq (1 , 2 , 2.75 , 2.75 ,2.75 ), Seq (1 , 1 , 1 , 1 , 2 )))
124123 }
@@ -127,7 +126,7 @@ class IsotonicRegressionSuite
127126 val testRDD = sc.parallelize(generateWeightedIsotonicInput(Seq (1 , 2 , 3 , 2 , 1 ), Seq (1 , 1 , 1 , 0.1 , 0.1 ))).cache()
128127
129128 val alg = new PoolAdjacentViolators
130- val model = alg.run(testRDD, Isotonic )
129+ val model = alg.run(testRDD, true )
131130
132131 model.predictions.map(p => p.copy(label = round(p.label))) should be
133132 (generateWeightedIsotonicInput(Seq (1 , 2 , 3.3 / 1.2 , 3.3 / 1.2 , 3.3 / 1.2 ), Seq (1 , 1 , 1 , 0.1 , 0.1 )))
@@ -137,7 +136,7 @@ class IsotonicRegressionSuite
137136 val testRDD = sc.parallelize(generateWeightedIsotonicInput(Seq (1 , 2 , 3 , 2 , 1 ), Seq (- 1 , 1 , - 3 , 1 , - 5 ))).cache()
138137
139138 val alg = new PoolAdjacentViolators
140- val model = alg.run(testRDD, Isotonic )
139+ val model = alg.run(testRDD, true )
141140
142141 model.predictions.map(p => p.copy(label = round(p.label))) should be
143142 (generateWeightedIsotonicInput(Seq (1 , 10 / 6 , 10 / 6 , 10 / 6 , 10 / 6 ), Seq (- 1 , 1 , - 3 , 1 , - 5 )))
@@ -147,7 +146,7 @@ class IsotonicRegressionSuite
147146 val testRDD = sc.parallelize(generateWeightedIsotonicInput(Seq (1 , 2 , 3 , 2 , 1 ), Seq (0 , 0 , 0 , 1 , 0 ))).cache()
148147
149148 val alg = new PoolAdjacentViolators
150- val model = alg.run(testRDD, Isotonic )
149+ val model = alg.run(testRDD, true )
151150
152151 model.predictions should be(generateWeightedIsotonicInput(Seq (1 , 2 , 2 , 2 , 2 ), Seq (0 , 0 , 0 , 1 , 0 )))
153152 }
@@ -156,7 +155,7 @@ class IsotonicRegressionSuite
156155 val testRDD = sc.parallelize(generateIsotonicInput(1 , 2 , 7 , 1 , 2 )).cache()
157156
158157 val alg = new PoolAdjacentViolators
159- val model = alg.run(testRDD, Isotonic )
158+ val model = alg.run(testRDD, true )
160159
161160 model.predict(Vectors .dense(0 )) should be(1 )
162161 model.predict(Vectors .dense(2 )) should be(2 )
@@ -168,7 +167,7 @@ class IsotonicRegressionSuite
168167 val testRDD = sc.parallelize(generateIsotonicInput(7 , 5 , 3 , 5 , 1 )).cache()
169168
170169 val alg = new PoolAdjacentViolators
171- val model = alg.run(testRDD, Antitonic )
170+ val model = alg.run(testRDD, false )
172171
173172 model.predict(Vectors .dense(0 )) should be(7 )
174173 model.predict(Vectors .dense(2 )) should be(5 )
@@ -183,7 +182,7 @@ class IsotonicRegressionSuite
183182 LabeledPoint (1 , Vectors .dense(2 )))).cache()
184183
185184 val alg = new PoolAdjacentViolators
186- val model = alg.run(testRDD, Isotonic )
185+ val model = alg.run(testRDD, true )
187186
188187 model.predictions should be(generateIsotonicInput(1.5 , 1.5 ))
189188 }
@@ -201,7 +200,7 @@ class IsotonicRegressionClusterSuite extends FunSuite with LocalClusterSparkCont
201200
202201 // If we serialize data directly in the task closure, the size of the serialized task would be
203202 // greater than 1MB and hence Spark would throw an error.
204- val model = IsotonicRegression .train(points, Isotonic )
203+ val model = IsotonicRegression .train(points, true )
205204 val predictions = model.predict(points.map(_.features))
206205 }
207206}
0 commit comments