load_digits

Function load_digits 

Source
pub fn load_digits() -> Result<Dataset>
Expand description

Generate the digits dataset

Examples found in repository?
examples/scikit_learn_benchmark.rs (line 313)
265fn run_sklearn_toy_dataset_comparison() {
266    println!("\n  📊 Toy Dataset Loading Comparison:");
267
268    let datasets = vec![
269        (
270            "iris",
271            "from sklearn.datasets import load_iris; load_iris()",
272        ),
273        (
274            "boston",
275            "from sklearn.datasets import load_boston; load_boston()",
276        ),
277        (
278            "digits",
279            "from sklearn.datasets import load_digits; load_digits()",
280        ),
281        (
282            "wine",
283            "from sklearn.datasets import load_wine; load_wine()",
284        ),
285        (
286            "breast_cancer",
287            "from sklearn.datasets import load_breast_cancer; load_breast_cancer()",
288        ),
289    ];
290
291    for (name, python_code) in datasets {
292        // Time Python execution
293        let _start = Instant::now();
294        let python_result = Command::new("python3")
295            .arg("-c")
296            .arg(format!(
297                "import time; start=time.time(); {python_code}; print(f'{{:.4f}}', time.time()-start)"
298            ))
299            .output();
300
301        match python_result {
302            Ok(output) if output.status.success() => {
303                let python_time = String::from_utf8_lossy(&output.stdout)
304                    .trim()
305                    .parse::<f64>()
306                    .unwrap_or(0.0);
307
308                // Time SciRS2 execution
309                let scirs2_start = Instant::now();
310                let _scirs2_result = match name {
311                    "iris" => load_iris().map(|_| ()),
312                    "boston" => load_boston().map(|_| ()),
313                    "digits" => load_digits().map(|_| ()),
314                    "wine" => load_wine(false).map(|_| ()),
315                    "breast_cancer" => load_breast_cancer().map(|_| ()),
316                    _ => Ok(()),
317                };
318                let scirs2_time = scirs2_start.elapsed().as_secs_f64();
319
320                let speedup = python_time / scirs2_time;
321                let status = if speedup > 1.2 {
322                    "🚀 FASTER"
323                } else if speedup > 0.8 {
324                    "≈ SIMILAR"
325                } else {
326                    "🐌 SLOWER"
327                };
328
329                println!(
330                    "    {}: SciRS2 {:.2}ms vs sklearn {:.2}ms ({:.1}x {}",
331                    name,
332                    scirs2_time * 1000.0,
333                    python_time * 1000.0,
334                    speedup,
335                    status
336                );
337            }
338            _ => {
339                println!("    {name}: Failed to benchmark Python version");
340            }
341        }
342    }
343}