text_html_output_1.png
from sklearn.linear_model import LinearRegression

from sklearn.model_selection import cross_val_score

import matplotlib.pyplot as plt

import numpy as np # linear algebra

import pandas as pd # data processing, CSV file I/O (e.g. pd.read_csv)

import seaborn as sns

df = pd.read_csv('../input/house-prices-advanced-regression-techniques/train.csv')
df_test = pd.read_csv('../input/house-prices-advanced-regression-techniques/test.csv')
example = pd.read_csv('../input/house-prices-advanced-regression-techniques/sample_submission.csv')
pd.read_csv

df_test.shape

df.shape

df.isna().sum()[df.isna().sum() > 0]

df.corr()[['SalePrice']].sort_values(by='SalePrice', ascending=False)

fig, ax = plt.subplots(figsize=(16,8))
ax= sns.heatmap(df.corr(), cmap ='bwr', linewidths=.5)

df.corr()

sns.set(font_scale=1.5)
plt.tight_layout()

model = LinearRegression()
target = df.loc[:, 'SalePrice']
features = df.loc[:, ['OverallQual', 'GrLivArea']]
model.fit(features, target)
cv_results = cross_val_score(estimator=model, X=features, y=target, cv=10, scoring='neg_root_mean_squared_error')
RMSE_train = np.round(cv_results.mean(), 0)
features_test = df_test.loc[:, ['OverallQual', 'GrLivArea']]
fc = model.predict(features_test)

si_train = RMSE_train / df.loc[:, 'SalePrice'].mean()
r2_train = cross_val_score(estimator=model, X=features, y=target, cv=10, scoring='r2').mean()
print('scatter index training', np.round(si_train, 2))
print('r2 cross validation training', np.round(r2_train, 2))