lib/svmkit/evaluation_measure/accuracy.rb in svmkit-0.2.7 vs lib/svmkit/evaluation_measure/accuracy.rb in svmkit-0.2.8
- old
+ new
@@ -17,9 +17,12 @@
#
# @param y_true [Numo::Int32] (shape: [n_samples]) Ground truth labels.
# @param y_pred [Numo::Int32] (shape: [n_samples]) Predicted labels.
# @return [Float] Mean accuracy
def score(y_true, y_pred)
+ SVMKit::Validation.check_label_array(y_true)
+ SVMKit::Validation.check_label_array(y_pred)
+
(y_true.to_a.map.with_index { |label, n| label == y_pred[n] ? 1 : 0 }).inject(:+) / y_true.size.to_f
end
end
end
end