Can you give an example for isotonic regression?

0 votes
Can you give an example of isotonic regression with python code? Thank you:)
Jun 3 in Machine Learning by Vish
83 views

1 answer to this question.

0 votes

Have a look at this one, It's shows linear regression as well as isotonic regression:

import numpy as np
import matplotlib.pyplot as plt
from matplotlib.collections import LineCollection

from sklearn.linear_model import LinearRegression
from sklearn.isotonic import IsotonicRegression
from sklearn.utils import check_random_state

n = 100
x = np.arange(n)
rs = check_random_state(0)
y = rs.randint(-50, 50, size=(n,)) + 50. * np.log1p(np.arange(n))

# #############################################################################
# Fit IsotonicRegression and LinearRegression models

ir = IsotonicRegression()

y_ = ir.fit_transform(x, y)

lr = LinearRegression()
lr.fit(x[:, np.newaxis], y)  # x needs to be 2d for LinearRegression

# #############################################################################
# Plot result

segments = [[[i, y[i]], [i, y_[i]]] for i in range(n)]
lc = LineCollection(segments, zorder=0)
lc.set_array(np.ones(len(y)))
lc.set_linewidths(np.full(n, 0.5))

fig = plt.figure()
plt.plot(x, y, 'r.', markersize=12)
plt.plot(x, y_, 'g.-', markersize=12)
plt.plot(x, lr.predict(x[:, np.newaxis]), 'b-')
plt.gca().add_collection(lc)
plt.legend(('Data', 'Isotonic Fit', 'Linear Fit'), loc='lower right')
plt.title('Isotonic regression')
plt.show()
answered Jun 3 by Mihir

Related Questions In Machine Learning

0 votes
1 answer
0 votes
1 answer

Can an ML model be recreated or retrained?

Of course, your model is retrainable, in ...READ MORE

answered May 13 in Machine Learning by Hemant
31 views
0 votes
1 answer
0 votes
1 answer

Ridge Regression Example

Hey @Nipun, you can try something like ...READ MORE

answered May 22 in Machine Learning by Umer
29 views
+1 vote
2 answers

how can i count the items in a list?

Syntax :            list. count(value) Code: colors = ['red', 'green', ...READ MORE

answered Jul 6 in Python by Neha
• 330 points

edited Jul 8 by Kalgi 278 views
0 votes
1 answer
0 votes
1 answer

What is Isotonic regression?

Isotonic regression builds an increasing approximation of ...READ MORE

answered Jun 3 in Machine Learning by Mohit
126 views