Python sci-kit learn (metrics): difference between r2_score and explained_variance_score? -
Python sci-kit learn (metrics): difference between r2_score and explained_variance_score? -
i noticed that 'r2_score' , 'explained_variance_score' both build-in sklearn.metrics methods regression problems.
i under impression r2_score percent variance explained model. how different 'explained_variance_score'?
when take 1 on other?
thanks!
ok, @ example:
in [123]: #data y_true = [3, -0.5, 2, 7] y_pred = [2.5, 0.0, 2, 8] print metrics.explained_variance_score(y_true, y_pred) print metrics.r2_score(y_true, y_pred) 0.957173447537 0.948608137045 in [124]: #what explained_variance_score 1-np.cov(np.array(y_true)-np.array(y_pred))/np.cov(y_true) out[124]: 0.95717344753747324 in [125]: #what r^2 1-((np.array(y_true)-np.array(y_pred))**2).sum()/(4*np.array(y_true).std()**2) out[125]: 0.94860813704496794 in [126]: #notice mean residue not 0 (np.array(y_true)-np.array(y_pred)).mean() out[126]: -0.25 in [127]: #if predicted values different, such mean residue 0: y_pred=[2.5, 0.0, 2, 7] (np.array(y_true)-np.array(y_pred)).mean() out[127]: 0.0 in [128]: #they become same stuff print metrics.explained_variance_score(y_true, y_pred) print metrics.r2_score(y_true, y_pred) 0.982869379015 0.982869379015
so, when mean residue 0, same. 1 take dependents on needs, is, mean residue suppose 0?
python scikit-learn
Comments
Post a Comment