The Same Line as statsmodels
intercept_ = 4.95
coef_ = [16.59]
Fit the same model with statsmodels, as we did in Module 8:
ols_model = smf.ols('life_expectancy ~ log_gdp', data=df_2007)
results = ols_model.fit()
print(results.summary())
results.params gets just the coefficients from the summary: an intercept of 4.95 and a slope of 16.59.
They are identical. It is the same method, ordinary least squares, on the same data. Fit on all the data, scikit-learn and statsmodels give the same line.
Recap: smf.ols with a formula adds an intercept automatically. With scikit-learn we use the columns directly, and it fits an intercept automatically too.