Lesson 12 of 15
R-squared & Residuals
R-squared & Residuals
After fitting an OLS line, we need to assess how well it fits the data.
Residuals are the differences between actual and predicted values:
R-squared (coefficient of determination) measures the proportion of variance explained:
where:
- — residual sum of squares
- — total sum of squares
means perfect fit; means the regression explains nothing (as good as just predicting the mean). In factor models, represents how much of an asset's variance is explained by the factors.
Your Task
Implement:
r_squared(xs, ys)— coefficient of determination using OLS fitresiduals(xs, ys)— list of OLS residuals
Python runtime loading...
Loading...
Click "Run" to execute your code.