12/03/2022 10:46 regressao_linear_simples.
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 df = pd.DataFrame(list(zip(propaganda,vendas)),
4 columns = ['propaganda','vendas'])
5 df
propaganda vendas
0 1 1
1 2 2
2 3 4
3 4 5
4 5 8
1 df.corr(method ='pearson')
propaganda vendas
propaganda 1.000000 0.981495
vendas 0.981495 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 0x7fcf373f09d0>
1
model = smf.ols(formula='vendas ~ propaganda', data=df)
2
resultado = model.fit()
https://colab.research.google.com/drive/1U7tF96iZuuNj0E_DDHH155dbJYWc_eLK#scrollTo=6W9IAprWS8j3&printMode=true 1/2
12/03/2022 10:46 regressao_linear_simples.ipynb - Colaboratory
3
print(resultado.summary())
OLS Regression Results
=============================================================================
Dep. Variable: vendas R-squared: 0.96
Model: OLS Adj. R-squared: 0.95
Method: Least Squares F-statistic: 78.8
Date: Sat, 12 Mar 2022 Prob (F-statistic): 0.0030
Time: 13:23:52 Log-Likelihood: -3.309
No. Observations: 5 AIC: 10.6
Df Residuals: 3 BIC: 9.83
Df Model: 1
Covariance Type: nonrobust
=============================================================================
coef std err t P>|t| [0.025 0.975
-----------------------------------------------------------------------------
Intercept -1.1000 0.635 -1.732 0.182 -3.121 0.92
propaganda 1.7000 0.191 8.878 0.003 1.091 2.30
=============================================================================
Omnibus: nan Durbin-Watson: 2.50
Prob(Omnibus): nan Jarque-Bera (JB): 0.39
Skew: -0.174 Prob(JB): 0.82
Kurtosis: 1.667 Cond. No. 8.3
=============================================================================
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:46
https://colab.research.google.com/drive/1U7tF96iZuuNj0E_DDHH155dbJYWc_eLK#scrollTo=6W9IAprWS8j3&printMode=true 2/2