Generalize the code to linear regression.