chore: update clippy lints (#272)
* chore: fix clippy lints --------- Co-authored-by: Luis Moreno <morenol@users.noreply.github.com>
This commit is contained in:
@@ -315,8 +315,7 @@ impl<TX: Number, TY: Number, X: Array2<TX>, Y: Array1<TY>, D: Distance<Vec<TX>>>
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
while !neighbors.is_empty() {
|
while let Some(neighbor) = neighbors.pop() {
|
||||||
let neighbor = neighbors.pop().unwrap();
|
|
||||||
let index = neighbor.0;
|
let index = neighbor.0;
|
||||||
|
|
||||||
if y[index] == outlier {
|
if y[index] == outlier {
|
||||||
|
|||||||
@@ -40,7 +40,7 @@ pub fn load_dataset() -> Dataset<f32, u32> {
|
|||||||
target: y,
|
target: y,
|
||||||
num_samples,
|
num_samples,
|
||||||
num_features,
|
num_features,
|
||||||
feature_names: vec![
|
feature_names: [
|
||||||
"Age", "Sex", "BMI", "BP", "S1", "S2", "S3", "S4", "S5", "S6",
|
"Age", "Sex", "BMI", "BP", "S1", "S2", "S3", "S4", "S5", "S6",
|
||||||
]
|
]
|
||||||
.iter()
|
.iter()
|
||||||
|
|||||||
@@ -25,16 +25,14 @@ pub fn load_dataset() -> Dataset<f32, f32> {
|
|||||||
target: y,
|
target: y,
|
||||||
num_samples,
|
num_samples,
|
||||||
num_features,
|
num_features,
|
||||||
feature_names: vec![
|
feature_names: ["sepal length (cm)",
|
||||||
"sepal length (cm)",
|
|
||||||
"sepal width (cm)",
|
"sepal width (cm)",
|
||||||
"petal length (cm)",
|
"petal length (cm)",
|
||||||
"petal width (cm)",
|
"petal width (cm)"]
|
||||||
]
|
|
||||||
.iter()
|
.iter()
|
||||||
.map(|s| s.to_string())
|
.map(|s| s.to_string())
|
||||||
.collect(),
|
.collect(),
|
||||||
target_names: vec!["setosa", "versicolor", "virginica"]
|
target_names: ["setosa", "versicolor", "virginica"]
|
||||||
.iter()
|
.iter()
|
||||||
.map(|s| s.to_string())
|
.map(|s| s.to_string())
|
||||||
.collect(),
|
.collect(),
|
||||||
|
|||||||
+2
-2
@@ -36,7 +36,7 @@ pub fn load_dataset() -> Dataset<f32, u32> {
|
|||||||
target: y,
|
target: y,
|
||||||
num_samples,
|
num_samples,
|
||||||
num_features,
|
num_features,
|
||||||
feature_names: vec![
|
feature_names: [
|
||||||
"sepal length (cm)",
|
"sepal length (cm)",
|
||||||
"sepal width (cm)",
|
"sepal width (cm)",
|
||||||
"petal length (cm)",
|
"petal length (cm)",
|
||||||
@@ -45,7 +45,7 @@ pub fn load_dataset() -> Dataset<f32, u32> {
|
|||||||
.iter()
|
.iter()
|
||||||
.map(|s| s.to_string())
|
.map(|s| s.to_string())
|
||||||
.collect(),
|
.collect(),
|
||||||
target_names: vec!["setosa", "versicolor", "virginica"]
|
target_names: ["setosa", "versicolor", "virginica"]
|
||||||
.iter()
|
.iter()
|
||||||
.map(|s| s.to_string())
|
.map(|s| s.to_string())
|
||||||
.collect(),
|
.collect(),
|
||||||
|
|||||||
@@ -188,8 +188,7 @@ pub trait ArrayView1<T: Debug + Display + Copy + Sized>: Array<T, usize> {
|
|||||||
_ => max,
|
_ => max,
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
self.iterator(0)
|
self.iterator(0).fold(T::min_value(), max_f)
|
||||||
.fold(T::min_value(), |max, x| max_f(max, x))
|
|
||||||
}
|
}
|
||||||
/// return min value from the view
|
/// return min value from the view
|
||||||
fn min(&self) -> T
|
fn min(&self) -> T
|
||||||
@@ -202,8 +201,7 @@ pub trait ArrayView1<T: Debug + Display + Copy + Sized>: Array<T, usize> {
|
|||||||
_ => min,
|
_ => min,
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
self.iterator(0)
|
self.iterator(0).fold(T::max_value(), min_f)
|
||||||
.fold(T::max_value(), |max, x| min_f(max, x))
|
|
||||||
}
|
}
|
||||||
/// return the position of the max value of the view
|
/// return the position of the max value of the view
|
||||||
fn argmax(&self) -> usize
|
fn argmax(&self) -> usize
|
||||||
|
|||||||
@@ -650,7 +650,7 @@ mod tests {
|
|||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_from_iterator() {
|
fn test_from_iterator() {
|
||||||
let data = vec![1, 2, 3, 4, 5, 6];
|
let data = [1, 2, 3, 4, 5, 6];
|
||||||
|
|
||||||
let m = DenseMatrix::from_iterator(data.iter(), 2, 3, 0);
|
let m = DenseMatrix::from_iterator(data.iter(), 2, 3, 0);
|
||||||
|
|
||||||
|
|||||||
@@ -211,7 +211,7 @@ mod tests {
|
|||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_len() {
|
fn test_len() {
|
||||||
let x = vec![1, 2, 3];
|
let x = [1, 2, 3];
|
||||||
assert_eq!(3, x.len());
|
assert_eq!(3, x.len());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -160,7 +160,7 @@ mod tests {
|
|||||||
fn bg_solver() {
|
fn bg_solver() {
|
||||||
let a = DenseMatrix::from_2d_array(&[&[25., 15., -5.], &[15., 18., 0.], &[-5., 0., 11.]]);
|
let a = DenseMatrix::from_2d_array(&[&[25., 15., -5.], &[15., 18., 0.], &[-5., 0., 11.]]);
|
||||||
let b = vec![40., 51., 28.];
|
let b = vec![40., 51., 28.];
|
||||||
let expected = vec![1.0, 2.0, 3.0];
|
let expected = [1.0, 2.0, 3.0];
|
||||||
|
|
||||||
let mut x = Vec::zeros(3);
|
let mut x = Vec::zeros(3);
|
||||||
|
|
||||||
|
|||||||
@@ -890,11 +890,7 @@ mod tests {
|
|||||||
|
|
||||||
let y_hat = lr.predict(&x).unwrap();
|
let y_hat = lr.predict(&x).unwrap();
|
||||||
|
|
||||||
let error: i32 = y
|
let error: i32 = y.into_iter().zip(y_hat).map(|(a, b)| (a - b).abs()).sum();
|
||||||
.into_iter()
|
|
||||||
.zip(y_hat.into_iter())
|
|
||||||
.map(|(a, b)| (a - b).abs())
|
|
||||||
.sum();
|
|
||||||
|
|
||||||
assert!(error <= 1);
|
assert!(error <= 1);
|
||||||
|
|
||||||
|
|||||||
@@ -297,7 +297,7 @@ mod tests {
|
|||||||
let x =
|
let x =
|
||||||
DenseMatrix::from_2d_array(&[&[1., 2.], &[3., 4.], &[5., 6.], &[7., 8.], &[9., 10.]]);
|
DenseMatrix::from_2d_array(&[&[1., 2.], &[3., 4.], &[5., 6.], &[7., 8.], &[9., 10.]]);
|
||||||
let y: Vec<f64> = vec![1., 2., 3., 4., 5.];
|
let y: Vec<f64> = vec![1., 2., 3., 4., 5.];
|
||||||
let y_exp = vec![1., 2., 3., 4., 5.];
|
let y_exp = [1., 2., 3., 4., 5.];
|
||||||
let knn = KNNRegressor::fit(
|
let knn = KNNRegressor::fit(
|
||||||
&x,
|
&x,
|
||||||
&y,
|
&y,
|
||||||
@@ -324,7 +324,7 @@ mod tests {
|
|||||||
let x =
|
let x =
|
||||||
DenseMatrix::from_2d_array(&[&[1., 2.], &[3., 4.], &[5., 6.], &[7., 8.], &[9., 10.]]);
|
DenseMatrix::from_2d_array(&[&[1., 2.], &[3., 4.], &[5., 6.], &[7., 8.], &[9., 10.]]);
|
||||||
let y: Vec<f64> = vec![1., 2., 3., 4., 5.];
|
let y: Vec<f64> = vec![1., 2., 3., 4., 5.];
|
||||||
let y_exp = vec![2., 2., 3., 4., 4.];
|
let y_exp = [2., 2., 3., 4., 4.];
|
||||||
let knn = KNNRegressor::fit(&x, &y, Default::default()).unwrap();
|
let knn = KNNRegressor::fit(&x, &y, Default::default()).unwrap();
|
||||||
let y_hat = knn.predict(&x).unwrap();
|
let y_hat = knn.predict(&x).unwrap();
|
||||||
assert_eq!(5, Vec::len(&y_hat));
|
assert_eq!(5, Vec::len(&y_hat));
|
||||||
|
|||||||
@@ -277,7 +277,7 @@ mod tests {
|
|||||||
)]
|
)]
|
||||||
#[test]
|
#[test]
|
||||||
fn hash_encode_f64_series() {
|
fn hash_encode_f64_series() {
|
||||||
let series = vec![3.0, 1.0, 2.0, 1.0];
|
let series = [3.0, 1.0, 2.0, 1.0];
|
||||||
let hashable_series: Vec<CategoricalFloat> =
|
let hashable_series: Vec<CategoricalFloat> =
|
||||||
series.iter().map(|v| v.to_category()).collect();
|
series.iter().map(|v| v.to_category()).collect();
|
||||||
let enc = CategoryMapper::from_positional_category_vec(hashable_series);
|
let enc = CategoryMapper::from_positional_category_vec(hashable_series);
|
||||||
|
|||||||
+1
-1
@@ -56,7 +56,7 @@ pub struct Kernels;
|
|||||||
impl Kernels {
|
impl Kernels {
|
||||||
/// Return a default linear
|
/// Return a default linear
|
||||||
pub fn linear() -> LinearKernel {
|
pub fn linear() -> LinearKernel {
|
||||||
LinearKernel::default()
|
LinearKernel
|
||||||
}
|
}
|
||||||
/// Return a default RBF
|
/// Return a default RBF
|
||||||
pub fn rbf() -> RBFKernel {
|
pub fn rbf() -> RBFKernel {
|
||||||
|
|||||||
@@ -767,7 +767,7 @@ mod tests {
|
|||||||
assert!((y_hat[i] - y[i]).abs() < 0.1);
|
assert!((y_hat[i] - y[i]).abs() < 0.1);
|
||||||
}
|
}
|
||||||
|
|
||||||
let expected_y = vec![
|
let expected_y = [
|
||||||
87.3, 87.3, 87.3, 87.3, 98.9, 98.9, 98.9, 98.9, 98.9, 107.9, 107.9, 107.9, 114.85,
|
87.3, 87.3, 87.3, 87.3, 98.9, 98.9, 98.9, 98.9, 98.9, 107.9, 107.9, 107.9, 114.85,
|
||||||
114.85, 114.85, 114.85,
|
114.85, 114.85, 114.85,
|
||||||
];
|
];
|
||||||
@@ -788,7 +788,7 @@ mod tests {
|
|||||||
assert!((y_hat[i] - expected_y[i]).abs() < 0.1);
|
assert!((y_hat[i] - expected_y[i]).abs() < 0.1);
|
||||||
}
|
}
|
||||||
|
|
||||||
let expected_y = vec![
|
let expected_y = [
|
||||||
83.0, 88.35, 88.35, 89.5, 97.15, 97.15, 99.5, 99.5, 101.2, 104.6, 109.6, 109.6, 113.4,
|
83.0, 88.35, 88.35, 89.5, 97.15, 97.15, 99.5, 99.5, 101.2, 104.6, 109.6, 109.6, 113.4,
|
||||||
113.4, 116.30, 116.30,
|
113.4, 116.30, 116.30,
|
||||||
];
|
];
|
||||||
|
|||||||
Reference in New Issue
Block a user