Explained variance score as a risk metric

The explained variance score explains the dispersion of errors of a given dataset, and the formula is written as follows:

Here, and Var(y) is the variance of prediction errors and actual values respectively. Scores close to 1.0 are highly desired, indicating better squares of standard deviations of errors.

Obtain the explained variance score of our predictions using the explained_variance_score function of the sklearn.metrics module with the following code:

In [ ]: from sklearn.metrics import explained_variance_score ...

Get Mastering Python for Finance - Second Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.