Week 12
Week 12
In [4]: df.info()
<class 'pandas.core.frame.DataFrame'>
RangeIndex: 4746 entries, 0 to 4745
Data columns (total 12 columns):
# Column Non-Null Count Dtype
--- ------ -------------- -----
0 Posted On 4746 non-null object
1 BHK 4746 non-null int64
2 Rent 4746 non-null int64
3 Size 4746 non-null int64
4 Floor 4746 non-null object
5 Area Type 4746 non-null object
6 Area Locality 4746 non-null object
7 City 4746 non-null object
8 Furnishing Status 4746 non-null object
9 Tenant Preferred 4746 non-null object
10 Bathroom 4746 non-null int64
11 Point of Contact 4746 non-null object
dtypes: int64(4), object(8)
memory usage: 445.1+ KB
In [5]: df.head()
Out[5]: Posted On BHK Rent Size Floor Area Type Area Locality City Furnishing Status Tenant Preferred Bathroom Point of Contact
0 2022-05-18 2 10000 1100 Ground out of 2 Super Area Bandel Kolkata Unfurnished Bachelors/Family 2 Contact Owner
1 2022-05-13 2 20000 800 1 out of 3 Super Area Phool Bagan, Kankurgachi Kolkata Semi-Furnished Bachelors/Family 1 Contact Owner
2 2022-05-16 2 17000 1000 1 out of 3 Super Area Salt Lake City Sector 2 Kolkata Semi-Furnished Bachelors/Family 1 Contact Owner
3 2022-07-04 2 10000 800 1 out of 2 Super Area Dumdum Park Kolkata Unfurnished Bachelors/Family 1 Contact Owner
4 2022-05-09 2 7500 850 1 out of 2 Carpet Area South Dum Dum Kolkata Unfurnished Bachelors 1 Contact Owner
In [7]: correlations=df['Size'].corr(df['Rent'])
print(f'The correlation is:{correlations}')
In [8]: correlations=df['Bathroom'].corr(df['BHK'])
print(f'The correlation is:{correlations}')
In [10]: df1.describe()
In [12]: X=df1[['Size']]
y=df1['BHK']
#splitting in 80 : 20 ratio
X_train,X_test,y_train,y_test = train_test_split(X, y,test_size=0.2,random_state=59)
model= LinearRegression()
model.fit(X_train,y_train)
m=model.coef_[0] #slope
b=model.intercept_ #intercept
print(f"Slope (m): {m}")
print(f"Intercept (b): {b}")
y_pred = model.predict(X_test)