Regressao Linear Simples - Ipynb - Colaboratory
Regressao Linear Simples - Ipynb - Colaboratory
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
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())
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)
https://colab.research.google.com/drive/1U7tF96iZuuNj0E_DDHH155dbJYWc_eLK#scrollTo=6W9IAprWS8j3&printMode=true 2/2