feat: + builders for algorithm parameters

This commit is contained in:
Volodymyr Orlov
2020-12-23 12:29:39 -08:00
parent 74f0d9e6fb
commit dd341f4a12
17 changed files with 276 additions and 8 deletions
+15
View File
@@ -96,6 +96,21 @@ impl<T: RealNumber> BernoulliNBParameters<T> {
binarize,
}
}
/// Additive (Laplace/Lidstone) smoothing parameter (0 for no smoothing).
pub fn with_alpha(mut self, alpha: T) -> Self {
self.alpha = alpha;
self
}
/// 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 {
self.priors = Some(priors);
self
}
/// Threshold for binarizing (mapping to booleans) of sample features. If None, input is presumed to already consist of binary vectors.
pub fn with_binarize(mut self, binarize: T) -> Self {
self.binarize = Some(binarize);
self
}
}
impl<T: RealNumber> Default for BernoulliNBParameters<T> {
+6
View File
@@ -234,7 +234,13 @@ impl<T: RealNumber> CategoricalNBParameters<T> {
)))
}
}
/// Additive (Laplace/Lidstone) smoothing parameter (0 for no smoothing).
pub fn with_alpha(mut self, alpha: T) -> Self {
self.alpha = alpha;
self
}
}
impl<T: RealNumber> Default for CategoricalNBParameters<T> {
fn default() -> Self {
Self { alpha: T::one() }
+5
View File
@@ -86,6 +86,11 @@ impl<T: RealNumber> GaussianNBParameters<T> {
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
pub fn with_priors(mut self, priors: Vec<T>) -> Self {
self.priors = Some(priors);
self
}
}
impl<T: RealNumber> GaussianNBDistribution<T> {
+10
View File
@@ -86,6 +86,16 @@ impl<T: RealNumber> MultinomialNBParameters<T> {
pub fn new(alpha: T, priors: Option<Vec<T>>) -> 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;
self
}
/// 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 {
self.priors = Some(priors);
self
}
}
impl<T: RealNumber> Default for MultinomialNBParameters<T> {