<jupyter_start><jupyter_text>Visualization of dataset<jupyter_code>def numerical(feature):
    sns.scatterplot(x=df[feature],y=df.SALES_PRICE,hue=df.REG_FEE,palette='Spectral')
def categorical(feature):
    plt.figure(figsize=(15,5))
    sns.barplot(x=df[feature],y=df.SALES_PRICE)
numerical('INT_SQFT')
numerical('REG_FEE')
sns.barplot(x=df.N_BEDROOM,y=df.SALES_PRICE)
sns.barplot(x=df.N_ROOM,y=df.SALES_PRICE)
numerical('COMMIS')
df.DATE_BUILD = pd.to_datetime(df.DATE_BUILD)
df.DATE_SALE = pd.to_datetime(df.DATE_SALE)
df['build_to_sale']= (df.DATE_SALE - df.DATE_BUILD).dt.days
df.head()
li = df.corr()['SALES_PRICE'].index
for i in df.columns:
    if i not in li:
        print(i)
categorical('AREA')
categorical('SALE_COND')
categorical('BUILDTYPE')
categorical('PARK_FACIL')
categorical('UTILITY_AVAIL')
categorical('STREET')
categorical('MZZONE')
df.head()
df.corr()['SALES_PRICE'].sort_values(ascending=False)<jupyter_output><empty_output><jupyter_text>Multi-variate Analysis<jupyter_code>sns.jointplot(df.REG_FEE,df.SALES_PRICE,kind='reg')
sns.jointplot(df.COMMIS,df.SALES_PRICE,kind='reg')
sns.jointplot(df.INT_SQFT,df.SALES_PRICE,kind='reg')
sns.boxplot(df.N_ROOM,df.SALES_PRICE)
df[df.N_ROOM<6].corr()['SALES_PRICE'].sort_values(ascending=False)
sns.boxplot(df.N_BEDROOM,df.SALES_PRICE)<jupyter_output><empty_output><jupyter_text>Imputation and Wrangling<jupyter_code>df.info()
df.AREA.value_counts()
area = {'Chrompt':'Chrompet','Chormpet':'Chrompet','Chrmpet':'Chrompet','TNagar':'T Nagar','<NAME>':'<NAME>','Karapakam':'Karapakkam','<NAME>ar':'<NAME>','Velchery':'Velachery','KKNagar':'KK Nagar','Adyr':'Adyar'}
df.AREA = df.AREA.replace(area)
df.SALE_COND.value_counts()
cond = {'Adj Land':'AdjLand','Ab Normal':'AbNormal','Partiall':'Partial','PartiaLl':'Partial'}
df.SALE_COND = df.SALE_COND.replace(cond)
df.PARK_FACIL.value_counts()
park = {'Noo':'No'}
df.PARK_FACIL = df.PARK_FACIL.replace(park)
df.BUILDTYPE.value_counts()
df.BUILDTYPE = df.BUILDTYPE.replace({'Comercial':'Commercial','Other':'Others'})
df.UTILITY_AVAIL.value_counts()
df.UTILITY_AVAIL = df.UTILITY_AVAIL.replace({'All Pub':'AllPub'})
df.STREET.value_counts()
df.STREET = df.STREET.replace({'NoAccess':'No Access','Pavd':'Paved'})
df.MZZONE.value_counts()
df.QS_OVERALL = (df.QS_BATHROOM + df.QS_BEDROOM + df.QS_ROOMS)/3
df[df.QS_OVERALL.isna()]
df[df.N_BEDROOM.isna()]
df[(df.AREA=='<NAME>') & (df.N_ROOM==4) & (df.N_BATHROOM==1)]
df.N_BEDROOM.fillna(1.0,inplace=True)
df[df.N_BATHROOM.isna()]
df[(df.AREA=='Chrompet')&(df.N_BEDROOM==1)&(df.N_ROOM==3)].N_BATHROOM.value_counts()
df.N_BATHROOM.fillna(1.0,inplace=True)
df.drop(['PRT_ID','DATE_SALE','DATE_BUILD'],axis=1,inplace=True)
df.head()
df = pd.get_dummies(df,drop_first=True)
df.head()
df.corr()['SALES_PRICE'].sort_values(ascending=False)<jupyter_output><empty_output><jupyter_text>Modelling<jupyter_code>from sklearn.linear_model import LinearRegression
from sklearn.model_selection import train_test_split, cross_val_score, KFold
from xgboost import XGBRegressor
from sklearn.ensemble import RandomForestRegressor,GradientBoostingRegressor
X = df.drop('SALES_PRICE',axis=1)
y = df.SALES_PRICE
X_train,X_test,y_train,y_test = train_test_split(X,y,random_state=0,test_size=0.2)
X_train,X_valid,y_train,y_valid = train_test_split(X_train,y_train,random_state=0,test_size=0.2)
kf = KFold(n_splits=10,shuffle=True)
lr = LinearRegression().fit(X_train,y_train)
cs = cross_val_score(lr,X_train,y_train,cv=kf)
cs.mean()
lr.score(X_train,y_train), lr.score(X_valid,y_valid)
rr = RandomForestRegressor(n_estimators=500).fit(X_train,y_train)
rr.score(X_train,y_train), rr.score(X_valid,y_valid)
xx = XGBRegressor().fit(X_train,y_train)
xx.score(X_train,y_train), xx.score(X_valid,y_valid)<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.1809473124002129, 'fraction_numerical': 0.006918573709419904, 'mean_word_length': 10.566153846153846, 'pattern_counts': {'":': 0, '<': 23, '<?xml version=': 0, '>': 22, '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': '4', 'dir': 'jupyter-structured-clean-dedup', 'id': '603251', 'license': 'MIT', 'n_tokens_mistral': 1738, 'n_tokens_neox': 1683, 'n_words': 143, 'path': 'House_Price_Prediction/chennai house price 1.ipynb', 'repo_name': 'manvi0308/datascience-mashup', 'size': '3774'}