Skip to content

Simple Linear Regression in Python Videos

Last Update: March 22, 2022

My online video tutorials are hosted at YouTube channel.

For learning this concept, you can view my online video tutorials: Simple Linear Regression in Python (Spyder) and Simple Linear Regression in Python (Jupyter).

Videos Code

1. Packages

import statsmodels.api as sm
import statsmodels.formula.api as smf
import seaborn as sns

2. Data

houseprices_object = sm.datasets.get_rdataset(dataname="HousePrices",
                                              package="AER", cache=True)
houseprices = houseprices_object.data
print(houseprices.iloc[:, 0:2].head())
print(houseprices_object.__doc__)

3. Chart

sns.regplot(x="lotsize", y="price", data=houseprices, ci=None,
            line_kws={"color": "red"})

4. Model

\hat{price} = \hat{\beta}_{0} + \hat{\beta}_{1} lotsize
slr = smf.ols(formula="price ~ lotsize", data=houseprices).fit()
print(slr.params)

Courses

My online courses are hosted at Teachable website.

For more details on this concept, you can view my Linear Regression in Python Course.

My online courses are closed for enrollment.
+