text_plain_output_1.png image_output_1.png
from sklearn import preprocessing

from sklearn.model_selection import train_test_split

import matplotlib.pyplot as plt   #visualisation

import numpy as np

import pandas as pd

import seaborn as sns

data = pd.read_csv('/kaggle/input/housesalesprediction/kc_house_data.csv')

data.shape

data.dtypes

data.drop(['id', 'date', 'lat', 'long'], axis=1, inplace=True)

column_names = ['bedrooms', 'bathrooms', 'sqft_living', 'sqft_lot', 'floors', 'waterfront', 'view', 'condition', 'grade', 'sqft_above', 'sqft_basement', 'yr_built', 'yr_renovated', 'sqft_living15', 'sqft_lot15']

Q1 = data.quantile(0.25)
Q3 = data.quantile(0.75)
IQR = Q3 - Q1
upper = data[~(data > Q3 + 1.5 * IQR)].max()
lower = data[~(data < Q1 - 1.5 * IQR)].min()
df = np.where(data > upper, data.mean(), np.where(data < lower, data.mean(), data))
data = pd.DataFrame(df, columns=data.columns)

c = data.corr()
c

X = data[['bedrooms', 'bathrooms', 'sqft_living', 'sqft_lot', 'floors', 'waterfront', 'view', 'condition', 'grade', 'sqft_above', 'sqft_basement', 'yr_built', 'yr_renovated', 'sqft_living15', 'sqft_lot15']]
X = preprocessing.StandardScaler().fit(X).transform(X)
Y = data['price']

from sklearn.model_selection import train_test_split
x_train, x_test, y_train, y_test = train_test_split(X, Y, test_size=0.3, random_state=1)
print('number of test samples :', x_test.shape[0])
print('number of training samples:', x_train.shape[0])