【问题标题】:How to use Seaborn's residplot after fitting regression?拟合回归后如何使用Seaborn的residplot?
【发布时间】:2019-04-23 20:36:01
【问题描述】:

我在 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-regression seaborn


    【解决方案1】:

    不,您需要将 x 和 y 作为参数传递,residplot 将运行回归并绘制残差。
    你可以阅读更多关于residplothere

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2015-11-29
      • 2014-05-16
      • 2021-02-17
      • 1970-01-01
      • 1970-01-01
      • 2019-03-28
      • 2016-09-26
      相关资源
      最近更新 更多