IoT Task4 21BEC0384
IoT Task4 21BEC0384
df=pd.read_csv('/content/drive/MyDrive/Housing.csv')
df.columns
print(df.head())
x=df['price']
y=df['area']
x=x.values.reshape(-1,1)
print(x_train.shape)
print(x_test.shape)
model = LinearRegression()
model.fit(x_train,y_train)
predictions = model.predict(x_test)
print(predictions)
poly = PolynomialFeatures(degree=4)
X_poly = poly.fit_transform(x)
poly.fit(X_poly, y)
lin2 = LinearRegression()
lin2.fit(X_poly, y)
predictions = model.predict(x_test)
print(predictions)
plt.scatter(x, y, color='blue')
plt.plot(x, lin2.predict(poly.fit_transform(x)),
color='red')
plt.title('Polynomial Regression')
plt.xlabel('Price')
plt.ylabel('Area')
plt.show()
pred2 = 78895
pred2array = np.array([[pred2]])
lin2.predict(poly.fit_transform(pred2array))
x = df[['price', 'area']].values
y = df[['parking']].values
new_data = np.array([[12250000,8960]])
new_data_poly = poly.transform(new_data)
predicted_price = model.predict(new_data_poly)
print(predicted_price)
Outputs
Verification
Reference
Housing Price Prediction ( Linear Regression ) (kaggle.com)