my code stock.com

aravindh ram

Housing pricing prediction using linear regression
von aravindh ram

Snippet-Optionen

Download: Snippet als housing-pricing-prediction-using-linear-regression.py herunterladen.
Snippet kopieren: Für diese Aktion benötigst du einen kostenlosen my code stock.com Account
Embed-Code : Du findest den Embed-Code für dieses Snippet am Ende der Seite, wenn du es in eine Webseite oder einen Blog einbinden möchtest!

# 
# The data contains the following columns:
# 
# * 'Avg. Area Income': Avg. Income of residents of the city house is located in.
# * 'Avg. Area House Age': Avg Age of Houses in same city
# * 'Avg. Area Number of Rooms': Avg Number of Rooms for Houses in same city
# * 'Avg. Area Number of Bedrooms': Avg Number of Bedrooms for Houses in same city
# * 'Area Population': Population of city house is located in
# * 'Price': Price that the house sold at
# * 'Address': Address for the house




import pandas as pd
import numpy as np
import matplotlib.pyplot as plt
import seaborn as sns
get_ipython().run_line_magic('matplotlib', 'inline')




USAhousing = pd.read_csv('USA_Housing.csv')




USAhousing.head()




USAhousing.info()




USAhousing.describe()




USAhousing.columns




sns.pairplot(USAhousing)




sns.distplot(USAhousing['Price'])




sns.heatmap(USAhousing.corr())





X = USAhousing['Avg. Area Number of Bedrooms'].values.reshape(-1,1)
pd.options.display.float_format = '{:,.2f}'.format
y = USAhousing['Price'].values




from sklearn.model_selection import train_test_split




X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.4, random_state=101)





from sklearn.linear_model import LinearRegression




lm = LinearRegression()




lm.fit(X_train,y_train)




y_train_pred=lm.predict(X_train)
y_test_pred=lm.predict(X_test)




plt.figure(figsize=(12,8))
plt.scatter(y_train_pred, y_train_pred - y_train, c='blue', marker='o', label='Training data')
plt.scatter(y_test_pred, y_test_pred - y_test, c='orange', marker='*', label='Test data')
plt.xlabel('Predicted values')
plt.ylabel('Residuals')
plt.legend(loc='upper left')
plt.xlim([1.593866e+04, 6.593866e+04])
plt.ylim([-5, 35])
plt.show()


print(lm.intercept_)




coeff_df = pd.DataFrame(lm.coef_,X.columns,columns=['Coefficient'])
coeff_df




plt.scatter(y_test,predictions)





sns.distplot((y_test-predictions),bins=50);



from sklearn import metrics




print('MAE:', metrics.mean_absolute_error(y_test, predictions))
print('MSE:', metrics.mean_squared_error(y_test, predictions))
print('RMSE:', np.sqrt(metrics.mean_squared_error(y_test, predictions)))



Jetzt kostenlosen my code stock.com Account anlegen

my code stok.com ist ein kostenloser Dienst zum Speichern und Verwalten von Code-Snippets jeglicher Art und Programmiersprache. Wir bieten dir viele Vorteile für die tägliche Arbeit mit Code-Snippets und der gemeinsamen Arbeit im Team, probier es aus!

Jetzt informieren und registrieren

Du kannst die Höhe des iFrame-Codes beliebig anpassen! Mehr Infos findest du in unserer Embed-Code API Referenz.