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, 2019 in Machine Learning by Vish
1,434 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, 2019 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, 2019 in Machine Learning by Hemant
193 views
0 votes
1 answer
0 votes
1 answer

Ridge Regression Example

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

answered May 22, 2019 in Machine Learning by Umer
254 views
0 votes
2 answers
+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 7, 2019 in Python by Neha
• 330 points

edited Jul 8, 2019 by Kalgi 2,543 views
0 votes
1 answer
0 votes
1 answer

Python script for linear regression on panda dataframe

Use the following code: from scipy import stats slope, ...READ MORE

answered May 23, 2019 in Machine Learning by Imran
1,002 views
0 votes
1 answer

What is Isotonic regression?

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

answered Jun 3, 2019 in Machine Learning by Mohit
929 views
webinar REGISTER FOR FREE WEBINAR
Send OTP
REGISTER NOW
webinar_success Thank you for registering Join Edureka Meetup community for 100+ Free Webinars each month JOIN MEETUP GROUP