Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Python: How to evaluate the residuals in StatsModels?

I want to evaluate the residuals: (y-hat y).

I know how to do that:

df = pd.read_csv('myFile', delim_whitespace = True, header = None)
df.columns = ['column1', 'column2']
y, X = ps.dmatrices('column1 ~ column2',data = df, return_type = 'dataframe')
model = sm.OLS(y,X)
results = model.fit()
predictedValues = results.predict()
#print predictedValues
yData = df.as_matrix(columns = ['column1'])
res = yData - predictedValues

I wonder if there is a Method to do this (?).

like image 913
DanielTheRocketMan Avatar asked Feb 15 '16 19:02

DanielTheRocketMan


1 Answers

That's stored in the resid attribute of the Results class

Likewise there's a results.fittedvalues method, so you don't need the results.predict().

like image 170
TomAugspurger Avatar answered Oct 03 '22 05:10

TomAugspurger