18
18
package org .apache .spark .mllib .regression
19
19
20
20
import org .apache .spark .mllib .linalg .Vectors
21
- import org .apache .spark .mllib .regression .MonotonicityConstraint .MonotonicityConstraint .{Antitonic , Isotonic }
22
21
import org .apache .spark .mllib .util .{LocalClusterSparkContext , MLlibTestSparkContext }
23
22
import org .scalatest .{Matchers , FunSuite }
24
23
import WeightedLabeledPointConversions ._
@@ -37,7 +36,7 @@ class IsotonicRegressionSuite
37
36
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()
38
37
39
38
val alg = new PoolAdjacentViolators
40
- val model = alg.run(testRDD, Isotonic )
39
+ val model = alg.run(testRDD, true )
41
40
42
41
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 ))
43
42
}
@@ -46,7 +45,7 @@ class IsotonicRegressionSuite
46
45
val testRDD = sc.parallelize(List [WeightedLabeledPoint ]()).cache()
47
46
48
47
val alg = new PoolAdjacentViolators
49
- val model = alg.run(testRDD, Isotonic )
48
+ val model = alg.run(testRDD, true )
50
49
51
50
model.predictions should be(List ())
52
51
}
@@ -55,7 +54,7 @@ class IsotonicRegressionSuite
55
54
val testRDD = sc.parallelize(generateIsotonicInput(1 )).cache()
56
55
57
56
val alg = new PoolAdjacentViolators
58
- val model = alg.run(testRDD, Isotonic )
57
+ val model = alg.run(testRDD, true )
59
58
60
59
model.predictions should be(generateIsotonicInput(1 ))
61
60
}
@@ -64,7 +63,7 @@ class IsotonicRegressionSuite
64
63
val testRDD = sc.parallelize(generateIsotonicInput(1 , 2 , 3 , 4 , 5 )).cache()
65
64
66
65
val alg = new PoolAdjacentViolators
67
- val model = alg.run(testRDD, Isotonic )
66
+ val model = alg.run(testRDD, true )
68
67
69
68
model.predictions should be(generateIsotonicInput(1 , 2 , 3 , 4 , 5 ))
70
69
}
@@ -73,7 +72,7 @@ class IsotonicRegressionSuite
73
72
val testRDD = sc.parallelize(generateIsotonicInput(5 , 4 , 3 , 2 , 1 )).cache()
74
73
75
74
val alg = new PoolAdjacentViolators
76
- val model = alg.run(testRDD, Isotonic )
75
+ val model = alg.run(testRDD, true )
77
76
78
77
model.predictions should be(generateIsotonicInput(3 , 3 , 3 , 3 , 3 ))
79
78
}
@@ -82,7 +81,7 @@ class IsotonicRegressionSuite
82
81
val testRDD = sc.parallelize(generateIsotonicInput(1 , 2 , 3 , 4 , 2 )).cache()
83
82
84
83
val alg = new PoolAdjacentViolators
85
- val model = alg.run(testRDD, Isotonic )
84
+ val model = alg.run(testRDD, true )
86
85
87
86
model.predictions should be(generateIsotonicInput(1 , 2 , 3 , 3 , 3 ))
88
87
}
@@ -91,7 +90,7 @@ class IsotonicRegressionSuite
91
90
val testRDD = sc.parallelize(generateIsotonicInput(4 , 2 , 3 , 4 , 5 )).cache()
92
91
93
92
val alg = new PoolAdjacentViolators
94
- val model = alg.run(testRDD, Isotonic )
93
+ val model = alg.run(testRDD, true )
95
94
96
95
model.predictions should be(generateIsotonicInput(3 , 3 , 3 , 4 , 5 ))
97
96
}
@@ -100,7 +99,7 @@ class IsotonicRegressionSuite
100
99
val testRDD = sc.parallelize(generateIsotonicInput(- 1 , - 2 , 0 , 1 , - 1 )).cache()
101
100
102
101
val alg = new PoolAdjacentViolators
103
- val model = alg.run(testRDD, Isotonic )
102
+ val model = alg.run(testRDD, true )
104
103
105
104
model.predictions should be(generateIsotonicInput(- 1.5 , - 1.5 , 0 , 0 , 0 ))
106
105
}
@@ -109,7 +108,7 @@ class IsotonicRegressionSuite
109
108
val testRDD = sc.parallelize(generateIsotonicInput(1 , 2 , 3 , 4 , 5 ).reverse).cache()
110
109
111
110
val alg = new PoolAdjacentViolators
112
- val model = alg.run(testRDD, Isotonic )
111
+ val model = alg.run(testRDD, true )
113
112
114
113
model.predictions should be(generateIsotonicInput(1 , 2 , 3 , 4 , 5 ))
115
114
}
@@ -118,7 +117,7 @@ class IsotonicRegressionSuite
118
117
val testRDD = sc.parallelize(generateWeightedIsotonicInput(Seq (1 , 2 , 3 , 4 , 2 ), Seq (1 , 1 , 1 , 1 , 2 ))).cache()
119
118
120
119
val alg = new PoolAdjacentViolators
121
- val model = alg.run(testRDD, Isotonic )
120
+ val model = alg.run(testRDD, true )
122
121
123
122
model.predictions should be(generateWeightedIsotonicInput(Seq (1 , 2 , 2.75 , 2.75 ,2.75 ), Seq (1 , 1 , 1 , 1 , 2 )))
124
123
}
@@ -127,7 +126,7 @@ class IsotonicRegressionSuite
127
126
val testRDD = sc.parallelize(generateWeightedIsotonicInput(Seq (1 , 2 , 3 , 2 , 1 ), Seq (1 , 1 , 1 , 0.1 , 0.1 ))).cache()
128
127
129
128
val alg = new PoolAdjacentViolators
130
- val model = alg.run(testRDD, Isotonic )
129
+ val model = alg.run(testRDD, true )
131
130
132
131
model.predictions.map(p => p.copy(label = round(p.label))) should be
133
132
(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
137
136
val testRDD = sc.parallelize(generateWeightedIsotonicInput(Seq (1 , 2 , 3 , 2 , 1 ), Seq (- 1 , 1 , - 3 , 1 , - 5 ))).cache()
138
137
139
138
val alg = new PoolAdjacentViolators
140
- val model = alg.run(testRDD, Isotonic )
139
+ val model = alg.run(testRDD, true )
141
140
142
141
model.predictions.map(p => p.copy(label = round(p.label))) should be
143
142
(generateWeightedIsotonicInput(Seq (1 , 10 / 6 , 10 / 6 , 10 / 6 , 10 / 6 ), Seq (- 1 , 1 , - 3 , 1 , - 5 )))
@@ -147,7 +146,7 @@ class IsotonicRegressionSuite
147
146
val testRDD = sc.parallelize(generateWeightedIsotonicInput(Seq (1 , 2 , 3 , 2 , 1 ), Seq (0 , 0 , 0 , 1 , 0 ))).cache()
148
147
149
148
val alg = new PoolAdjacentViolators
150
- val model = alg.run(testRDD, Isotonic )
149
+ val model = alg.run(testRDD, true )
151
150
152
151
model.predictions should be(generateWeightedIsotonicInput(Seq (1 , 2 , 2 , 2 , 2 ), Seq (0 , 0 , 0 , 1 , 0 )))
153
152
}
@@ -156,7 +155,7 @@ class IsotonicRegressionSuite
156
155
val testRDD = sc.parallelize(generateIsotonicInput(1 , 2 , 7 , 1 , 2 )).cache()
157
156
158
157
val alg = new PoolAdjacentViolators
159
- val model = alg.run(testRDD, Isotonic )
158
+ val model = alg.run(testRDD, true )
160
159
161
160
model.predict(Vectors .dense(0 )) should be(1 )
162
161
model.predict(Vectors .dense(2 )) should be(2 )
@@ -168,7 +167,7 @@ class IsotonicRegressionSuite
168
167
val testRDD = sc.parallelize(generateIsotonicInput(7 , 5 , 3 , 5 , 1 )).cache()
169
168
170
169
val alg = new PoolAdjacentViolators
171
- val model = alg.run(testRDD, Antitonic )
170
+ val model = alg.run(testRDD, false )
172
171
173
172
model.predict(Vectors .dense(0 )) should be(7 )
174
173
model.predict(Vectors .dense(2 )) should be(5 )
@@ -183,7 +182,7 @@ class IsotonicRegressionSuite
183
182
LabeledPoint (1 , Vectors .dense(2 )))).cache()
184
183
185
184
val alg = new PoolAdjacentViolators
186
- val model = alg.run(testRDD, Isotonic )
185
+ val model = alg.run(testRDD, true )
187
186
188
187
model.predictions should be(generateIsotonicInput(1.5 , 1.5 ))
189
188
}
@@ -201,7 +200,7 @@ class IsotonicRegressionClusterSuite extends FunSuite with LocalClusterSparkCont
201
200
202
201
// If we serialize data directly in the task closure, the size of the serialized task would be
203
202
// greater than 1MB and hence Spark would throw an error.
204
- val model = IsotonicRegression .train(points, Isotonic )
203
+ val model = IsotonicRegression .train(points, true )
205
204
val predictions = model.predict(points.map(_.features))
206
205
}
207
206
}
0 commit comments