Professional Documents
Culture Documents
In [12]: df=pd.read_csv("homeprices.csv")
#df.head(2)
#df.tail()
#df.head()
#df.tail(2)
#df.describe()
#df.info()
#df.shape
df
0 2600 550000
1 3000 565000
2 3200 610000
3 3600 680000
4 4000 725000
0 2600
Out[15]:
1 3000
2 3200
3 3600
4 4000
Name: area, dtype: int64
file:///home/invincible/Desktop/p1.html 1/3
1/3/23, 2:10 PM p1
In [16]: reg=linear_model.LinearRegression()
reg.fit(df[['area']],df.price)
LinearRegression()
Out[16]:
In [17]: new_data=np.array(3300).reshape(-1,1)
new_data
y_pred=reg.predict(new_data)
y_pred
new_data1=np.array(3700).reshape(-1,1)
new_data1
y_pred1=reg.predict(new_data1)
y_pred1
/home/invincible/anaconda3/lib/python3.9/site-packages/sklearn/base.py:450:
UserWarning: X does not have valid feature names, but LinearRegression was
fitted with feature names
warnings.warn(
/home/invincible/anaconda3/lib/python3.9/site-packages/sklearn/base.py:450:
UserWarning: X does not have valid feature names, but LinearRegression was
fitted with feature names
warnings.warn(
array([683030.82191781])
Out[17]:
In [18]: print("Cofficient{}:",reg.coef_)
Cofficient{}: [135.78767123]
In [19]: print("Intercept{}:",reg.intercept_)
Intercept{}: 180616.43835616432
file:///home/invincible/Desktop/p1.html 2/3
1/3/23, 2:10 PM p1
plt.scatter(df.area,df.price,color='red',marker='*')
plt.plot(df.area,reg.predict(df[['area']]),color='blue')
[<matplotlib.lines.Line2D at 0x7f5f1eb03910>]
Out[22]:
In [ ]:
file:///home/invincible/Desktop/p1.html 3/3