Feat C++ API
A feature engineering automation tool
scorer.cc
Go to the documentation of this file.
1 /* FEAT
2 copyright 2017 William La Cava
3 license: GNU/GPL v3
4 */
5 // internal includes
6 #include "metrics.h"
7 #include "scorer.h"
8 using namespace shogun;
9 using Eigen::Map;
10 
11 // code to evaluate GP programs.
12 namespace FT{
13 
18  namespace Eval{
20 
25  Scorer::Scorer(string scorer)
26  {
27  score_hash["mse"] = &mse_label;
28  score_hash["zero_one"] = &zero_one_loss_label;
29  score_hash["bal_zero_one"] = &bal_zero_one_loss_label;
30  score_hash["log"] = &log_loss_label;
31  score_hash["multi_log"] = &multi_log_loss_label;
32  score_hash["fpr"] = &false_positive_loss_label;
33 
34  this->set_scorer(scorer);
35  }
36  void Scorer::set_scorer(string scorer)
37  {
38  this->scorer = scorer;
39  }
40 
41  float Scorer::score(const VectorXf& y_true,
42  const shared_ptr<CLabels>& yhat,
43  VectorXf& loss,
44  const vector<float>& w)
45  {
46  if ( score_hash.find(this->scorer) == score_hash.end() )
47  {
48  // not found
49  THROW_INVALID_ARGUMENT("Scoring function '" + this->scorer
50  + "' not defined");
51  return 0;
52  }
53  else
54  {
55  // found
56  return score_hash.at(this->scorer)(y_true, yhat, loss, w);
57  }
58  }
59  // overloaded score with no loss
60  float Scorer::score(const VectorXf& y_true,
61  const shared_ptr<CLabels>& yhat,
62  vector<float> w)
63  {
64  VectorXf dummy;
65  return this->score(y_true, yhat, dummy, w);
66  }
67  }
68 }
#define THROW_INVALID_ARGUMENT(err)
Definition: error.h:31
float bal_zero_one_loss_label(const VectorXf &y, const shared_ptr< CLabels > &labels, VectorXf &loss, const vector< float > &class_weights)
Definition: metrics.cc:412
float zero_one_loss_label(const VectorXf &y, const shared_ptr< CLabels > &labels, VectorXf &loss, const vector< float > &class_weights)
1 - accuracy
Definition: metrics.cc:444
float mse_label(const VectorXf &y, const shared_ptr< CLabels > &labels, VectorXf &loss, const vector< float > &weights)
Definition: metrics.cc:77
float multi_log_loss_label(const VectorXf &y, const shared_ptr< CLabels > &labels, VectorXf &loss, const vector< float > &class_weights)
multinomial log loss
Definition: metrics.cc:250
float false_positive_loss_label(const VectorXf &y, const shared_ptr< CLabels > &labels, VectorXf &loss, const vector< float > &class_weights)
false positive rate
Definition: metrics.cc:468
float log_loss_label(const VectorXf &y, const shared_ptr< CLabels > &labels, VectorXf &loss, const vector< float > &class_weights)
log loss
Definition: metrics.cc:147
main Feat namespace
Definition: data.cc:13