9float mse(
const VectorXf& y,
const VectorXf&
yhat, VectorXf& loss,
10 const vector<float>& class_weights)
12 loss = (
yhat - y).array().pow(2);
16VectorXf
log_loss(
const VectorXf& y,
const VectorXf& predict_proba,
17 const vector<float>& class_weights)
19 float eps = pow(10,-10);
24 loss.resize(y.rows());
25 for (
unsigned i = 0;
i < y.rows(); ++
i)
27 if (predict_proba(
i) <
eps || 1 - predict_proba(
i) <
eps)
29 loss(
i) = -(y(
i)*log(
eps) + (1-y(
i))*log(1-
eps));
31 loss(
i) = -(y(
i)*log(predict_proba(
i)) + (1-y(
i))*log(1-predict_proba(
i)));
33 std::runtime_error(
"loss(i)= " + to_string(loss(
i))
34 +
". y = " + to_string(y(
i)) +
", predict_proba(i) = "
35 + to_string(predict_proba(
i)));
37 if (!class_weights.empty())
39 loss(
i) = loss(
i) * class_weights.at(y(
i));
52 const VectorXf& predict_proba, VectorXf& loss,
53 const vector<float>& class_weights)
55 loss =
log_loss(y,predict_proba,class_weights);
61 const vector<float>& class_weights) {
64 vector<int> argsort(predict_proba.size());
65 iota(argsort.begin(), argsort.end(), 0);
66 sort(argsort.begin(), argsort.end(), [&](
int i,
int j) {
67 return predict_proba[i] > predict_proba[j];
71 if (!class_weights.empty())
72 for (
int i = 0;
i < class_weights.size();
i++) {
73 ysum += y(
i) * class_weights.at(y(
i));
80 VectorXf
recall(predict_proba.size());
86 for (
int i = 0;
i < predict_proba.size();
i++) {
87 if (predict_proba[argsort[
i]] >= 0.5 && y[argsort[
i]] == 1) {
91 if (!class_weights.empty())
106 for (
int i = 0;
i < predict_proba.size();
i++) {
119 const vector<float>& class_weights)
122 VectorXf loss = VectorXf::Zero(y.rows());
170 const ArrayXXf& predict_proba, VectorXf& loss,
171 const vector<float>& class_weights)
void bind_engine(py::module &m, string name)
float mean_log_loss(const VectorXf &y, const VectorXf &predict_proba, VectorXf &loss, const vector< float > &class_weights)
log loss
float mean_multi_log_loss(const VectorXf &y, const ArrayXXf &predict_proba, VectorXf &loss, const vector< float > &class_weights)
Calculates the mean multinomial log loss between the predicted probabilities and the true labels.
float average_precision_score(const VectorXf &y, const VectorXf &predict_proba, VectorXf &loss, const vector< float > &class_weights)
Calculates the average precision score between the predicted probabilities and the true labels.
float mse(const VectorXf &y, const VectorXf &yhat, VectorXf &loss, const vector< float > &class_weights)
mean squared error
VectorXf multi_log_loss(const VectorXf &y, const ArrayXXf &predict_proba, const vector< float > &class_weights)
Calculates the multinomial log loss between the predicted probabilities and the true labels.
VectorXf log_loss(const VectorXf &y, const VectorXf &predict_proba, const vector< float > &class_weights)
Calculates the log loss between the predicted probabilities and the true labels.
< nsga2 selection operator for getting the front
Namespace containing scoring functions for evaluation metrics.