pub fn binary_accuracy<F: Float + Debug>(
predictions: &Array<F, Ix1>,
targets: &Array<F, Ix1>,
threshold: F,
) -> Result<F>
Expand description
Calculate the binary accuracy between predictions and targets
§Arguments
predictions
- Predicted values (should be between 0 and 1)targets
- Target values (should be either 0 or 1)threshold
- Threshold value for binary classification (default: 0.5)
§Returns
- The accuracy (proportion of correct predictions)
§Examples
use scirs2_neural::utils::binary_accuracy;
use ndarray::arr1;
let predictions = arr1(&[0.7f64, 0.3, 0.8, 0.2]);
let targets = arr1(&[1.0f64, 0.0, 1.0, 0.0]);
let accuracy = binary_accuracy(&predictions, &targets, 0.5f64).unwrap();
assert_eq!(accuracy, 1.0f64); // All predictions are correct