Last active
August 24, 2018 22:22
-
-
Save ericmjl/b51ca0dffc3ab72052356e91f1a3552e to your computer and use it in GitHub Desktop.
Difference between the my own implementation of explained variance and scikit-learn's
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from sklearn.metrics import explained_variance_score | |
def var_explained(preds, actual): | |
""" | |
Implementation taken directly from the formula on this page: | |
http://scikit-learn.org/stable/modules/model_evaluation.html#explained-variance-score | |
""" | |
return 1 - ((preds - actual).var() / actual.var()) | |
y_pred = np.array([3, -0.5, 2, 7]) | |
y_actual = np.array([2.5, 0.0, 2, 8]) | |
var_explained(y_pred, y_actual) # 0.9644760213143873 | |
explained_variance_score(y_pred, y_actual) # 0.9571734475374732 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment