entrenar/eval/evaluator/
result.rs1use super::metric::Metric;
4use std::collections::HashMap;
5use std::fmt;
6
7#[derive(Clone, Debug)]
9pub struct EvalResult {
10 pub model_name: String,
12 pub scores: HashMap<Metric, f64>,
14 pub cv_scores: Option<Vec<f64>>,
16 pub cv_mean: Option<f64>,
18 pub cv_std: Option<f64>,
20 pub inference_time_ms: f64,
22 pub trace_id: Option<String>,
24}
25
26impl EvalResult {
27 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 pub fn get_score(&self, metric: Metric) -> Option<f64> {
42 self.scores.get(&metric).copied()
43 }
44
45 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}