mlpack
accuracy_impl.hpp
Go to the documentation of this file.
1 
12 #ifndef MLPACK_CORE_CV_METRICS_ACCURACY_IMPL_HPP
13 #define MLPACK_CORE_CV_METRICS_ACCURACY_IMPL_HPP
14 
15 namespace mlpack {
16 namespace cv {
17 
18 template<typename MLAlgorithm, typename DataType>
19 double Accuracy::Evaluate(MLAlgorithm& model,
20  const DataType& data,
21  const arma::Row<size_t>& labels)
22 {
23  util::CheckSameSizes(data, labels, "Accuracy::Evaluate()");
24 
25  arma::Row<size_t> predictedLabels;
26  model.Classify(data, predictedLabels);
27  size_t amountOfCorrectPredictions = arma::sum(predictedLabels == labels);
28 
29  return (double) amountOfCorrectPredictions / labels.n_elem;
30 }
31 
32 } // namespace cv
33 } // namespace mlpack
34 
35 #endif
Linear algebra utility functions, generally performed on matrices or vectors.
Definition: cv.hpp:1
static double Evaluate(MLAlgorithm &model, const DataType &data, const arma::Row< size_t > &labels)
Run classification and calculate accuracy.
Definition: accuracy_impl.hpp:19