Implement Display for NaiveBayes

This commit is contained in:
Lorenzo (Mec-iS)
2022-11-03 14:18:56 +00:00
parent d298709040
commit ba70bb941f
4 changed files with 62 additions and 0 deletions
+17
View File
@@ -364,6 +364,20 @@ pub struct BernoulliNB<
binarize: Option<TX>,
}
impl<TX: Number + PartialOrd, TY: Number + Ord + Unsigned, X: Array2<TX>, Y: Array1<TY>>
fmt::Display for BernoulliNB<TX, TY, X, Y>
{
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
writeln!(
f,
"BernoulliNB:\ninner: {:?}\nbinarize: {:?}",
self.inner.as_ref().unwrap(),
self.binarize.as_ref().unwrap()
)?;
Ok(())
}
}
impl<TX: Number + PartialOrd, TY: Number + Ord + Unsigned, X: Array2<TX>, Y: Array1<TY>>
SupervisedEstimator<X, Y, BernoulliNBParameters<TX>> for BernoulliNB<TX, TY, X, Y>
{
@@ -594,6 +608,9 @@ mod tests {
]
);
// test Display
println!("{}", &bnb);
let distribution = bnb.inner.clone().unwrap().distribution;
assert_eq!(