Skip to content

Commit f80ec1b

Browse files
committed
address comments
1 parent 49600cc commit f80ec1b

File tree

2 files changed

+7
-5
lines changed

2 files changed

+7
-5
lines changed

mllib/src/main/scala/org/apache/spark/mllib/regression/IsotonicRegression.scala

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -143,7 +143,7 @@ object IsotonicRegressionModel extends Loader[IsotonicRegressionModel] {
143143

144144
import org.apache.spark.mllib.util.Loader._
145145

146-
private object SaveLoadV1_0 {
146+
private object SaveLoadV1_0 {
147147

148148
def thisFormatVersion: String = "1.0"
149149

@@ -167,7 +167,7 @@ object IsotonicRegressionModel extends Loader[IsotonicRegressionModel] {
167167
("isotonic" -> isotonic)))
168168
sc.parallelize(Seq(metadata), 1).saveAsTextFile(metadataPath(path))
169169

170-
sqlContext.createDataFrame(boundaries.toList.zip(predictions.toList)
170+
sqlContext.createDataFrame(boundaries.toSeq.zip(predictions)
171171
.map { case (b, p) => Data(b, p) }).saveAsParquetFile(dataPath(path))
172172
}
173173

@@ -177,8 +177,8 @@ object IsotonicRegressionModel extends Loader[IsotonicRegressionModel] {
177177

178178
checkSchema[Data](dataRDD.schema)
179179
val dataArray = dataRDD.select("boundary", "prediction").collect()
180-
val (boundaries, predictions) = dataArray.map {
181-
x => (x.getAs[Double](0), x.getAs[Double](1)) }.toList.unzip
180+
val (boundaries, predictions) = dataArray.map {
181+
x => (x.getDouble(0), x.getDouble(1)) }.toList.sortBy(_._1).unzip
182182
(boundaries.toArray, predictions.toArray)
183183
}
184184
}

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

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,9 @@ class IsotonicRegressionSuite extends FunSuite with MLlibTestSparkContext with M
7575
}
7676

7777
test("model save/load") {
78-
val model = runIsotonicRegression(Seq(1, 2, 3, 1, 6, 17, 16, 17, 18), true)
78+
val boundaries = Array(0.0, 1.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0)
79+
val predictions = Array(1, 2, 2, 6, 16.5, 16.5, 17.0, 18.0)
80+
val model = new IsotonicRegressionModel(boundaries, predictions, true)
7981

8082
val tempDir = Utils.createTempDir()
8183
val path = tempDir.toURI.toString

0 commit comments

Comments
 (0)