【问题标题】:How to find the standardized residuals with sklearn?如何使用 sklearn 找到标准化残差?
【发布时间】:2021-03-17 10:56:53
【问题描述】:

sklearn 有没有获得标准化残差的方法? 我创建了一个包含所有值、预测值和残差的数据框。

Weight  Height  Sex  Age  PredictedWeight  Residual
81.0    177     0    31   81.2             -0.2
78.2    176     0    28   78.8             -0.6
72.5    172     1    29   71.8              0.7
...     ...     ...  ...  ...               ...

我的代码:

from sklearn import linear_model
import pandas as pd

X = df[["Height", "Sex", "Age"]]
Y = df["Weight"]

regr = linear_model.LinearRegression()
regr.fit(X, Y)

df["PredictedWeight"] = regr.predict(df[["Height", "Sex", "Age"]])
df["Residual"] = df["Weight"] - df["Predicted"]

我想在df 中添加一个带有标准化残差的新列,有什么建议吗?

【问题讨论】:

    标签: python-3.x pandas scikit-learn linear-regression


    【解决方案1】:

    我觉得很简单

    mean = df["Residual"].mean()
    std = df["Residual"].std()
    
    df["StdResidual"] = (df["Residual"] - mean)/std
    
    

    还是你想要别的东西?

    【讨论】:

      猜你喜欢
      • 2020-02-28
      • 2013-11-15
      • 2017-11-10
      • 1970-01-01
      • 2018-04-16
      • 1970-01-01
      • 2019-03-28
      • 1970-01-01
      • 2021-05-03
      相关资源
      最近更新 更多