使用sns.regplot() 建立回归模型,可看成是在散点图的基础上,多绘制一条回归线,观察两个变量的关系
regplot()和lmplot()都可以绘制线性回归曲线。这两个函数非常相似,lmplot()要比regplot()强大一点
数据准备
import numpy as np
import pandas as pd
import seaborn as sns
import matplotlib.pyplot as plt
tips = pd.read_csv(r'../input/seaborn-data/iris.csv')
tips.head()
seaborn.regplot(x, y, data=None, x_estimator=None, x_bins=None, x_ci='ci',
scatter=True, fit_reg=True, ci=95, n_boot=1000, units=None, order=1, logistic=False,
lowess=False, robust=False, logx=False, x_partial=None, y_partial=None,
truncate=False, dropna=True, x_jitter=None, y_jitter=None, label=None, color=None,
marker='o', scatter_kws=None, line_kws=None, ax=None)
sns.regplot(x='total_bill', y='tip', data=tips)
sns.regplot(x='size', y='tip', data=tips)
sns.regplot(x='size', y='tip', data=tips, x_jitter=0.05)
用 sns.lmplot()
函数也能达到一样的效果,当然两个函数的使用方法不完全一致,这里不做过多介绍
seaborn.lmplot(x, y, data, hue=None, col=None, row=None, palette=None,
col_wrap=None, height=5, aspect=1, markers='o', sharex=True, sharey=True,
hue_order=None, col_order=None, row_order=None, legend=True, legend_out=True,
x_estimator=None, x_bins=None, x_ci='ci', scatter=True, fit_reg=True, ci=95,
n_boot=1000, units=None, order=1, logistic=False, lowess=False, robust=False,
logx=False, x_partial=None, y_partial=None, truncate=False, x_jitter=None,
y_jitter=None, scatter_kws=None, line_kws=None, size=None)
sns.lmplot(x='total_bill', y='tip', data=tips)
sns.lmplot(x="total_bill", y="tip", hue="smoker", data=tips)