text_plain_output_1.png
from scipy import stats

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)

pearson_coef_values = []
p_values = []
for name in column_names:
    pearson_coef, p_value = stats.pearsonr(data[name], data['price'])
    pearson_coef_values.append(pearson_coef)
    p_values.append(p_value)
pearson_corelation = pd.DataFrame({'Feature': column_names, 'Pearson Coefficient Values': pearson_coef_values, 'P Values': p_values})
pearson_corelation.sort_values('Pearson Coefficient Values')
pearson_corelation.head(30)