pub struct LabelModel { /* private fields */ }Expand description
Label Model for combining weak supervision sources.
Learns the accuracy and coverage of labeling functions to produce optimal probabilistic labels.
§Example
ⓘ
use aprender::weak_supervision::{LabelModel, LFOutput};
// Matrix of LF outputs: [n_samples x n_labeling_functions]
let lf_matrix = vec![
vec![LFOutput::Label(1), LFOutput::Abstain, LFOutput::Label(1)],
vec![LFOutput::Label(0), LFOutput::Label(0), LFOutput::Abstain],
// ...
];
let mut model = LabelModel::new(2, 3); // 2 classes, 3 LFs
model.fit(&lf_matrix, 100, 0.01);
let probs = model.predict_proba(&lf_matrix);Implementations§
Source§impl LabelModel
impl LabelModel
Sourcepub fn new(n_classes: usize, n_lfs: usize) -> Self
pub fn new(n_classes: usize, n_lfs: usize) -> Self
Create a new label model.
§Arguments
n_classes- Number of output classesn_lfs- Number of labeling functions
Sourcepub fn fit(&mut self, lf_matrix: &[Vec<LFOutput>], n_epochs: usize, lr: f32)
pub fn fit(&mut self, lf_matrix: &[Vec<LFOutput>], n_epochs: usize, lr: f32)
Fit the label model using EM algorithm.
§Arguments
lf_matrix- Matrix of LF outputs [n_samples x n_lfs]n_epochs- Number of EM iterationslr- Learning rate for parameter updates
Sourcepub fn predict_proba(&self, lf_matrix: &[Vec<LFOutput>]) -> Vec<Vector<f32>>
pub fn predict_proba(&self, lf_matrix: &[Vec<LFOutput>]) -> Vec<Vector<f32>>
Get probabilistic labels for samples.
Sourcepub fn predict(&self, lf_matrix: &[Vec<LFOutput>]) -> Vec<usize>
pub fn predict(&self, lf_matrix: &[Vec<LFOutput>]) -> Vec<usize>
Get hard label predictions (argmax of probabilities).
Sourcepub fn get_accuracies(&self) -> &[Vec<f32>]
pub fn get_accuracies(&self) -> &[Vec<f32>]
Get estimated LF accuracies.
Sourcepub fn get_class_priors(&self) -> &[f32]
pub fn get_class_priors(&self) -> &[f32]
Get estimated class priors.
Trait Implementations§
Source§impl Clone for LabelModel
impl Clone for LabelModel
Source§fn clone(&self) -> LabelModel
fn clone(&self) -> LabelModel
Returns a duplicate of the value. Read more
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source. Read moreAuto Trait Implementations§
impl Freeze for LabelModel
impl RefUnwindSafe for LabelModel
impl Send for LabelModel
impl Sync for LabelModel
impl Unpin for LabelModel
impl UnwindSafe for LabelModel
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
Converts
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
Converts
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more