Update machine learning documentation for clarity and completeness

This commit is contained in:
Palash Tyagi 2025-08-04 00:04:36 +01:00
parent 039fb1a98e
commit 3d11226d57

View File

@ -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 endtoend walkthroughs see the examples directory in the
repository.
Currently implemented models include:
- Linear and logistic regression
- K-means clustering
- Kmeans 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.