Allow KNN with k=1
This commit is contained in:
@@ -41,6 +41,9 @@ impl<'a, T: PartialOrd + Debug> HeapSelection<T> {
|
|||||||
|
|
||||||
pub fn heapify(&mut self) {
|
pub fn heapify(&mut self) {
|
||||||
let n = self.heap.len();
|
let n = self.heap.len();
|
||||||
|
if n <= 1 {
|
||||||
|
return;
|
||||||
|
}
|
||||||
for i in (0..=(n / 2 - 1)).rev() {
|
for i in (0..=(n / 2 - 1)).rev() {
|
||||||
self.sift_down(i, n - 1);
|
self.sift_down(i, n - 1);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -116,9 +116,9 @@ impl<T: RealNumber, D: Distance<Vec<T>, T>> KNNRegressor<T, D> {
|
|||||||
)));
|
)));
|
||||||
}
|
}
|
||||||
|
|
||||||
if parameters.k <= 1 {
|
if parameters.k < 1 {
|
||||||
return Err(Failed::fit(&format!(
|
return Err(Failed::fit(&format!(
|
||||||
"k should be > 1, k=[{}]",
|
"k should be > 0, k=[{}]",
|
||||||
parameters.k
|
parameters.k
|
||||||
)));
|
)));
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user