Skip to main content

Module classification

Module classification 

Source
Expand description

Classification algorithms.

This module implements classification algorithms including:

  • Logistic Regression for binary classification
  • K-Nearest Neighbors (kNN) for instance-based classification
  • Gaussian Naive Bayes for probabilistic classification
  • Linear Support Vector Machine (SVM) for maximum-margin classification
  • Softmax Regression for multi-class classification (planned)

§Example

use aprender::classification::LogisticRegression;
use aprender::prelude::*;

// Binary classification data
let x = Matrix::from_vec(4, 2, vec![
    0.0, 0.0,
    0.0, 1.0,
    1.0, 0.0,
    1.0, 1.0,
]).expect("Matrix dimensions match data length");
let y = vec![0, 0, 0, 1];

let mut model = LogisticRegression::new()
    .with_learning_rate(0.1)
    .with_max_iter(1000);
model.fit(&x, &y).expect("Training data is valid with 4 samples");
let predictions = model.predict(&x);

assert_eq!(predictions.len(), 4);
for pred in predictions {
    assert!(pred == 0 || pred == 1);
}

Structs§

GaussianNB
Gaussian Naive Bayes classifier.
KNearestNeighbors
K-Nearest Neighbors classifier.
LinearSVM
Linear Support Vector Machine (SVM) classifier.
LogisticRegression
Logistic Regression classifier for binary classification.

Enums§

DistanceMetric
Distance metric for K-Nearest Neighbors.