Loss functions

statinf.ml.losses.binary_accuracy(y_true, y_pred)[source]

Accuracy for binary data.

Parameters
  • y_true (numpy.array) – Real values on which to compare.

  • y_pred (numpy.array) – Predicted values

Returns

Binary accuracy (in percent)

Return type

float

statinf.ml.losses.binary_cross_entropy(y_true, y_pred)[source]

Binary cross-entropy.

Parameters
  • y_true (numpy.array) – Real values on which to compare.

  • y_pred (numpy.array) – Predicted values.

Formula

\(loss = y_{i} \log \left[ \hat{y}_{i} \right] + (1 - y_{i}) \log \left[1 - \hat{y}_{i} \right]\)

References
Returns

Binary cross-entropy

Return type

float

statinf.ml.losses.log_stability(x, delta=0.0001)[source]

Log-stability for computing loss.

Parameters
  • x (float) – Input value.

  • delta (float, optional) – Constant to move from 0 or 1, defaults to 10e-9.

Returns

Stabilized value where \(\hat{x} \in (0, 1)\)

Return type

float

statinf.ml.losses.mean_squared_error(y_true, y_pred, root=False)[source]

Mean Squared Error.

Parameters
  • y_true (numpy.array) – Real values on which to compare.

  • y_pred (numpy.array) – Predicted values.

  • root (bool, optional) – Return Root Mean Squared Error (RMSE), defaults to False.

Formula

\(loss = \dfrac{1}{m} \times \sum_{i=1}^{m} (y_i - \hat{y}_i)^2\)

References
Returns

Mean Squared Error or its root.

Return type

float