From 763a8370ebf4fbc513ac3ff6c032f877ac8fcad2 Mon Sep 17 00:00:00 2001 From: Luis Moreno Date: Sat, 5 Jun 2021 00:25:34 -0400 Subject: [PATCH 1/2] docs: fix documentation of naive bayes structs --- src/naive_bayes/bernoulli.rs | 3 ++- src/naive_bayes/gaussian.rs | 5 +++-- src/naive_bayes/multinomial.rs | 2 +- 3 files changed, 6 insertions(+), 4 deletions(-) diff --git a/src/naive_bayes/bernoulli.rs b/src/naive_bayes/bernoulli.rs index 69eb13c..95c4d36 100644 --- a/src/naive_bayes/bernoulli.rs +++ b/src/naive_bayes/bernoulli.rs @@ -249,7 +249,8 @@ impl BernoulliNBDistribution { } } -/// BernoulliNB implements the categorical naive Bayes algorithm for categorically distributed data. +/// BernoulliNB implements the naive Bayes algorithm for data that follows the Bernoulli +/// distribution. #[cfg_attr(feature = "serde", derive(Serialize, Deserialize))] #[derive(Debug, PartialEq)] pub struct BernoulliNB> { diff --git a/src/naive_bayes/gaussian.rs b/src/naive_bayes/gaussian.rs index b84e65f..bd23919 100644 --- a/src/naive_bayes/gaussian.rs +++ b/src/naive_bayes/gaussian.rs @@ -33,7 +33,7 @@ use crate::naive_bayes::{BaseNaiveBayes, NBDistribution}; #[cfg(feature = "serde")] use serde::{Deserialize, Serialize}; -/// Naive Bayes classifier for categorical features +/// Naive Bayes classifier using Gaussian distribution #[cfg_attr(feature = "serde", derive(Serialize, Deserialize))] #[derive(Debug, PartialEq)] struct GaussianNBDistribution { @@ -179,7 +179,8 @@ impl GaussianNBDistribution { } } -/// GaussianNB implements the categorical naive Bayes algorithm for categorically distributed data. +/// GaussianNB implements the naive Bayes algorithm for data that follows the Gaussian +/// distribution. #[cfg_attr(feature = "serde", derive(Serialize, Deserialize))] #[derive(Debug, PartialEq)] pub struct GaussianNB> { diff --git a/src/naive_bayes/multinomial.rs b/src/naive_bayes/multinomial.rs index 43a022a..f42b99e 100644 --- a/src/naive_bayes/multinomial.rs +++ b/src/naive_bayes/multinomial.rs @@ -212,7 +212,7 @@ impl MultinomialNBDistribution { } } -/// MultinomialNB implements the categorical naive Bayes algorithm for categorically distributed data. +/// MultinomialNB implements the naive Bayes algorithm for multinomially distributed data. #[cfg_attr(feature = "serde", derive(Serialize, Deserialize))] #[derive(Debug, PartialEq)] pub struct MultinomialNB> { From 0b3bf946dfc40153b910e61a05de6dd90c95b6d7 Mon Sep 17 00:00:00 2001 From: Luis Moreno Date: Sat, 5 Jun 2021 01:00:38 -0400 Subject: [PATCH 2/2] chore: fix clippy warnings --- src/linalg/evd.rs | 2 +- src/linalg/ndarray_bindings.rs | 2 +- src/naive_bayes/categorical.rs | 2 +- src/preprocessing/series_encoder.rs | 6 ++---- 4 files changed, 5 insertions(+), 7 deletions(-) diff --git a/src/linalg/evd.rs b/src/linalg/evd.rs index 78b6cc2..81e2315 100644 --- a/src/linalg/evd.rs +++ b/src/linalg/evd.rs @@ -93,7 +93,7 @@ pub trait EVDDecomposableMatrix: BaseMatrix { sort(&mut d, &mut e, &mut V); } - Ok(EVD { V, d, e }) + Ok(EVD { d, e, V }) } } diff --git a/src/linalg/ndarray_bindings.rs b/src/linalg/ndarray_bindings.rs index 0aa97aa..e081dcc 100644 --- a/src/linalg/ndarray_bindings.rs +++ b/src/linalg/ndarray_bindings.rs @@ -966,7 +966,7 @@ mod tests { let error: f64 = y .into_iter() .zip(y_hat.into_iter()) - .map(|(&a, &b)| (a - b).abs()) + .map(|(a, b)| (a - b).abs()) .sum(); assert!(error <= 1.0); diff --git a/src/naive_bayes/categorical.rs b/src/naive_bayes/categorical.rs index 51619b6..44e5dd9 100644 --- a/src/naive_bayes/categorical.rs +++ b/src/naive_bayes/categorical.rs @@ -232,8 +232,8 @@ impl CategoricalNBDistribution { class_labels, class_priors, coefficients, - n_categories, n_features, + n_categories, category_count, }) } diff --git a/src/preprocessing/series_encoder.rs b/src/preprocessing/series_encoder.rs index 2cd4133..ab99b08 100644 --- a/src/preprocessing/series_encoder.rs +++ b/src/preprocessing/series_encoder.rs @@ -134,10 +134,8 @@ where U: RealNumber, V: BaseVector, { - match self.get_num(category) { - None => None, - Some(&idx) => Some(make_one_hot::(idx, self.num_categories)), - } + self.get_num(category) + .map(|&idx| make_one_hot::(idx, self.num_categories)) } /// Invert one-hot vector, back to the category