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

Function main

examples/mnist_digits.rs:7–32  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

5use rustml::knn::classify;
6
7fn main() {
8 let k = 5;
9
10 println!("Reading training data ...");
11 let (training, training_labels) = MnistDigits::default_training_set().unwrap();
12 let tr = training.map(|&val| val as f32);
13
14 println!("Reading test data ...");
15 let (test, test_labels) = MnistDigits::default_test_set().unwrap();
16 let te = test.map(|&val| val as f32);
17
18 // classify the first five examples from the test set
19 println!("Classifying ...");
20 let r = te.row_iter().zip(test_labels.iter()).take(5)
21 .map(|(row, label)| {
22 let target = classify(
23 &tr, &training_labels, row, k, |x, y| Euclid::compute(x, y).unwrap()
24 );
25
26 (label, target)
27 });
28
29 for (x, y) in r {
30 println!("label = {}, prediction = {}", x, y);
31 }
32}
33
34

Callers

nothing calls this directly

Calls 4

classifyFunction · 0.85
mapMethod · 0.80
row_iterMethod · 0.80
iterMethod · 0.45

Tested by

no test coverage detected