lrclassifier 0.1.0

A simple logistic regression classifier implementation
Documentation
  • Coverage
  • 100%
    10 out of 10 items documented1 out of 7 items with examples
  • Size
  • Source code size: 9.24 kB This is the summed size of all the files inside the crates.io package for this release.
  • Documentation size: 1.46 MB This is the summed size of all files generated by rustdoc for all configured targets
  • Links
  • ibnz36/lrclassifier
    2 0 0
  • crates.io
  • Dependencies
  • Versions
  • Owners
  • Brian3647

lrclassifier: Logistic Regression Classifiers in rust

lrclassifier is a Rust library that provides an implementation of the Logistic Regression Classifier, a popular machine learning algorithm for binary classification problems.

Features

  • Efficient implementation of Logistic Regression algorithm.
  • Supports L2 regularization.
  • Customizable learning rate and regularization parameter.
  • Easy-to-use API for training models and making predictions.

Quick start

This is the code for a sample positive-negative number classification.

# Cargo.toml

[dependencies]
lrclassifier = "*"
// main.rs
use lrclassifier::LRClassifier;

fn main() {
    // Data: positive and negative numbers
    let inputs: Vec<Vec<f64>> = vec![
        vec![-3.0],
        vec![-2.0],
        vec![-1.0],
        vec![1.0],
        vec![2.0],
        vec![3.0],
    ];

    let expected: Vec<f64> = vec![0.0, 0.0, 0.0, 1.0, 1.0, 1.0]; // 0 for negative, 1 for positive

    let learning_rate = 0.1;
    let lambda = 0.1;
    let input_size = inputs[0].len();

    // Create a classifier
    let mut classifier = LRClassifier::new(input_size, learning_rate, lambda);

    // Train the classifier
    classifier.train(&inputs, &expected, 10000);

    // Test the classifier
    for (input, output) in inputs.iter().zip(expected) {
        let prediction = dbg!(classifier.predict(input));
        let binary_prediction = if prediction >= 0.5 { 1.0 } else { 0.0 };
        assert_eq!(binary_prediction, output);
    }
}

License

This project is licensed under the MIT license that can be found here