Created
February 11, 2019 09:54
-
-
Save nithyadurai87/b7d3bf7733b5d4a8d2c8b2d1b8dcb531 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import pandas as pd | |
import matplotlib.pyplot as plt | |
from sklearn.linear_model import LinearRegression | |
from sklearn.preprocessing import PolynomialFeatures | |
X = pd.DataFrame([100,200,300,400,500,600],columns=['sqft']) | |
y = pd.DataFrame([543543,34543543,35435345,34534,34534534,345345],columns=['Price']) | |
lin = LinearRegression() | |
lin.fit(X, y) | |
plt.scatter(X, y, color = 'blue') | |
plt.plot(X, lin.predict(X), color = 'red') | |
plt.title('Linear Regression') | |
plt.xlabel('sqft') | |
plt.ylabel('Price') | |
plt.show() | |
for i in [2,3,4,5]: | |
poly = PolynomialFeatures(degree = i) | |
X_poly = poly.fit_transform(X) | |
poly.fit(X_poly, y) | |
lin2 = LinearRegression() | |
lin2.fit(X_poly, y) | |
plt.scatter(X, y, color = 'blue') | |
plt.plot(X, lin2.predict(poly.fit_transform(X)), color = 'red') | |
plt.title('Polynomial Regression') | |
plt.xlabel('sqft') | |
plt.ylabel('Price') | |
plt.show() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment