You are on page 1of 2

12/03/2022 10:42 regressao_linear_multipla.

ipynb - Colaboratory

1 import pandas as pd
2 import statsmodels.formula.api as smf
3 import seaborn as sn

1 propaganda = [1,2,3,4,5]
2 vendas = [1,2,4,5,8]
3 demanda = [12,15,16,17,19]
4 df = pd.DataFrame(list(zip(propaganda,vendas,demanda)), 
5                   columns = ['propaganda','vendas','demanda'])
6 df

propaganda vendas demanda

0 1 1 12

1 2 2 15

2 3 4 16

3 4 5 17

4 5 8 19

1 df.corr(method ='pearson')

propaganda vendas demanda

propaganda 1.000000 0.981495 0.977356

vendas 0.981495 1.000000 0.952217

demanda 0.977356 0.952217 1.000000

1 correlation = df.corr(method ='pearson')
2 plot = sn.heatmap(correlation, annot = True, fmt=".4f", linewidths=.6)
3 plot

<matplotlib.axes._subplots.AxesSubplot at 0x7f8af4143950>

https://colab.research.google.com/drive/1brMaelvpTlP6hrc5YhJSvKOLi44-Lbv0#scrollTo=0Rm5NVr4Ukrr&printMode=true 1/2
12/03/2022 10:42 regressao_linear_multipla.ipynb - Colaboratory

1
model = smf.ols(formula='vendas ~ propaganda + demanda', data=df)

2
resultado = model.fit()

3
print(resultado.summary())

OLS Regression Results


=============================================================================
Dep. Variable: vendas R-squared: 0.96
Model: OLS Adj. R-squared: 0.92
Method: Least Squares F-statistic: 27.1
Date: Sat, 12 Mar 2022 Prob (F-statistic): 0.035
Time: 13:36:14 Log-Likelihood: -3.232
No. Observations: 5 AIC: 12.4
Df Residuals: 2 BIC: 11.2
Df Model: 2
Covariance Type: nonrobust
=============================================================================
coef std err t P>|t| [0.025 0.975
-----------------------------------------------------------------------------
Intercept 0.7333 7.373 0.099 0.930 -30.991 32.45
propaganda 1.9667 1.091 1.802 0.213 -2.729 6.66
demanda -0.1667 0.667 -0.250 0.826 -3.035 2.70
=============================================================================
Omnibus: nan Durbin-Watson: 2.59
Prob(Omnibus): nan Jarque-Bera (JB): 0.31
Skew: -0.431 Prob(JB): 0.85
Kurtosis: 2.127 Cond. No. 373
=============================================================================

Warnings:

[1] Standard Errors assume that the covariance matrix of the errors is correc
/usr/local/lib/python3.7/dist-packages/statsmodels/stats/stattools.py:71: Val
"samples were given." % int(n), ValueWarning)

check 0s conclusão: 10:42

https://colab.research.google.com/drive/1brMaelvpTlP6hrc5YhJSvKOLi44-Lbv0#scrollTo=0Rm5NVr4Ukrr&printMode=true 2/2

You might also like