SelfTrainingClassifier<T>

Models & Types · AiDotNet.Classification.SemiSupervised

A self-training classifier that iteratively labels high-confidence unlabeled samples.

Inheritance: ClassifierBase<T> → SemiSupervisedClassifierBase<T> → SelfTrainingClassifier<T>

Implements: IGeneratedParameterRegistrar<T>, IGradientComputable<T, Matrix<T>, Vector<T>>

For Beginners

Self-training is like a student who:

  1. Studies the examples with answers (labeled data)
  2. Makes predictions on practice problems (unlabeled data)
  3. Is most confident about some answers
  4. Treats those confident answers as correct and studies them too
  5. Repeats until no more confident predictions can be made

The key insight is that the classifier’s most confident predictions are likely correct, so we can use them to expand our training set. Over time, the classifier becomes more accurate as it learns from its own confident predictions.

Algorithm steps:

  1. Train base classifier on labeled data
  2. Predict probabilities for all unlabeled samples
  3. Find predictions with confidence above threshold
  4. Add those samples (with predicted labels) to the training set
  5. Repeat until no new samples are added or max iterations reached

References:

  • Yarowsky, D. (1995). “Unsupervised word sense disambiguation rivaling supervised methods”
  • Triguero et al. (2015). “Self-labeled techniques for semi-supervised learning”

How It Works

Self-training is one of the oldest and simplest semi-supervised learning algorithms. It works by iteratively training a classifier on labeled data, using it to predict labels for unlabeled data, and adding high-confidence predictions to the training set.

Example

var features = new Matrix<double>(new double[,] { { 1.0, 2.0 }, { 3.0, 4.0 }, { 5.0, 6.0 }, { 7.0, 8.0 } });
var labels = new Vector<double>(new double[] { 0.0, 1.0, 0.0, 1.0 });
var newSample = new Matrix<double>(new double[,] { { 1.0, 2.0 }, { 3.0, 4.0 }, { 5.0, 6.0 }, { 7.0, 8.0 } });
// Use AiModelBuilder facade for selftrainingclassifier classification
var builder = new AiModelBuilder<double, Matrix<double>, Vector<double>>()
    .ConfigureModel(new SelfTrainingClassifier<double>(new GaussianNaiveBayes<double>()));
            
var result = builder.Build(features, labels);
var prediction = result.Predict(newSample);

Constructors

Constructor Summary
SelfTrainingClassifier() Initializes a new instance with default settings using Gaussian Naive Bayes as the base classifier.
SelfTrainingClassifier(IClassifier<T> baseClassifier, double confidenceThreshold, int maxIterations, int maxSamplesPerIteration, SelectionCriterion<T> selectionCriterion, ClassifierOptions<T> options, IRegularization<T, Matrix<T>, Vector<T>> regularization) Initializes a new instance of the SelfTrainingClassifier class.

Properties

Property Summary
int IterationsPerformed { get; set; } Gets the number of iterations performed during training.
int SamplesAdded { get; set; } Gets the number of samples added from unlabeled data during training.

Methods

Method Summary
IFullModel<T, Matrix<T>, Vector<T>> WithParameters(Vector<T> parameters) Creates a new instance of the model with specified parameters.
Vector<T> ComputeGradients(Matrix<T> input, Vector<T> target, ILossFunction<T> lossFunction) Computes gradients for the model parameters.
Vector<T> Predict(Matrix<T> input) Predicts class labels for the given input data.
void ApplyGradients(Vector<T> gradients, T learningRate) Applies gradients to update the model parameters.