text_plain_output_1.png
from sklearn import metrics

from sklearn.linear_model import LinearRegression

from sklearn.model_selection import train_test_split,cross_val_score, cross_val_predict

from sklearn.preprocessing import PolynomialFeatures

from sklearn.tree import DecisionTreeRegressor

import missingno as msno # plotting missing data

import pandas as pd # data processing

import numpy as np
import pandas as pd
import matplotlib.pyplot as plt
import missingno as msno
import seaborn as sns
from sklearn.model_selection import train_test_split, cross_val_score, cross_val_predict
from sklearn import metrics
from sklearn.preprocessing import Imputer
from sklearn.linear_model import LinearRegression
from sklearn.preprocessing import PolynomialFeatures
from sklearn.tree import DecisionTreeRegressor
from sklearn.ensemble import RandomForestRegressor
dataset = pd.read_csv('../input/train.csv')

dataset.isnull().sum()

msno.matrix(df=dataset, figsize=(20, 14), color=(0.5, 0, 0))

dataset = dataset.drop(['Id', 'LotFrontage', 'Alley', 'FireplaceQu', 'PoolQC', 'Fence', 'MiscFeature'], axis=1)
len(dataset.columns)

dataset = dataset.dropna(thresh=70)
msno.matrix(df=dataset, figsize=(20, 14), color=(0.5, 0, 0))

X = dataset.iloc[:, 0:-1]
y = dataset.iloc[:, -1]

X = pd.get_dummies(data=X, columns=['MSZoning', 'Street', 'LotShape', 'LandContour', 'Utilities', 'LotConfig', 'LandSlope', 'Neighborhood', 'Condition1', 'Condition2', 'BldgType', 'HouseStyle', 'RoofStyle', 'RoofMatl', 'Exterior1st', 'Exterior2nd', 'MasVnrType', 'ExterQual', 'ExterCond', 'Foundation', 'BsmtQual', 'BsmtCond', 'BsmtExposure', 'BsmtFinType1', 'BsmtFinType2', 'Heating', 'HeatingQC', 'CentralAir', 'Electrical', 'SaleType', 'SaleCondition', 'KitchenQual', 'Functional', 'GarageType', 'GarageFinish', 'GarageQual', 'GarageCond', 'PavedDrive'], drop_first=True)

X = X.fillna(X.median())

lin_reg = LinearRegression()
lin_reg.fit(X_train, y_train)
y_pred_lr = lin_reg.predict(X_test)
accuracy_lf = metrics.r2_score(y_test, y_pred_lr)
y_pred_kf_lr = cross_val_predict(lin_reg, X, y, cv=10)
accuracy_lf = metrics.r2_score(y, y_pred_kf_lr)

poly_reg = PolynomialFeatures(degree=2)
X_poly = poly_reg.fit_transform(X)
lin_reg_pl = LinearRegression()
y_pred_pl = cross_val_predict(lin_reg_pl, X_poly, y, cv=10)
accuracy_pl = metrics.r2_score(y, y_pred_pl)

dt_regressor = DecisionTreeRegressor(random_state=0)
dt_regressor.fit(X_train, y_train)
y_pred_dt = dt_regressor.predict(X_test)
print('Decision Tree Regression Accuracy: ', dt_regressor.score(X_test, y_test))
y_pred_dt = cross_val_predict(dt_regressor, X, y, cv=10)
accuracy_dt = metrics.r2_score(y, y_pred_dt)
print('Cross-Predicted(KFold) Decision Tree Regression Accuracy: ', accuracy_dt)