Skip to main content

Module label_binarizer

Module label_binarizer 

Source
Expand description

One-vs-rest label binarizer.

Transforms a vector of integer class labels into a binary indicator matrix. For K classes the output has K columns (one-hot rows), except in the binary case (K = 2) where a single column is produced.

§Examples

use ferrolearn_preprocess::label_binarizer::LabelBinarizer;
use ferrolearn_core::traits::{Fit, Transform};
use ndarray::array;

let lb = LabelBinarizer::new();
let y = array![0_usize, 1, 2, 1];
let fitted = lb.fit(&y, &()).unwrap();
let mat = fitted.transform(&y).unwrap();
// 3 classes → (4, 3) indicator matrix
assert_eq!(mat.shape(), &[4, 3]);
assert_eq!(mat[[0, 0]], 1.0);
assert_eq!(mat[[0, 1]], 0.0);

Structs§

FittedLabelBinarizer
A fitted label binarizer holding the discovered class set.
LabelBinarizer
An unfitted one-vs-rest label binarizer.