From 55932f751b4232e8e4ef85db03064e0da1988ea5 Mon Sep 17 00:00:00 2001 From: m7142yosuke Date: Wed, 16 Nov 2022 09:53:03 +0900 Subject: [PATCH 1/4] Add flag to pretty-print --- src/naive_bayes/gaussian.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/naive_bayes/gaussian.rs b/src/naive_bayes/gaussian.rs index a9c1d4fe..2fe875ed 100644 --- a/src/naive_bayes/gaussian.rs +++ b/src/naive_bayes/gaussian.rs @@ -279,7 +279,7 @@ impl< > fmt::Display for GaussianNB { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { - writeln!(f, "GaussianNB:\ninner: {:?}", self.inner.as_ref().unwrap())?; + writeln!(f, "GaussianNB:\ninner: {:#?}", self.inner.as_ref().unwrap())?; Ok(()) } } From 90f84600ba76aa6c029c8dc7b11980c888a59ce7 Mon Sep 17 00:00:00 2001 From: m7142yosuke Date: Thu, 17 Nov 2022 15:30:32 +0900 Subject: [PATCH 2/4] print only distribution --- src/naive_bayes/gaussian.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/naive_bayes/gaussian.rs b/src/naive_bayes/gaussian.rs index 2fe875ed..e73041ca 100644 --- a/src/naive_bayes/gaussian.rs +++ b/src/naive_bayes/gaussian.rs @@ -279,7 +279,7 @@ impl< > fmt::Display for GaussianNB { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { - writeln!(f, "GaussianNB:\ninner: {:#?}", self.inner.as_ref().unwrap())?; + writeln!(f, "GaussianNB:\ninner: {:#?}", self.inner.as_ref().unwrap().distribution)?; Ok(()) } } From f2d0af2f6693a3b2dd2de0e279475f828948d049 Mon Sep 17 00:00:00 2001 From: m7142yosuke Date: Tue, 22 Nov 2022 10:45:22 +0900 Subject: [PATCH 3/4] improve Display for naive_bayes --- src/naive_bayes/gaussian.rs | 25 +++++++++++++++++++++---- 1 file changed, 21 insertions(+), 4 deletions(-) diff --git a/src/naive_bayes/gaussian.rs b/src/naive_bayes/gaussian.rs index e73041ca..989e7717 100644 --- a/src/naive_bayes/gaussian.rs +++ b/src/naive_bayes/gaussian.rs @@ -51,14 +51,31 @@ struct GaussianNBDistribution { theta: Vec>, } +impl< + TX: Number + RealNumber + RealNumber, + TY: Number + Ord + Unsigned, + X: Array2, + Y: Array1, + > fmt::Display for BaseNaiveBayes> +{ + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { + writeln!(f, "BaseNaiveBayes: {{\n distribution: {}}}", self.distribution)?; + Ok(()) + } +} + impl fmt::Display for GaussianNBDistribution { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { writeln!( f, - "GaussianNBDistribution: class_count: {:?}", - self.class_count + "GaussianNBDistribution: {{" )?; - writeln!(f, "class_labels: {:?}", self.class_labels)?; + 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(()) } } @@ -279,7 +296,7 @@ impl< > fmt::Display for GaussianNB { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { - writeln!(f, "GaussianNB:\ninner: {:#?}", self.inner.as_ref().unwrap().distribution)?; + writeln!(f, "GaussianNB:\n inner: {}", self.inner.as_ref().unwrap())?; Ok(()) } } From c40725e599ab1b09a5684d042961ab926f9db052 Mon Sep 17 00:00:00 2001 From: m7142yosuke Date: Tue, 22 Nov 2022 10:46:16 +0900 Subject: [PATCH 4/4] cargo fmt --- src/naive_bayes/gaussian.rs | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/src/naive_bayes/gaussian.rs b/src/naive_bayes/gaussian.rs index 989e7717..0cedc1de 100644 --- a/src/naive_bayes/gaussian.rs +++ b/src/naive_bayes/gaussian.rs @@ -59,17 +59,18 @@ impl< > fmt::Display for BaseNaiveBayes> { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { - writeln!(f, "BaseNaiveBayes: {{\n distribution: {}}}", self.distribution)?; + writeln!( + f, + "BaseNaiveBayes: {{\n distribution: {}}}", + self.distribution + )?; Ok(()) } } impl fmt::Display for GaussianNBDistribution { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { - writeln!( - f, - "GaussianNBDistribution: {{" - )?; + writeln!(f, "GaussianNBDistribution: {{")?; writeln!(f, " class_labels: {:?},", self.class_labels)?; writeln!(f, " class_count: {:?},", self.class_count)?; writeln!(f, " class_priors: {:?},", self.class_priors)?;