<jupyter_start><jupyter_text>Dataset https://www.kaggle.com/harlfoxem/housesalesprediction  Import Libraries<jupyter_code>import numpy as np
import pandas as pd
import matplotlib.pyplot as plt
import seaborn as sns
plt.style.use("seaborn-whitegrid")<jupyter_output><empty_output><jupyter_text>Import the dataset<jupyter_code>data = pd.read_csv("houseSales.csv")
data.head()<jupyter_output><empty_output><jupyter_text>Information about the dataset<jupyter_code>data.info()
data.describe().T
data.columns<jupyter_output><empty_output><jupyter_text>Visualizating and Examining the Dataset<jupyter_code>data.hist(bins=25,figsize=(15,15),xlabelsize='10',ylabelsize='10')
plt.tight_layout()
plt.show()
plt.figure(dpi=120)
sns.boxplot(x=data['bedrooms'],y=data['price'])
plt.show()
plt.figure(dpi=120)
sns.boxplot(x=data['floors'],y=data['price'])
plt.show()
plt.figure(dpi=120,figsize=(15,7))
sns.boxplot(x=data['bathrooms'],y=data['price'])
plt.show()<jupyter_output><empty_output><jupyter_text>It seems that there is not a perfect linear relationship between the price and these features<jupyter_code># Waterfront does have an effect on the price
plt.figure(dpi=120)
sns.boxplot(x=data['waterfront'],y=data['price'])
plt.show()
# View have less effect on the price
plt.figure(dpi=120)
sns.boxplot(x=data['view'],y=data['price'])
plt.show()
plt.figure(dpi=130)
sns.boxplot(x=data['grade'],y=data['price'])
plt.show()<jupyter_output><empty_output><jupyter_text>Correlation<jupyter_code>data.corr()
plt.figure(dpi=120,figsize=(16, 12))
sns.heatmap(data.corr(),square=True,cmap="BuGn",linecolor='w',annot=True,annot_kws={"size":8})
plt.show()
plt.figure(dpi=120,figsize=(16, 12))
sns.heatmap(data.corr(),square=True,cmap="BuGn",
            linecolor='w',annot=True,annot_kws={"size":8},
           mask=np.triu(data.corr()))
plt.show()
data.corr().index!="price"
corr_data = data.corr().loc[data.corr().index!="price","price"]
corr_data
np.abs(corr_data)
threshold=0.3
corr_data[np.abs(corr_data)>threshold]
feature_name = corr_data[np.abs(corr_data)>threshold].index.values
feature_name
X = data[feature_name]
print(X.shape)
print(X.head())
y = data["price"]
print(y.shape)
print(y.head())
from sklearn.model_selection import train_test_split
X_train, X_test, y_train, y_test = train_test_split(X, y,test_size=0.2,random_state=123)
print(X_train.shape)
print(y_train.shape)
print(X_test.shape)
print(y_test.shape)
from sklearn.linear_model import LinearRegression
model=LinearRegression()
model.fit(X_train,y_train)
model.coef_
model.intercept_
model.score(X_test,y_test)<jupyter_output><empty_output><jupyter_text>Polynomial Regression<jupyter_code>X.head()
from sklearn.preprocessing import PolynomialFeatures
poly=PolynomialFeatures(degree=2)
new_X=poly.fit_transform(X)
print(new_X.shape)
print(new_X[0])
from sklearn.model_selection import train_test_split
X_train, X_test, y_train, y_test = train_test_split(new_X, y,test_size=0.2,random_state=123)
model=LinearRegression()
model.fit(X_train,y_train)
model.coef_[:10]
model.intercept_
model.score(X_test,y_test)<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.1582012293756066, 'fraction_numerical': 0.020381753477838885, 'mean_word_length': 10.202898550724637, 'pattern_counts': {'":': 2, '<': 29, '<?xml version=': 0, '>': 31, 'https://': 1, 'lorem ipsum': 0, 'www.': 1, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '7', 'dir': 'jupyter-structured-clean-dedup', 'id': '176521', 'license': 'MIT', 'n_tokens_mistral': 1278, 'n_tokens_neox': 1203, 'n_words': 158, 'path': 'python/projects/houseSales/basicHousePrice.ipynb', 'repo_name': 'BharathC15/NielitChennai', 'size': '3091'}