layout: global title: Isotonic regression - RDD-based API displayTitle: Regression - RDD-based API license: | Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. See the NOTICE file distributed with this work for additional information regarding copyright ownership. The ASF licenses this file to You under the Apache License, Version 2.0 (the “License”); you may not use this file except in compliance with the License. You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Isotonic regression belongs to the family of regression algorithms. Formally isotonic regression is a problem where given a finite set of real numbers $Y = {y_1, y_2, ..., y_n}$
representing observed responses and $X = {x_1, x_2, ..., x_n}$
the unknown response values to be fitted finding a function that minimizes
\begin{equation} f(x) = \sum_{i=1}^n w_i (y_i - x_i)^2 \end{equation}
with respect to complete order subject to $x_1\le x_2\le ...\le x_n$
where $w_i$
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.
spark.mllib
supports a pool adjacent violators algorithm which uses an approach to parallelizing isotonic regression. The training input is an RDD of tuples of three double values that represent label, feature and weight in this order. Additionally, IsotonicRegression algorithm has one optional parameter called $isotonic$ defaulting to true. This argument specifies if the isotonic regression is isotonic (monotonically increasing) or antitonic (monotonically decreasing).
Training returns an IsotonicRegressionModel that can be used to predict labels for both known and unknown features. The result of isotonic regression is treated as piecewise linear function. The rules for prediction therefore are:
Refer to the IsotonicRegression
Scala docs and IsotonicRegressionModel
Scala docs for details on the API.
{% include_example scala/org/apache/spark/examples/mllib/IsotonicRegressionExample.scala %}
Refer to the IsotonicRegression
Java docs and IsotonicRegressionModel
Java docs for details on the API.
{% include_example java/org/apache/spark/examples/mllib/JavaIsotonicRegressionExample.java %}
Refer to the IsotonicRegression
Python docs and IsotonicRegressionModel
Python docs for more details on the API.
{% include_example python/mllib/isotonic_regression_example.py %}