Reputation: 449
Does sklearn
have a method to get the standardized residuals?
I have created a dataframe with all the values, the predicted values and the residuals.
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
... ... ... ... ... ...
The code I have:
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"]
I would like to add a new column to df
with the standardized residuals, any suggestions?
Upvotes: 3
Views: 3370
Reputation: 8219
I think it is simply
mean = df["Residual"].mean()
std = df["Residual"].std()
df["StdResidual"] = (df["Residual"] - mean)/std
or do you want something else?
Upvotes: 5