image_output_1.png
from sklearn.linear_model import LinearRegression

from sklearn.metrics import mean_squared_error,mean_absolute_error

from sklearn.model_selection import train_test_split

import numpy as np # linear algebra

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

import matplotlib.pyplot as plt
import seaborn as sns
house_df = pd.read_csv('../input/housesalesprediction/kc_house_data.csv')

house_df.isnull().sum()

house_df.drop(15870, inplace=True)

from sklearn.model_selection import train_test_split
y = house_df['price']
X = house_df[['bedrooms', 'bathrooms', 'sqft_living', 'sqft_lot', 'floors', 'waterfront', 'view', 'condition', 'grade', 'sqft_above', 'sqft_basement', 'yr_built', 'yr_renovated', 'zipcode', 'lat', 'long', 'sqft_living15', 'sqft_lot15']]
X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.33, random_state=42)

from sklearn.linear_model import LinearRegression
lr = LinearRegression(fit_intercept=True)

lr.fit(X_train, y_train)

pred = lr.predict(X_test)

import sklearn.metrics
from sklearn.metrics import mean_squared_error, mean_absolute_error
print('Mean Squared Error:', mean_squared_error(y_test, pred))
print()
print('Root Mean Squared Error:', np.sqrt(mean_squared_error(y_test, pred)))
print()
print('Mean Absolute Error:', mean_absolute_error(y_test, pred))
print()
print('Mean Absolute Percentage Error:', np.mean(np.abs((y_test - pred) / y_test)) * 100)