mirror of
https://github.com/Magnus167/rustframe.git
synced 2025-08-20 04:00:01 +00:00
add test as examples
This commit is contained in:
parent
45ec754d47
commit
b0d8050b11
@ -49,3 +49,17 @@ fn customer_spend_example() {
|
|||||||
let pred = model.predict(&new_customers);
|
let pred = model.predict(&new_customers);
|
||||||
println!("Cluster of new customers: {:?}", pred);
|
println!("Cluster of new customers: {:?}", pred);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn k_means_store_locations() {
|
||||||
|
let raw = vec![
|
||||||
|
1.0, 2.0, 1.5, 1.8, 5.0, 8.0, 8.0, 8.0, 1.0, 0.6, 9.0, 11.0, 8.0, 2.0, 10.0, 2.0, 9.0, 3.0,
|
||||||
|
];
|
||||||
|
let x = Matrix::from_rows_vec(raw, 9, 2);
|
||||||
|
let (model, labels) = KMeans::fit(&x, 2, 100, 1e-4);
|
||||||
|
assert_eq!(labels.len(), 9);
|
||||||
|
assert_eq!(model.centroids.rows(), 2);
|
||||||
|
let new_points = Matrix::from_rows_vec(vec![0.0, 0.0, 8.0, 3.0], 2, 2);
|
||||||
|
let pred = model.predict(&new_points);
|
||||||
|
assert_eq!(pred.len(), 2);
|
||||||
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user