Visualización básica de modelos de regresión lineal con lmplot() —#
0:00 min | Última modificación: Octubre 13, 2021 | [YouTube]
[1]:
import matplotlib.pyplot as plt
import seaborn as sns
import numpy as np
[2]:
tips = sns.load_dataset("tips")
tips.head()
[2]:
total_bill | tip | sex | smoker | day | time | size | |
---|---|---|---|---|---|---|---|
0 | 16.99 | 1.01 | Female | No | Sun | Dinner | 2 |
1 | 10.34 | 1.66 | Male | No | Sun | Dinner | 3 |
2 | 21.01 | 3.50 | Male | No | Sun | Dinner | 3 |
3 | 23.68 | 3.31 | Male | No | Sun | Dinner | 2 |
4 | 24.59 | 3.61 | Female | No | Sun | Dinner | 4 |
[3]:
#
# Regresión univariada con intervalos de confianza del 95% usando regplot()
#
sns.regplot(
x="total_bill",
y="tip",
data=tips,
marker='+',
)
plt.show()

[4]:
#
# Gráfica equivalente usando lmplot()
#
sns.lmplot(
x="total_bill",
y="tip",
data=tips,
x_jitter=0.05,
)
plt.show()

[5]:
#
# Regresión sobre una variable categórica
#
sns.lmplot(x="size", y="tip", data=tips,)
plt.show()

[6]:
#
# Regresión sobre una variable categórica + jitter
#
sns.lmplot(x="size", y="tip", data=tips, x_jitter=.05,)
plt.show()

[7]:
#
# Visualización de los datos con intervalos de confianza
#
sns.lmplot(
x="size",
y="tip",
data=tips,
x_estimator=np.mean,
)
plt.show()
