Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import numpy as np
- import matplotlib.pyplot as plt
- import random, time, math
- aa = np.array(range(10))
- X = aa.reshape(len(aa), 1)
- y = np.array(range(10))
- print('\n', X, '\n\n', y)
- # regression
- from sklearn import linear_model
- regr = linear_model.LinearRegression()
- regr.fit(X, y)
- print('\n', regr.coef_, regr.intercept_)
- regr.fit(X, y*2)
- print('\n', regr.coef_, regr.intercept_)
- regr.fit(X, y+10)
- print('\n', regr.coef_, regr.intercept_)
- np.dot(X, regr.coef_)
- X = np.array([10, 20, 30, 40]).reshape(4, 1)
- np.dot(X, regr.coef_)
- regr.predict(90)
- # what happens with squaring
- regr.fit(X, y**2)
- print('\n', regr.coef_)
- y2 = np.dot(X, regr.coef_)
- # y2 is array([ 0., 9., 18., 27., 36., 45., 54., 63., 72., 81.])
- # So lets plot the original and the fit (green)
- plt.plot(aa, y**2), plt.plot(aa, y2), plt.show()
Add Comment
Please, Sign In to add comment