# Should the residuals of a machine learning regression model be i.i.d.?

This is a basic question but I did not find the answer in most common statistical learning books.

In linear regression we assume that the residuals are i.i.d. Do we assume the same for a regression made by a ML algorithm?

I use in particular random forest. My residuals show spatial autocorrelation. It is not a problem itself because I can make some diagnostics and account for it. But more generally, I want to know whether this is harmful for the random forest model since it violates the i.i.d assumption of the residuals.

It relates this this question but only for the residuals.

$$r = (I-H)\epsilon\sim N(0,\sigma^2(I-H))$$
where $$H$$ is the hat matrix (https://en.wikipedia.org/wiki/Projection_matrix). As can be seen the covariance matrix is not diagonal (dependent), nor the variances are equal (not identical).