fix: post-review changes
This commit is contained in:
@@ -88,14 +88,6 @@ pub struct BernoulliNBParameters<T: RealNumber> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
impl<T: RealNumber> BernoulliNBParameters<T> {
|
impl<T: RealNumber> BernoulliNBParameters<T> {
|
||||||
/// Create BernoulliNBParameters with specific paramaters.
|
|
||||||
pub fn new(alpha: T, priors: Option<Vec<T>>, binarize: Option<T>) -> Self {
|
|
||||||
Self {
|
|
||||||
alpha,
|
|
||||||
priors,
|
|
||||||
binarize,
|
|
||||||
}
|
|
||||||
}
|
|
||||||
/// Additive (Laplace/Lidstone) smoothing parameter (0 for no smoothing).
|
/// Additive (Laplace/Lidstone) smoothing parameter (0 for no smoothing).
|
||||||
pub fn with_alpha(mut self, alpha: T) -> Self {
|
pub fn with_alpha(mut self, alpha: T) -> Self {
|
||||||
self.alpha = alpha;
|
self.alpha = alpha;
|
||||||
|
|||||||
@@ -223,17 +223,6 @@ pub struct CategoricalNBParameters<T: RealNumber> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
impl<T: RealNumber> CategoricalNBParameters<T> {
|
impl<T: RealNumber> CategoricalNBParameters<T> {
|
||||||
/// Create CategoricalNBParameters with specific paramaters.
|
|
||||||
pub fn new(alpha: T) -> Result<Self, Failed> {
|
|
||||||
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).
|
/// Additive (Laplace/Lidstone) smoothing parameter (0 for no smoothing).
|
||||||
pub fn with_alpha(mut self, alpha: T) -> Self {
|
pub fn with_alpha(mut self, alpha: T) -> Self {
|
||||||
self.alpha = alpha;
|
self.alpha = alpha;
|
||||||
|
|||||||
@@ -82,10 +82,6 @@ pub struct GaussianNBParameters<T: RealNumber> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
impl<T: RealNumber> GaussianNBParameters<T> {
|
impl<T: RealNumber> GaussianNBParameters<T> {
|
||||||
/// Create GaussianNBParameters with specific paramaters.
|
|
||||||
pub fn new(priors: Option<Vec<T>>) -> Self {
|
|
||||||
Self { priors }
|
|
||||||
}
|
|
||||||
/// Prior probabilities of the classes. If specified the priors are not adjusted according to the data
|
/// Prior probabilities of the classes. If specified the priors are not adjusted according to the data
|
||||||
pub fn with_priors(mut self, priors: Vec<T>) -> Self {
|
pub fn with_priors(mut self, priors: Vec<T>) -> Self {
|
||||||
self.priors = Some(priors);
|
self.priors = Some(priors);
|
||||||
@@ -266,7 +262,7 @@ mod tests {
|
|||||||
let y = vec![1., 1., 1., 2., 2., 2.];
|
let y = vec![1., 1., 1., 2., 2., 2.];
|
||||||
|
|
||||||
let priors = vec![0.3, 0.7];
|
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();
|
let gnb = GaussianNB::fit(&x, &y, parameters).unwrap();
|
||||||
|
|
||||||
assert_eq!(gnb.inner.distribution.class_priors, priors);
|
assert_eq!(gnb.inner.distribution.class_priors, priors);
|
||||||
|
|||||||
@@ -82,10 +82,6 @@ pub struct MultinomialNBParameters<T: RealNumber> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
impl<T: RealNumber> MultinomialNBParameters<T> {
|
impl<T: RealNumber> MultinomialNBParameters<T> {
|
||||||
/// Create MultinomialNBParameters with specific paramaters.
|
|
||||||
pub fn new(alpha: T, priors: Option<Vec<T>>) -> Self {
|
|
||||||
Self { alpha, priors }
|
|
||||||
}
|
|
||||||
/// Additive (Laplace/Lidstone) smoothing parameter (0 for no smoothing).
|
/// Additive (Laplace/Lidstone) smoothing parameter (0 for no smoothing).
|
||||||
pub fn with_alpha(mut self, alpha: T) -> Self {
|
pub fn with_alpha(mut self, alpha: T) -> Self {
|
||||||
self.alpha = alpha;
|
self.alpha = alpha;
|
||||||
|
|||||||
Reference in New Issue
Block a user