mirror of
https://github.com/Magnus167/rustframe.git
synced 2025-08-20 04:00:01 +00:00
Refactor error handling in GaussianNB fit method to use assert instead of panic for empty class labels
This commit is contained in:
parent
2cd2e24f57
commit
e7c181f011
@ -59,9 +59,7 @@ impl GaussianNB {
|
||||
let bits = label.to_bits();
|
||||
groups.entry(bits).or_default().push(i);
|
||||
}
|
||||
if groups.is_empty() {
|
||||
panic!("No class labels found in y");
|
||||
}
|
||||
assert!(!groups.is_empty(), "No class labels found in y"); //-- panicked earlier
|
||||
|
||||
// Extract and sort class labels
|
||||
self.classes = groups.keys().cloned().map(f64::from_bits).collect();
|
||||
@ -209,6 +207,5 @@ mod tests {
|
||||
let y = Matrix::from_vec(vec![0.0], 1, 1);
|
||||
let mut clf = GaussianNB::new(1e-9, false);
|
||||
clf.fit(&x, &y);
|
||||
clf.predict(&x);
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user