From d22be7d6ae44c1fddc412fde9ca434070ae890b5 Mon Sep 17 00:00:00 2001 From: Volodymyr Orlov Date: Thu, 24 Dec 2020 13:47:09 -0800 Subject: [PATCH] fix: post-review changes --- src/naive_bayes/bernoulli.rs | 8 -------- src/naive_bayes/categorical.rs | 11 ----------- src/naive_bayes/gaussian.rs | 6 +----- src/naive_bayes/multinomial.rs | 4 ---- 4 files changed, 1 insertion(+), 28 deletions(-) diff --git a/src/naive_bayes/bernoulli.rs b/src/naive_bayes/bernoulli.rs index db98efc..c6cbfa8 100644 --- a/src/naive_bayes/bernoulli.rs +++ b/src/naive_bayes/bernoulli.rs @@ -88,14 +88,6 @@ pub struct BernoulliNBParameters { } impl BernoulliNBParameters { - /// Create BernoulliNBParameters with specific paramaters. - pub fn new(alpha: T, priors: Option>, binarize: Option) -> Self { - Self { - alpha, - priors, - binarize, - } - } /// Additive (Laplace/Lidstone) smoothing parameter (0 for no smoothing). pub fn with_alpha(mut self, alpha: T) -> Self { self.alpha = alpha; diff --git a/src/naive_bayes/categorical.rs b/src/naive_bayes/categorical.rs index ea81eb5..667a270 100644 --- a/src/naive_bayes/categorical.rs +++ b/src/naive_bayes/categorical.rs @@ -223,17 +223,6 @@ pub struct CategoricalNBParameters { } impl CategoricalNBParameters { - /// Create CategoricalNBParameters with specific paramaters. - pub fn new(alpha: T) -> Result { - if alpha > T::zero() { - Ok(Self { alpha }) - } else { - Err(Failed::fit(&format!( - "alpha should be >= 0, alpha=[{}]", - alpha - ))) - } - } /// Additive (Laplace/Lidstone) smoothing parameter (0 for no smoothing). pub fn with_alpha(mut self, alpha: T) -> Self { self.alpha = alpha; diff --git a/src/naive_bayes/gaussian.rs b/src/naive_bayes/gaussian.rs index f1fc812..bc96420 100644 --- a/src/naive_bayes/gaussian.rs +++ b/src/naive_bayes/gaussian.rs @@ -82,10 +82,6 @@ pub struct GaussianNBParameters { } impl GaussianNBParameters { - /// Create GaussianNBParameters with specific paramaters. - pub fn new(priors: Option>) -> Self { - Self { priors } - } /// Prior probabilities of the classes. If specified the priors are not adjusted according to the data pub fn with_priors(mut self, priors: Vec) -> Self { self.priors = Some(priors); @@ -266,7 +262,7 @@ mod tests { let y = vec![1., 1., 1., 2., 2., 2.]; let priors = vec![0.3, 0.7]; - let parameters = GaussianNBParameters::new(Some(priors.clone())); + let parameters = GaussianNBParameters::default().with_priors(priors.clone()); let gnb = GaussianNB::fit(&x, &y, parameters).unwrap(); assert_eq!(gnb.inner.distribution.class_priors, priors); diff --git a/src/naive_bayes/multinomial.rs b/src/naive_bayes/multinomial.rs index 50d2ee2..237b606 100644 --- a/src/naive_bayes/multinomial.rs +++ b/src/naive_bayes/multinomial.rs @@ -82,10 +82,6 @@ pub struct MultinomialNBParameters { } impl MultinomialNBParameters { - /// Create MultinomialNBParameters with specific paramaters. - pub fn new(alpha: T, priors: Option>) -> Self { - Self { alpha, priors } - } /// Additive (Laplace/Lidstone) smoothing parameter (0 for no smoothing). pub fn with_alpha(mut self, alpha: T) -> Self { self.alpha = alpha;