Skip to content

Commit 5f59588

Browse files
Merge pull request #13 from morenol/lmm/knn
Allow KNN with k=1
2 parents a2588f6 + 92dad01 commit 5f59588

File tree

2 files changed

+5
-2
lines changed

2 files changed

+5
-2
lines changed

src/algorithm/sort/heap_select.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,9 @@ impl<'a, T: PartialOrd + Debug> HeapSelection<T> {
4141

4242
pub fn heapify(&mut self) {
4343
let n = self.heap.len();
44+
if n <= 1 {
45+
return;
46+
}
4447
for i in (0..=(n / 2 - 1)).rev() {
4548
self.sift_down(i, n - 1);
4649
}

src/neighbors/knn_regressor.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -116,9 +116,9 @@ impl<T: RealNumber, D: Distance<Vec<T>, T>> KNNRegressor<T, D> {
116116
)));
117117
}
118118

119-
if parameters.k <= 1 {
119+
if parameters.k < 1 {
120120
return Err(Failed::fit(&format!(
121-
"k should be > 1, k=[{}]",
121+
"k should be > 0, k=[{}]",
122122
parameters.k
123123
)));
124124
}

0 commit comments

Comments
 (0)