feat: adds dataset module, fixs problem in CoverTree implementation

This commit is contained in:
Volodymyr Orlov
2020-09-10 12:21:59 -07:00
parent cc1f84e81f
commit b95e11cc98
9 changed files with 598 additions and 394 deletions
+3 -1
View File
@@ -143,6 +143,7 @@ impl<T: RealNumber, D: Distance<Vec<T>, T>> KNNRegressor<T, D> {
fn predict_for_row(&self, x: Vec<T>) -> T {
let search_result = self.knn_algorithm.find(&x, self.k);
println!("{:?}", search_result);
let mut result = T::zero();
let weights = self
@@ -195,9 +196,10 @@ mod tests {
let y_exp = vec![2., 2., 3., 4., 4.];
let knn = KNNRegressor::fit(&x, &y, Distances::euclidian(), Default::default());
let y_hat = knn.predict(&x);
println!("{:?}", y_hat);
assert_eq!(5, Vec::len(&y_hat));
for i in 0..y_hat.len() {
assert!((y_hat[i] - y_exp[i]).abs() < std::f64::EPSILON);
assert!((y_hat[i] - y_exp[i]).abs() < 1e-7);
}
}