From 263aef0d902fc82bed31bbee78cc93956657720c Mon Sep 17 00:00:00 2001 From: Moh Nouri Date: Sun, 26 Apr 2026 01:00:35 +0330 Subject: [PATCH] Update README.md 1. Fix error[E0615]: attempted to take value of method unwrap on type Result, Failed> 2. Add output --- README.md | 40 +++++++++++++++++++++++----------------- 1 file changed, 23 insertions(+), 17 deletions(-) diff --git a/README.md b/README.md index f370abdb..44ead133 100644 --- a/README.md +++ b/README.md @@ -63,23 +63,29 @@ Here is a minimal example fitting a KNN classifier from native Rust vectors usin use smartcore::linalg::basic::matrix::DenseMatrix; use smartcore::neighbors::knn_classifier::KNNClassifier; -// Turn vector slices into a matrix -let x = DenseMatrix::from_2d_array(&[ - &[1., 2.], - &[3., 4.], - &[5., 6.], - &[7., 8.], - &[9., 10.], -]).unwrap; - -// Class labels -let y = vec![2, 2, 2, 3, 3]; - -// Train classifier -let knn = KNNClassifier::fit(&x, &y, Default::default()).unwrap(); - -// Predict -let yhat = knn.predict(&x).unwrap(); +fn main() { + // Turn vector slices into a matrix + let x = DenseMatrix::from_2d_array(&[ + &[1., 2.], + &[3., 4.], + &[5., 6.], + &[7., 8.], + &[9., 10.], + ]).unwrap(); + + // Class labels + let y = vec![2, 2, 2, 3, 3]; + + // Train classifier + let knn = KNNClassifier::fit(&x, &y, Default::default()).unwrap(); + + // Predict + let yhat = knn.predict(&x).unwrap(); + + // Output + println!("Real Data: {:?}", y); + println!("Predicted Data: {:?}", yhat); +} ``` This example mirrors the “First Example” section of the crate docs and demonstrates smartcore’s ergonomic API surface.