Regression Plots (lmplot, regplot)
Why regression plots?
Regression plots help you see:
- Trend direction
- Strength of relationship (visual)
- Outliers that affect the trend
regplotregplot (axes-level)
regplot
import seaborn as sns
import matplotlib.pyplot as plt
tips = sns.load_dataset("tips")
plt.figure(figsize=(7, 4))
sns.regplot(data=tips, x="total_bill", y="tip")
plt.title("Tip vs total bill")
plt.tight_layout()
plt.show()regplot
import seaborn as sns
import matplotlib.pyplot as plt
tips = sns.load_dataset("tips")
plt.figure(figsize=(7, 4))
sns.regplot(data=tips, x="total_bill", y="tip")
plt.title("Tip vs total bill")
plt.tight_layout()
plt.show()lmplotlmplot (figure-level, great for facets)
lmplot
import seaborn as sns
tips = sns.load_dataset("tips")
sns.lmplot(data=tips, x="total_bill", y="tip", hue="sex")lmplot
import seaborn as sns
tips = sns.load_dataset("tips")
sns.lmplot(data=tips, x="total_bill", y="tip", hue="sex")Non-linear patterns
You can try polynomial fits.
Polynomial fit
import seaborn as sns
import matplotlib.pyplot as plt
tips = sns.load_dataset("tips")
plt.figure(figsize=(7, 4))
sns.regplot(data=tips, x="total_bill", y="tip", order=2)
plt.title("Quadratic trend")
plt.tight_layout()
plt.show()Polynomial fit
import seaborn as sns
import matplotlib.pyplot as plt
tips = sns.load_dataset("tips")
plt.figure(figsize=(7, 4))
sns.regplot(data=tips, x="total_bill", y="tip", order=2)
plt.title("Quadratic trend")
plt.tight_layout()
plt.show()Tips
- Regression plots show association, not causation.
- Outliers can heavily affect the fitted line.
- Use transformations (log) if relationships are multiplicative.
If this helped you, consider buying me a coffee ☕
Buy me a coffeeWas this page helpful?
Let us know how we did
