Seaborn Regression Plots

Scatter + a fitted trend line, with confidence interval.

๐Ÿ“ˆ regplot โ€” axes-level

sns.regplot(data=df, x="total_bill", y="tip")
sns.regplot(data=df, x="total_bill", y="tip", ci=95)             # confidence interval band, default 95
sns.regplot(data=df, x="total_bill", y="tip", ci=None)               # no CI shading
sns.regplot(data=df, x="total_bill", y="tip", order=2)                  # polynomial fit (quadratic here)
sns.regplot(data=df, x="total_bill", y="tip", logistic=True)               # logistic regression (binary y)
sns.regplot(data=df, x="total_bill", y="tip", scatter=False)                  # line only, no points

๐ŸŽฏ lmplot โ€” figure-level, supports faceting

sns.lmplot(data=df, x="total_bill", y="tip", hue="smoker")                # separate line per category
sns.lmplot(data=df, x="total_bill", y="tip", col="time")                     # facet into columns
sns.lmplot(data=df, x="total_bill", y="tip", col="time", row="sex")             # full grid

regplot = single axes, no faceting, works with ax=. lmplot = figure-level, supports hue/col/row faceting like relplot/catplot. Same underlying regression logic.

๐Ÿ“‰ residplot โ€” residuals of a linear fit

sns.residplot(data=df, x="total_bill", y="tip")

Residuals should look like random scatter around 0. A visible curve/pattern in residuals means a linear fit is a poor choice for that data.

๐Ÿงฎ Choosing fit order

sns.regplot(data=df, x="x", y="y", order=1)   # linear (default)
sns.regplot(data=df, x="x", y="y", order=2)      # quadratic
sns.regplot(data=df, x="x", y="y", order=3)         # cubic

Higher order = more prone to overfitting, especially with limited data. Only bump order if a linear fit visibly, genuinely doesn't capture the trend.

๐Ÿ”— Next

Seaborn Matrix & Heatmaps ยท Seaborn Multi-Plot Grids