From 3d11226d57fcc540b75d087688806c731cdb2bfb Mon Sep 17 00:00:00 2001 From: Palash Tyagi <23239946+Magnus167@users.noreply.github.com> Date: Mon, 4 Aug 2025 00:04:36 +0100 Subject: [PATCH] Update machine learning documentation for clarity and completeness --- docs/src/machine-learning.md | 43 +++++++++++++++++++++++++++++++++--- 1 file changed, 40 insertions(+), 3 deletions(-) diff --git a/docs/src/machine-learning.md b/docs/src/machine-learning.md index 1694da8..ccbec53 100644 --- a/docs/src/machine-learning.md +++ b/docs/src/machine-learning.md @@ -1,11 +1,17 @@ # Machine Learning -RustFrame ships with several algorithms: +The `compute::models` module bundles several learning algorithms that operate on +`Matrix` structures. These examples highlight the basic training and prediction +APIs. For more end‑to‑end walkthroughs see the examples directory in the +repository. + +Currently implemented models include: - Linear and logistic regression -- K-means clustering +- K‑means clustering - Principal component analysis (PCA) -- Naive Bayes and dense neural networks +- Gaussian Naive Bayes +- Dense neural networks ## Linear Regression @@ -37,3 +43,34 @@ let cluster = model.predict(&new_point)[0]; For helper functions and upcoming modules, visit the [utilities](./utilities.md) section. + +## Logistic Regression + +```rust +# extern crate rustframe; +use rustframe::compute::models::logreg::LogReg; +use rustframe::matrix::Matrix; + +let x = Matrix::from_vec(vec![1.0, 2.0, 3.0, 4.0], 4, 1); +let y = Matrix::from_vec(vec![0.0, 0.0, 1.0, 1.0], 4, 1); +let mut model = LogReg::new(1); +model.fit(&x, &y, 0.1, 200); +let preds = model.predict_proba(&x); +assert_eq!(preds.rows(), 4); +``` + +## Principal Component Analysis + +```rust +# extern crate rustframe; +use rustframe::compute::models::pca::PCA; +use rustframe::matrix::Matrix; + +let data = Matrix::from_vec(vec![1.0, 2.0, 3.0, 4.0], 2, 2); +let pca = PCA::fit(&data, 1, 0); +let transformed = pca.transform(&data); +assert_eq!(transformed.cols(), 1); +``` + +For helper functions and upcoming modules, visit the +[utilities](./utilities.md) section.