首页 > 解决方案 > 拟合回归后如何使用Seaborn的residplot?

问题描述

我在 Python 中有一个简单的线性多元回归,如下所示:

X_train,X_test,y_train,y_test=train_test_split(x_cols,df['Volume'],test_size=0.15)

regr = LinearRegression()
regr.fit(X_train, y_train)
y_pred = regr.predict(X_test)

如何绘制该模型的残差?

起初我试过这个:

sns.residplot(y_pred, y_test)

但我不确定这是否真的显示了线性回归的残差。我是否将正确的参数传递给了 residplot?

标签: linear-regressionseaborn

解决方案


不,您需要将 x 和 y 作为参数传递,然后residplot运行回归并绘制残差。您可以在此处
阅读更多信息:residplot

df = pd.DataFrame({ 
    'X':np.random.randn(60),
    'Y':np.random.randn(60),
    })

sns.residplot('X','Y',data=df)  

残渣图


推荐阅读