Skip to content

Commit 22c9640

Browse files
committed
fmt
1 parent 8881439 commit 22c9640

File tree

2 files changed

+8
-12
lines changed

2 files changed

+8
-12
lines changed

src/naive_bayes/gaussian.rs

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -427,22 +427,18 @@ mod tests {
427427

428428
#[test]
429429
fn run_gaussian_naive_bayes_with_few_samples() {
430-
let x = DenseMatrix::<f64>::from_2d_array(&[
431-
&[-1., -1.],
432-
&[-2., -1.],
433-
&[-3., -2.],
434-
&[1., 1.],
435-
]);
430+
let x =
431+
DenseMatrix::<f64>::from_2d_array(&[&[-1., -1.], &[-2., -1.], &[-3., -2.], &[1., 1.]]);
436432
let y: Vec<u32> = vec![1, 1, 1, 2];
437433

438434
let gnb = GaussianNB::fit(&x, &y, Default::default());
439435

440436
match gnb.unwrap().predict(&x) {
441437
Ok(_) => assert!(false, "test should return Failed"),
442438
Err(err) => {
443-
assert!(err.to_string() == "Can't find solution: log_likelihood for distribution of one of the rows is NaN");
439+
assert!(err.to_string() == "Can't find solution: log_likelihood for distribution of one of the rows is NaN");
444440
assert!(true)
445-
},
441+
}
446442
}
447443
}
448444

src/naive_bayes/mod.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -101,17 +101,17 @@ impl<TX: Number, TY: Number, X: Array2<TX>, Y: Array1<TY>, D: NBDistribution<TX,
101101
.iter()
102102
.enumerate()
103103
.map(|(class_index, class)| {
104-
let mut log_likelihood = self.distribution.log_likelihood(class_index, &row);
104+
let mut log_likelihood =
105+
self.distribution.log_likelihood(class_index, &row);
105106
if log_likelihood.is_nan() {
106107
log_likelihood = 0f64;
107108
log_likehood_is_nan = true;
108109
}
109110
(
110111
class,
111-
log_likelihood
112-
+ self.distribution.prior(class_index).ln(),
112+
log_likelihood + self.distribution.prior(class_index).ln(),
113113
)
114-
})
114+
})
115115
.max_by(|(_, p1), (_, p2)| p1.partial_cmp(p2).unwrap())
116116
.unwrap();
117117
*prediction

0 commit comments

Comments
 (0)