Professional Documents
Culture Documents
Linear Regression
Linear Regression
Linear Regression
NAME:- PRIADARSHANA
ROLL NO:- 2019332
Out[1]:
Unnamed: 0 TV Radio Newspaper Sales
In [2]: data.columns
In [6]: X = data['TV'].values.reshape(-1,1)
y = data['Sales'].values.reshape(-1,1)
from sklearn.model_selection import train_test_split
X_train, X_test, y_train, y_test = train_test_split(X,y,test_size=0.3,random_stat
print(X_train.shape)
print(X_test.shape)
print(y_train.shape)
print(y_test.shape)
reg = LinearRegression()
reg.fit(X_train, y_train)
(140, 1)
(60, 1)
(140, 1)
(60, 1)
normalize=False)
In [7]: print(reg.coef_[0][0])
print(reg.intercept_[0])
print("The linear model is: Y = {:.5} + {:.5}X".format(reg.intercept_[0], reg.coe
0.04581434217189623
7.310810165411681
In [10]: X=X_train
y=y_train
X2 = sm.add_constant(X)
est = sm.OLS(y, X2)
est2 = est.fit()
print(est2.summary())
==============================================================================
Df Model: 1
==============================================================================
------------------------------------------------------------------------------
==============================================================================
==============================================================================
Warnings:
[1] Standard Errors assume that the covariance matrix of the errors is correctl
y specified.
MSE : 7.497479593464674
RMSE : 2.7381525876883988
==============================================================================
Df Model: 3
==============================================================================
------------------------------------------------------------------------------
==============================================================================
==============================================================================
Warnings:
[1] Standard Errors assume that the covariance matrix of the errors is correctl
y specified.