Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix #225: Improve Display for naive_bayes #241

Open
wants to merge 5 commits into
base: development
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 23 additions & 5 deletions src/naive_bayes/gaussian.rs
Original file line number Diff line number Diff line change
Expand Up @@ -51,14 +51,32 @@ struct GaussianNBDistribution<T: Number> {
theta: Vec<Vec<f64>>,
}

impl<T: Number + Ord + Unsigned> fmt::Display for GaussianNBDistribution<T> {
impl<
TX: Number + RealNumber + RealNumber,
TY: Number + Ord + Unsigned,
X: Array2<TX>,
Y: Array1<TY>,
> fmt::Display for BaseNaiveBayes<TX, TY, X, Y, GaussianNBDistribution<TY>>
{
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
writeln!(
f,
"GaussianNBDistribution: class_count: {:?}",
self.class_count
"BaseNaiveBayes: {{\n distribution: {}}}",
self.distribution
)?;
writeln!(f, "class_labels: {:?}", self.class_labels)?;
Ok(())
}
}

impl<T: Number + Ord + Unsigned> fmt::Display for GaussianNBDistribution<T> {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
writeln!(f, "GaussianNBDistribution: {{")?;
writeln!(f, " class_labels: {:?},", self.class_labels)?;
writeln!(f, " class_count: {:?},", self.class_count)?;
writeln!(f, " class_priors: {:?},", self.class_priors)?;
writeln!(f, " var: {:?},", self.var)?;
writeln!(f, " theta: {:?}", self.theta)?;
write!(f, "}}")?;
Ok(())
}
}
Expand Down Expand Up @@ -277,7 +295,7 @@ impl<
> fmt::Display for GaussianNB<TX, TY, X, Y>
{
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
writeln!(f, "GaussianNB:\ninner: {:?}", self.inner.as_ref().unwrap())?;
writeln!(f, "GaussianNB:\n inner: {}", self.inner.as_ref().unwrap())?;
Ok(())
}
}
Expand Down