Isotonic regression

Isotonic regression

belongs to the family of regression algorithms. Formally isotonic regression is a problem where given a finite set of real numbers Y=y1,y2,...,yn representing observed responses and X=x1,x2,...,xn the unknown response values to be fitted finding a function that minimizes
with respect to complete order subject to x1≀x2≀...≀xn where wi are positive weights. The resulting function is called isotonic regression and it is unique. It can be viewed as least squares problem under order restriction. Essentially isotonic regression is a monotonic function best fitting the original data points.
1
import org.apache.spark.ml.regression.IsotonicRegression
2
// Loads data.
3
val dataset = spark.read.format("libsvm")
4
.load("file:///opt/spark/data/mllib/sample_libsvm_data.txt")
5
// Trains an isotonic regression model.
6
val ir = new IsotonicRegression()
7
val model = ir.fit(dataset)
8
println(s"Boundaries in increasing order: ${model.boundaries}n")
9
println(s"Predictions associated with the boundaries: ${model.predictions}n")
10
// Makes predictions.
11
model.transform(dataset).show(3)
12
​
13
/*
14
Output:
15
Boundaries in increasing order: [0.0,0.0]n
16
Predictions associated with the boundaries: [0.0,1.0]n
17
+-----+--------------------+----------+
18
|label| features|prediction|
19
+-----+--------------------+----------+
20
| 0.0|(692,[127,128,129...| 0.0|
21
| 1.0|(692,[158,159,160...| 0.0|
22
| 1.0|(692,[124,125,126...| 0.0|
23
+-----+--------------------+----------+
24
only showing top 3 rows
25
​
26
​
27
*/
Copied!
​
Last modified 1yr ago
Copy link