Skip to content

Commit b7f9d11

Browse files
authored
Merge pull request #121 from adi271001/Isotonic-Regression
Isotonic regression
2 parents 769688c + c5905e6 commit b7f9d11

File tree

1 file changed

+23
-0
lines changed

1 file changed

+23
-0
lines changed
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
from sklearn.isotonic import IsotonicRegression
2+
import matplotlib.pyplot as plt
3+
from matplotlib.collections import LineCollection
4+
5+
ir = IsotonicRegression() # create an instance of the IsotonicRegression class
6+
7+
# Fit isotonic regression model
8+
y_ir = ir.fit_transform(x, y) # fit the model and transform the data
9+
print('Isotonic Regression Predictions :\n',y_ir)
10+
11+
# Create LineCollection for the isotonic regression line
12+
lines = [[[i, y_ir[i]] for i in range(n)]]
13+
14+
# Line to measure the difference between actual and target value
15+
lc = LineCollection(lines)
16+
17+
plt.plot(x, y_ir, '-', markersize=10, label='isotonic regression')
18+
19+
plt.gca().add_collection(lc)
20+
plt.legend() # add a legend
21+
22+
plt.title("Isotonic Regression")
23+
plt.show()

0 commit comments

Comments
 (0)