Skip to main content

permutation_importance

Function permutation_importance 

Source
pub fn permutation_importance(
    features: &[Vec<f64>],
    target: &[f64],
    predict: &dyn Fn(&[Vec<f64>]) -> Vec<f64>,
    scorer: fn(&[f64], &[f64]) -> f64,
    n_repeats: usize,
    seed: u64,
) -> PermutationImportance
Expand description

Compute permutation importance for any model.

§Arguments

  • features - Column-major feature matrix: features[feature_idx][sample_idx].
  • target - Target values, one per sample.
  • predict - Prediction function: given column-major features, returns predictions.
  • scorer - Scoring function: scorer(y_true, y_pred) -> score. Higher is better (e.g. accuracy, R2). The importance is baseline_score - permuted_score.
  • n_repeats - Number of times to permute each feature (default: 5).
  • seed - RNG seed for reproducibility.

§Returns

A PermutationImportance with mean, std, and raw importances per feature.

§Panics

Panics if features is empty or if feature columns have different lengths.