assignment2
assignment2
import pandas as pd
import matplotlib.pyplot as plt
import seaborn as sns
df = pd.read_csv("Datasets/SalesData.csv")
df.head()
Temperature Revenue
0 24.566884 534.799028
1 26.005191 625.190122
2 27.790554 660.632289
3 20.595335 487.706960
4 11.503498 316.240194
lin_reg = LinearRegression()
lin_reg.fit(X_train, y_train)
LinearRegression()
print(f"Coefficient: {lin_reg.coef_}")
print(f"Intercept: {lin_reg.intercept_}")
Coefficient: [[21.38145125]]
Intercept: [46.72052514]
y_pred = lin_reg.predict(X_test)
R-Squared: 0.973546292060864
X = df["Temperature"]
y = df[["Revenue"]]
======================================================================
=================
Dep. Variable: Revenue R-squared (uncentered):
0.997
Model: OLS Adj. R-squared (uncentered):
0.997
Method: Least Squares F-statistic:
1.756e+05
Date: Thu, 13 Feb 2025 Prob (F-statistic):
0.00
Time: 21:13:20 Log-Likelihood:
-2398.1
No. Observations: 500 AIC:
4798.
Df Residuals: 499 BIC:
4802.
Df Model: 1
======================================================================
=========
coef std err t P>|t| [0.025
0.975]
----------------------------------------------------------------------
---------
Temperature 23.2244 0.055 419.007 0.000 23.116
23.333
======================================================================
========
Omnibus: 3.228 Durbin-Watson:
2.022
Prob(Omnibus): 0.199 Jarque-Bera (JB):
3.426
Skew: 0.080 Prob(JB):
0.180
Kurtosis: 3.372 Cond. No.
1.00
======================================================================
========
Notes:
[1] R² is computed without centering (uncentered) since the model does
not contain a constant.
[2] Standard Errors assume that the covariance matrix of the errors is
correctly specified.