diff --git a/src/algorithm/sort/heap_select.rs b/src/algorithm/sort/heap_select.rs index 063ffc6..ae3ff18 100644 --- a/src/algorithm/sort/heap_select.rs +++ b/src/algorithm/sort/heap_select.rs @@ -41,6 +41,9 @@ impl<'a, T: PartialOrd + Debug> HeapSelection { pub fn heapify(&mut self) { let n = self.heap.len(); + if n <= 1 { + return; + } for i in (0..=(n / 2 - 1)).rev() { self.sift_down(i, n - 1); } diff --git a/src/neighbors/knn_regressor.rs b/src/neighbors/knn_regressor.rs index 04fbd35..0bf283f 100644 --- a/src/neighbors/knn_regressor.rs +++ b/src/neighbors/knn_regressor.rs @@ -116,9 +116,9 @@ impl, T>> KNNRegressor { ))); } - if parameters.k <= 1 { + if parameters.k < 1 { return Err(Failed::fit(&format!( - "k should be > 1, k=[{}]", + "k should be > 0, k=[{}]", parameters.k ))); }