Isotonic regression
Last updated
Last updated
import org.apache.spark.ml.regression.IsotonicRegression
// Loads data.
val dataset = spark.read.format("libsvm")
.load("file:///opt/spark/data/mllib/sample_libsvm_data.txt")
// Trains an isotonic regression model.
val ir = new IsotonicRegression()
val model = ir.fit(dataset)
println(s"Boundaries in increasing order: ${model.boundaries}n")
println(s"Predictions associated with the boundaries: ${model.predictions}n")
// Makes predictions.
model.transform(dataset).show(3)
/*
Output:
Boundaries in increasing order: [0.0,0.0]n
Predictions associated with the boundaries: [0.0,1.0]n
+-----+--------------------+----------+
|label| features|prediction|
+-----+--------------------+----------+
| 0.0|(692,[127,128,129...| 0.0|
| 1.0|(692,[158,159,160...| 0.0|
| 1.0|(692,[124,125,126...| 0.0|
+-----+--------------------+----------+
only showing top 3 rows
*/