Skip to main content

entrenar/eval/evaluator/
result.rs

1//! Evaluation result structure
2
3use super::metric::Metric;
4use std::collections::HashMap;
5use std::fmt;
6
7/// Model evaluation results
8#[derive(Clone, Debug)]
9pub struct EvalResult {
10    /// Name of the model
11    pub model_name: String,
12    /// Computed metric scores
13    pub scores: HashMap<Metric, f64>,
14    /// Cross-validation scores per fold (if CV enabled)
15    pub cv_scores: Option<Vec<f64>>,
16    /// Mean CV score
17    pub cv_mean: Option<f64>,
18    /// CV score standard deviation
19    pub cv_std: Option<f64>,
20    /// Inference time in milliseconds
21    pub inference_time_ms: f64,
22    /// Optional trace ID for observability
23    pub trace_id: Option<String>,
24}
25
26impl EvalResult {
27    /// Create new eval result
28    pub fn new(model_name: impl Into<String>) -> Self {
29        Self {
30            model_name: model_name.into(),
31            scores: HashMap::new(),
32            cv_scores: None,
33            cv_mean: None,
34            cv_std: None,
35            inference_time_ms: 0.0,
36            trace_id: None,
37        }
38    }
39
40    /// Get score for a specific metric
41    pub fn get_score(&self, metric: Metric) -> Option<f64> {
42        self.scores.get(&metric).copied()
43    }
44
45    /// Add a score
46    pub fn add_score(&mut self, metric: Metric, score: f64) {
47        self.scores.insert(metric, score);
48    }
49}
50
51impl fmt::Display for EvalResult {
52    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
53        writeln!(f, "Model: {}", self.model_name)?;
54        writeln!(f, "Metrics:")?;
55        for (metric, score) in &self.scores {
56            writeln!(f, "  {metric}: {score:.4}")?;
57        }
58        writeln!(f, "Inference time: {:.2}ms", self.inference_time_ms)?;
59        Ok(())
60    }
61}