<jupyter_start><jupyter_text>Predicting the price of house<jupyter_code>import numpy as np
import pandas as pd
import seaborn as sns
import matplotlib.pyplot as plt
%matplotlib inline 
df = pd.read_csv("/content/drive/MyDrive/Colab Notebooks/Dataset/House_Price.csv")
df.head()
df.tail()
df.shape
df.describe()
df.info()<jupyter_output><class 'pandas.core.frame.DataFrame'>
RangeIndex: 506 entries, 0 to 505
Data columns (total 19 columns):
 #   Column       Non-Null Count  Dtype  
---  ------       --------------  -----  
 0   price        506 non-null    float64
 1   crime_rate   506 non-null    float64
 2   resid_area   506 non-null    float64
 3   air_qual     506 non-null    float64
 4   room_num     506 non-null    float64
 5   age          506 non-null    float64
 6   dist1        506 non-null    float64
 7   dist2        506 non-null    float64
 8   dist3        506 non-null    float64
 9   dist4        506 non-null    float64
 10  teachers     506 non-null    float64
 11  poor_prop    506 non-null    float64
 12  airport      506 non-null    object 
 13  n_hos_beds   498 non-null    float64
 14  n_hot_rooms  506 non-null    float64
 15  waterbody    506 non-null    object 
 16  rainfall     506 non-null    int64  
 17  bus_ter      506 non-null    object 
 18  parks        506 non-null    float64
dtypes: float[...]<jupyter_text>Exploratory Analysis<jupyter_code>sns.jointplot(x = "crime_rate", y="price", data=df)
sns.jointplot(x = "n_hot_rooms", y="price", data=df)
sns.jointplot(x="air_qual", y="price", data=df)
sns.jointplot(x="rainfall", y="price", data=df)
sns.countplot(x="bus_ter", data=df)
sns.countplot(x="airport", data=df)
sns.countplot(x="waterbody", data=df)
corr = df.corr()
ax = sns.heatmap(
    corr, 
    vmin=-1, vmax=1, center=0,
    cmap=sns.diverging_palette(20, 220, n=200),
    square=True
)
ax.set_xticklabels(
    ax.get_xticklabels(),
    rotation=45,
    horizontalalignment='right'
);<jupyter_output><empty_output><jupyter_text>Couple of ObservationsMissing values in "no_hot_rooms"Only "Yes" responses in "bus_ter"Skewness exists in the missing valuesDarker colors represent more the magnitude Handling missing values<jupyter_code>df.info()
df.n_hos_beds = df.n_hos_beds.fillna(df.n_hos_beds.mean())
df.info()<jupyter_output><class 'pandas.core.frame.DataFrame'>
RangeIndex: 506 entries, 0 to 505
Data columns (total 19 columns):
 #   Column       Non-Null Count  Dtype  
---  ------       --------------  -----  
 0   price        506 non-null    float64
 1   crime_rate   506 non-null    float64
 2   resid_area   506 non-null    float64
 3   air_qual     506 non-null    float64
 4   room_num     506 non-null    float64
 5   age          506 non-null    float64
 6   dist1        506 non-null    float64
 7   dist2        506 non-null    float64
 8   dist3        506 non-null    float64
 9   dist4        506 non-null    float64
 10  teachers     506 non-null    float64
 11  poor_prop    506 non-null    float64
 12  airport      506 non-null    object 
 13  n_hos_beds   506 non-null    float64
 14  n_hot_rooms  506 non-null    float64
 15  waterbody    506 non-null    object 
 16  rainfall     506 non-null    int64  
 17  bus_ter      506 non-null    object 
 18  parks        506 non-null    float64
dtypes: float[...]<jupyter_text>Variable Manipulation<jupyter_code>df['avg_dist'] = (df.dist1 + df.dist2 + df.dist3 + df.dist4)/4
del df['dist1']
del df['dist2']
del df['dist3']
del df['dist4']
df.head()
df.corr()
plt.scatter(df.air_qual, df.parks)
plt.xlabel("Parks")
plt.ylabel("Air Quality")
plt.show()
plt.scatter(df.room_num, df.price)
plt.xlabel("Room number")
plt.ylabel("Price")
plt.show()<jupyter_output><empty_output><jupyter_text>Linear Regression<jupyter_code>import statsmodels.api as sn
X = sn.add_constant(df['room_num'])
lm = sn.OLS(df['price'], X).fit()
lm.summary()
from sklearn.linear_model import LinearRegression
y = df['price']
X = df[['room_num']]
lm2 = LinearRegression()
lm2.fit(X,y)
print(lm2.intercept_, lm2.coef_)
sns.jointplot(x= df['room_num'], y = df['price'], data=df, kind='reg')<jupyter_output><empty_output><jupyter_text>Predicting Linear RegressionThe Equation is:9.0997* [room_num] + -34.6592<jupyter_code>print("What would be the price if the number of rooms are 6.756?")
print(round((9.0997)*(6.756)-(34.6592),2))<jupyter_output>What would be the price if the number of rooms are 6.756?
26.82
{'fraction_non_alphanumeric': 0.11704545454545455, 'fraction_numerical': 0.07386363636363637, 'mean_word_length': 3.0487580496780127, 'pattern_counts': {'":': 0, '<': 24, '<?xml version=': 0, '>': 24, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, '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': '6', 'dir': 'jupyter-structured-clean-dedup', 'id': '566248', 'license': 'MIT', 'n_tokens_mistral': 1825, 'n_tokens_neox': 1588, 'n_words': 404, 'path': 'Predicting_the_price_of_house.ipynb', 'repo_name': 'saditrahman/Predicting-the-price-of-house', 'size': '4400'}