2 releases
0.1.1 | Feb 18, 2020 |
---|---|
0.1.0 | Feb 18, 2020 |
#569 in Machine learning
8KB
62 lines
Super fast online learning using perceptron. It allows you to train your model as you go, and use an ensemble to make accurate predictions.
Background
Preceptron is a relatively simple and fast machine learning algorithm. It has
- no hyper parameters (no need to tune),
- good generalization properties using ensemble and
- overall good classification accuracy.
Usage
use perceptron::*;
fn and_works() {
let examples = vec!((vec!(-1.0, 1.0), false), (vec!(-1.0, -1.0), false), (vec!(1.0, -1.0), false), (vec!(1.0, 1.0), true));
let perceptron = (1..100).fold(Perceptron::new(2),
|pepoch, _epoch| examples.iter().fold(pepoch,
|pexample, example| pexample.train(example.0.clone(), example.1).unwrap()));
println!("{:?}", perceptron);
assert_eq!(perceptron.predict(examples[0].0.clone()), examples[0].1);
assert_eq!(perceptron.predict(examples[1].0.clone()), examples[1].1);
assert_eq!(perceptron.predict(examples[2].0.clone()), examples[2].1);
assert_eq!(perceptron.predict(examples[3].0.clone()), examples[3].1);
}
Dependencies
~0.7–1.6MB
~34K SLoC