A comprehensive library for machine learning and numerical computing. The library provides a set of tools for linear algebra, numerical computing, optimization, and enables a generic, powerful yet still efficient approach to machine learning.
Prediction of GaussianNB fails when trained on very small data.
Expected Behaviour:
Assertion of Y may fail but should not panic.
Steps to reproduce:
#[test]
fn run_gaussian_naive_bayes_with_few_samples() {
let x = DenseMatrix::<f64>::from_2d_array(&[
&[-1., -1.],
&[-2., -1.],
&[-3., -2.],
&[1., 1.],
]);
let y: Vec<u32> = vec![1, 1, 1, 2];
let gnb = GaussianNB::fit(&x, &y, Default::default()).unwrap();
assert_eq!(gnb.classes(), &[1, 2]);
let y_hat = gnb.predict(&x).unwrap();
assert_eq!(y_hat, y);
}
Snapshot:
thread 'classifier::bayes::tests::test_detector' panicked at 'called `Option::unwrap()` on a `None` value', /Users/chriamue/.cargo/registry/src/github.com-1ecc6299db9ec823/smartcore-0.3.0/src/naive_bayes/mod.rs:109:67
I'm submitting a
Current Behaviour:
Prediction of GaussianNB fails when trained on very small data.
Expected Behaviour:
Assertion of Y may fail but should not panic.
Steps to reproduce:
Snapshot:
https://github.com/smartcorelib/smartcore/blob/development/src/naive_bayes/mod.rs#L109
p1 or p2 is NaN so partial_cmp is None which panics on unwrap().
Do you want to work on this issue?
A solution would be to check the log_likelihood for NaN and return 0, but I am not sure if this is mathematically right. https://github.com/smartcorelib/smartcore/blob/development/src/naive_bayes/gaussian.rs#L77
Another solution is to check for NaN in predict function: https://github.com/smartcorelib/smartcore/blob/development/src/naive_bayes/mod.rs#L102