Class: Rumale::EvaluationMeasure::ExplainedVarianceScore
- Inherits:
-
Object
- Object
- Rumale::EvaluationMeasure::ExplainedVarianceScore
- Includes:
- Base::Evaluator
- Defined in:
- 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.
20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 |
# File 'lib/rumale/evaluation_measure/explained_variance_score.rb', line 20 def score(y_true, y_pred) check_tvalue_array(y_true) check_tvalue_array(y_pred) raise ArgumentError, 'Expect to have the same size both y_true and y_pred.' unless y_true.shape == y_pred.shape 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 |