[][src]Crate oner_induction

The 1R (Holt, 1993) rule learning algorithm.

1R is a baseline rule learning algorithm

The algorithm generates a rule for each attribute in a dataset, and then picks the "one rule" that has the best accuracy.

Each rule (hypothesis) is a set of cases: for every value of the attribute, the prediction (the then part) is the most frequent class for examples with that attribute value.

This is a baseline learner for use in comparison against more sophisticated algorithms. A related idea is "0R" (zero rule), which is the most frequent class in the dataset.

Examples

This crate uses ndarray to represent attributes and classes.

use ndarray::prelude::*;
use oner_induction::{Rule, Case, Accuracy, discover};

let examples = array![
   ["sunny", "summer"],
   ["sunny", "summer"],
   ["cloudy", "winter"],
   ["sunny", "winter"]
];

let classes = array![
    "hot",
    "hot",
    "cold",
    "cold"
];

// Discover the best rule, and the column it applies to:
let rule: Option<(usize, Rule<&str, &str>)> =
  discover(&examples.view(), &classes.view());

// Expected accuracy is 100%
let accuracy = Accuracy(1.0);

// The "rule" is a set of cases (conditions, or "IF...THENs"):
let cases = vec![
    Case { attribute_value: "summer", predicted_class: "hot" },
    Case { attribute_value: "winter", predicted_class: "cold" }
];

// Column 1 is the Season (winter or summer)
assert_eq!(rule, Some( (1, Rule { cases, accuracy }) ));

References

Terminology

I'm following the terminology from Holte (1993):

  • Attribute (a.k.a. feature)
  • Value (the value of an attribute or class)
  • Class (classification, prediction)
  • Example (instance)

In generic parameters, A is for attribute and C is for class.

Limitations

This crate assumes numeric data has already been converted to categorical data.

See https://docs.rs/oner_quantize for an implementation of the 1R qualitzation algorithm.

Structs

Accuracy

Fraction of correct predictions out of all rows in the training data.

Case

A prediction based on an attribute value.

Rule

The rule for an attribute, together with the training data accuracy.

Functions

discover

Find the one rule that fits a set of example data points.

evaluate

Evaluate cases (a.k.a., a rule) against a data set, to get a performance accuracy.

interpret

Apply a set of cases to an attribute value to get a prediction.