# Residual analysis in Python

when doing residual analysis do we first fit our model on our entire training set and calculate residuals between fitted values and actual values? Or do we first fit our model on the training+testing set?

I'm having trouble wrapping my head around the concept of residual variance. Does the variance mean that if we fit our linear regression model on multiple (varying) datasets, our residuals would vary according to the normal distribution with mean 0 and this variance?

When would we use prediction vs estimation? Predictions have more variance because of new data point, but it seems that we are always estimating/predicting new data points?

How do you deal with leverage points?

Does anybody know any good Python packages to do residual analysis?

• I'm not sure what you're asking about re: prediction v estimation. Bear in mind one estimates the coefficients in a regression, but having done so predicts $$y$$ values from $$x$$ values.