MCPcopy Create free account
hub / github.com/daniel-e/rustml / classify

Function classify

src/knn.rs:61–72  ·  view source on GitHub ↗
(m: &Matrix<T>, labels: &Vec<L>, example: &[T], k: usize, df: D)

Source from the content-addressed store, hash-verified

59}
60
61pub fn classify<T, L, D>(m: &Matrix<T>, labels: &Vec<L>, example: &[T], k: usize, df: D) -> L
62 where T: Float, L: Clone + Ord, D: Fn(&[T], &[T]) -> T {
63
64 let idx = scan(&m, example, k, df).unwrap();
65
66 let mut targets: Vec<L> = idx.iter().map(|pos| labels.get(*pos).unwrap()).cloned().collect();
67 targets.sort_by(|a, b| a.cmp(&b));
68 let mut r = group(&targets);
69 r.sort_by(|a, b| a.1.cmp(&b.1));
70
71 r.last().unwrap().0.clone()
72}
73
74
75#[cfg(test)]

Callers 3

test_knn_classifyFunction · 0.85
mainFunction · 0.85

Calls 5

scanFunction · 0.85
groupFunction · 0.85
mapMethod · 0.80
getMethod · 0.80
iterMethod · 0.45

Tested by 1

test_knn_classifyFunction · 0.68