Back to Seaborn

Regression

doc/_tutorial/regression.ipynb

0.13.22.5 KB
Original Source
python
import numpy as np
import seaborn as sns
import matplotlib.pyplot as plt
sns.set_theme(color_codes=True)
np.random.seed(sum(map(ord, "regression")))
python
tips = sns.load_dataset("tips")
sns.regplot(x="total_bill", y="tip", data=tips);
python
sns.lmplot(x="total_bill", y="tip", data=tips);
python
sns.lmplot(x="size", y="tip", data=tips);
python
sns.lmplot(x="size", y="tip", data=tips, x_jitter=.05);
python
sns.lmplot(x="size", y="tip", data=tips, x_estimator=np.mean);
python
anscombe = sns.load_dataset("anscombe")
python
sns.lmplot(x="x", y="y", data=anscombe.query("dataset == 'I'"),
           ci=None, scatter_kws={"s": 80});
python
sns.lmplot(x="x", y="y", data=anscombe.query("dataset == 'II'"),
           ci=None, scatter_kws={"s": 80});
python
sns.lmplot(x="x", y="y", data=anscombe.query("dataset == 'II'"),
           order=2, ci=None, scatter_kws={"s": 80});
python
sns.lmplot(x="x", y="y", data=anscombe.query("dataset == 'III'"),
           ci=None, scatter_kws={"s": 80});
python
sns.lmplot(x="x", y="y", data=anscombe.query("dataset == 'III'"),
           robust=True, ci=None, scatter_kws={"s": 80});
python
tips["big_tip"] = (tips.tip / tips.total_bill) > .15
sns.lmplot(x="total_bill", y="big_tip", data=tips,
           y_jitter=.03);
python
sns.lmplot(x="total_bill", y="big_tip", data=tips,
           logistic=True, y_jitter=.03);
python
sns.lmplot(x="total_bill", y="tip", data=tips,
           lowess=True, line_kws={"color": "C1"});
python
sns.residplot(x="x", y="y", data=anscombe.query("dataset == 'I'"),
              scatter_kws={"s": 80});
python
sns.residplot(x="x", y="y", data=anscombe.query("dataset == 'II'"),
              scatter_kws={"s": 80});
python
sns.lmplot(x="total_bill", y="tip", hue="smoker", data=tips);
python
sns.lmplot(x="total_bill", y="tip", hue="smoker", data=tips,
           markers=["o", "x"], palette="Set1");
python
sns.lmplot(x="total_bill", y="tip", hue="smoker", col="time", data=tips);
python
sns.lmplot(x="total_bill", y="tip", hue="smoker",
           col="time", row="sex", data=tips, height=3);
python
sns.jointplot(x="total_bill", y="tip", data=tips, kind="reg");
python
sns.pairplot(tips, x_vars=["total_bill", "size"], y_vars=["tip"],
             height=5, aspect=.8, kind="reg");
python
sns.pairplot(tips, x_vars=["total_bill", "size"], y_vars=["tip"],
             hue="smoker", height=5, aspect=.8, kind="reg");