In [6]:
import pandas as pa
#Données reliant un nombre de ventes et l’investissement dans différents médias.
#Le modèle de régression multiple a une variable dépendante y mesurant le nombre de ventes
#et 3 variables indépendantes mesurant les investissements en terme de publicité par média.
data = pa.read_csv('advertising.csv')
data.head()
Out[6]:
TV | Radio | Newspaper | Sales | |
---|---|---|---|---|
0 | 230.1 | 37.8 | 69.2 | 22.1 |
1 | 44.5 | 39.3 | 45.1 | 10.4 |
2 | 17.2 | 45.9 | 69.3 | 9.3 |
3 | 151.5 | 41.3 | 58.5 | 18.5 |
4 | 180.8 | 10.8 | 58.4 | 12.9 |
In [7]:
X = data[['TV', 'Radio', 'Newspaper']]
y = data['Sales']
In [8]:
from statsmodels.regression.linear_model import OLS
model = OLS(y,X)
results = model.fit()
report = results.summary()
report
Out[8]:
Dep. Variable: | Sales | R-squared (uncentered): | 0.979 |
---|---|---|---|
Model: | OLS | Adj. R-squared (uncentered): | 0.979 |
Method: | Least Squares | F-statistic: | 3091. |
Date: | Fri, 22 Sep 2023 | Prob (F-statistic): | 2.40e-165 |
Time: | 07:52:32 | Log-Likelihood: | -437.56 |
No. Observations: | 200 | AIC: | 881.1 |
Df Residuals: | 197 | BIC: | 891.0 |
Df Model: | 3 | ||
Covariance Type: | nonrobust |
coef | std err | t | P>|t| | [0.025 | 0.975] | |
---|---|---|---|---|---|---|
TV | 0.0531 | 0.001 | 37.422 | 0.000 | 0.050 | 0.056 |
Radio | 0.2296 | 0.010 | 22.877 | 0.000 | 0.210 | 0.249 |
Newspaper | 0.0158 | 0.007 | 2.206 | 0.029 | 0.002 | 0.030 |
Omnibus: | 24.277 | Durbin-Watson: | 2.053 |
---|---|---|---|
Prob(Omnibus): | 0.000 | Jarque-Bera (JB): | 83.215 |
Skew: | 0.371 | Prob(JB): | 8.51e-19 |
Kurtosis: | 6.072 | Cond. No. | 12.5 |
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.
In [ ]: