Class: Rumale::EvaluationMeasure::ExplainedVarianceScore
- Inherits:
-
Object
- Object
- Rumale::EvaluationMeasure::ExplainedVarianceScore
- Includes:
- Base::Evaluator
- Defined in:
- rumale-evaluation_measure/lib/rumale/evaluation_measure/explained_variance_score.rb
Overview
ExplainedVarianceScore is a class that calculates the explained variance score.
Instance Method Summary collapse
-
#score(y_true, y_pred) ⇒ Float
Calculate explained variance score.
Instance Method Details
#score(y_true, y_pred) ⇒ Float
Calculate explained variance score.
22 23 24 25 26 27 28 29 30 31 32 33 34 |
# File 'rumale-evaluation_measure/lib/rumale/evaluation_measure/explained_variance_score.rb', line 22 def score(y_true, y_pred) diff = y_true - y_pred numerator = ((diff - diff.mean(0))**2).mean(0) denominator = ((y_true - y_true.mean(0))**2).mean(0) n_outputs = y_true.shape[1] if n_outputs.nil? denominator.zero? ? 0 : 1.0 - numerator / denominator else valids = denominator.ne(0) (1.0 - numerator[valids] / denominator[valids]).sum / n_outputs end end |