Run cargo clippy --fix (#250)
* Run `cargo clippy --fix` * Run `cargo clippy --all-features --fix` * Fix other clippy warnings * cargo fmt Co-authored-by: Luis Moreno <morenol@users.noreply.github.com>
This commit is contained in:
@@ -271,21 +271,18 @@ impl<TY: Number + Ord + Unsigned> BernoulliNBDistribution<TY> {
|
||||
let y_samples = y.shape();
|
||||
if y_samples != n_samples {
|
||||
return Err(Failed::fit(&format!(
|
||||
"Size of x should equal size of y; |x|=[{}], |y|=[{}]",
|
||||
n_samples, y_samples
|
||||
"Size of x should equal size of y; |x|=[{n_samples}], |y|=[{y_samples}]"
|
||||
)));
|
||||
}
|
||||
|
||||
if n_samples == 0 {
|
||||
return Err(Failed::fit(&format!(
|
||||
"Size of x and y should greater than 0; |x|=[{}]",
|
||||
n_samples
|
||||
"Size of x and y should greater than 0; |x|=[{n_samples}]"
|
||||
)));
|
||||
}
|
||||
if alpha < 0f64 {
|
||||
return Err(Failed::fit(&format!(
|
||||
"Alpha should be greater than 0; |alpha|=[{}]",
|
||||
alpha
|
||||
"Alpha should be greater than 0; |alpha|=[{alpha}]"
|
||||
)));
|
||||
}
|
||||
|
||||
@@ -318,8 +315,7 @@ impl<TY: Number + Ord + Unsigned> BernoulliNBDistribution<TY> {
|
||||
feature_in_class_counter[class_index][idx] +=
|
||||
row_i.to_usize().ok_or_else(|| {
|
||||
Failed::fit(&format!(
|
||||
"Elements of the matrix should be 1.0 or 0.0 |found|=[{}]",
|
||||
row_i
|
||||
"Elements of the matrix should be 1.0 or 0.0 |found|=[{row_i}]"
|
||||
))
|
||||
})?;
|
||||
}
|
||||
|
||||
@@ -158,8 +158,7 @@ impl<T: Number + Unsigned> CategoricalNBDistribution<T> {
|
||||
pub fn fit<X: Array2<T>, Y: Array1<T>>(x: &X, y: &Y, alpha: f64) -> Result<Self, Failed> {
|
||||
if alpha < 0f64 {
|
||||
return Err(Failed::fit(&format!(
|
||||
"alpha should be >= 0, alpha=[{}]",
|
||||
alpha
|
||||
"alpha should be >= 0, alpha=[{alpha}]"
|
||||
)));
|
||||
}
|
||||
|
||||
@@ -167,15 +166,13 @@ impl<T: Number + Unsigned> CategoricalNBDistribution<T> {
|
||||
let y_samples = y.shape();
|
||||
if y_samples != n_samples {
|
||||
return Err(Failed::fit(&format!(
|
||||
"Size of x should equal size of y; |x|=[{}], |y|=[{}]",
|
||||
n_samples, y_samples
|
||||
"Size of x should equal size of y; |x|=[{n_samples}], |y|=[{y_samples}]"
|
||||
)));
|
||||
}
|
||||
|
||||
if n_samples == 0 {
|
||||
return Err(Failed::fit(&format!(
|
||||
"Size of x and y should greater than 0; |x|=[{}]",
|
||||
n_samples
|
||||
"Size of x and y should greater than 0; |x|=[{n_samples}]"
|
||||
)));
|
||||
}
|
||||
let y: Vec<usize> = y.iterator(0).map(|y_i| y_i.to_usize().unwrap()).collect();
|
||||
@@ -202,8 +199,7 @@ impl<T: Number + Unsigned> CategoricalNBDistribution<T> {
|
||||
.max()
|
||||
.ok_or_else(|| {
|
||||
Failed::fit(&format!(
|
||||
"Failed to get the categories for feature = {}",
|
||||
feature
|
||||
"Failed to get the categories for feature = {feature}"
|
||||
))
|
||||
})?;
|
||||
n_categories.push(feature_max + 1);
|
||||
@@ -429,7 +425,6 @@ mod tests {
|
||||
fn search_parameters() {
|
||||
let parameters = CategoricalNBSearchParameters {
|
||||
alpha: vec![1., 2.],
|
||||
..Default::default()
|
||||
};
|
||||
let mut iter = parameters.into_iter();
|
||||
let next = iter.next().unwrap();
|
||||
|
||||
@@ -185,15 +185,13 @@ impl<TY: Number + Ord + Unsigned> GaussianNBDistribution<TY> {
|
||||
let y_samples = y.shape();
|
||||
if y_samples != n_samples {
|
||||
return Err(Failed::fit(&format!(
|
||||
"Size of x should equal size of y; |x|=[{}], |y|=[{}]",
|
||||
n_samples, y_samples
|
||||
"Size of x should equal size of y; |x|=[{n_samples}], |y|=[{y_samples}]"
|
||||
)));
|
||||
}
|
||||
|
||||
if n_samples == 0 {
|
||||
return Err(Failed::fit(&format!(
|
||||
"Size of x and y should greater than 0; |x|=[{}]",
|
||||
n_samples
|
||||
"Size of x and y should greater than 0; |x|=[{n_samples}]"
|
||||
)));
|
||||
}
|
||||
let (class_labels, indices) = y.unique_with_indices();
|
||||
@@ -375,7 +373,6 @@ mod tests {
|
||||
fn search_parameters() {
|
||||
let parameters = GaussianNBSearchParameters {
|
||||
priors: vec![Some(vec![1.]), Some(vec![2.])],
|
||||
..Default::default()
|
||||
};
|
||||
let mut iter = parameters.into_iter();
|
||||
let next = iter.next().unwrap();
|
||||
|
||||
@@ -220,21 +220,18 @@ impl<TY: Number + Ord + Unsigned> MultinomialNBDistribution<TY> {
|
||||
let y_samples = y.shape();
|
||||
if y_samples != n_samples {
|
||||
return Err(Failed::fit(&format!(
|
||||
"Size of x should equal size of y; |x|=[{}], |y|=[{}]",
|
||||
n_samples, y_samples
|
||||
"Size of x should equal size of y; |x|=[{n_samples}], |y|=[{y_samples}]"
|
||||
)));
|
||||
}
|
||||
|
||||
if n_samples == 0 {
|
||||
return Err(Failed::fit(&format!(
|
||||
"Size of x and y should greater than 0; |x|=[{}]",
|
||||
n_samples
|
||||
"Size of x and y should greater than 0; |x|=[{n_samples}]"
|
||||
)));
|
||||
}
|
||||
if alpha < 0f64 {
|
||||
return Err(Failed::fit(&format!(
|
||||
"Alpha should be greater than 0; |alpha|=[{}]",
|
||||
alpha
|
||||
"Alpha should be greater than 0; |alpha|=[{alpha}]"
|
||||
)));
|
||||
}
|
||||
|
||||
@@ -266,8 +263,7 @@ impl<TY: Number + Ord + Unsigned> MultinomialNBDistribution<TY> {
|
||||
feature_in_class_counter[class_index][idx] +=
|
||||
row_i.to_usize().ok_or_else(|| {
|
||||
Failed::fit(&format!(
|
||||
"Elements of the matrix should be convertible to usize |found|=[{}]",
|
||||
row_i
|
||||
"Elements of the matrix should be convertible to usize |found|=[{row_i}]"
|
||||
))
|
||||
})?;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user