LabelPropagation<T>

Models & Types · AiDotNet.Classification.SemiSupervised

Implements the Label Propagation algorithm for semi-supervised classification.

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

Implements: IGeneratedParameterRegistrar<T>

For Beginners

Imagine you have a few people in a social network whose political views you know (labeled), and many others whose views you don’t know (unlabeled). Label Propagation assumes that connected people (friends) tend to have similar views.

The algorithm builds a graph where people are connected based on similarity, then lets the known labels “spread” through the connections. After many rounds of spreading, even people far from the labeled ones get assigned labels based on how the information flowed through the network.

The key insight is that similar data points should have similar labels, and this similarity can be captured through a graph structure.

How It Works

Label Propagation is a graph-based semi-supervised learning algorithm that propagates labels from labeled samples to unlabeled samples through a similarity graph.

Example

// Create label propagation for semi-supervised learning
            
// Prepare data: some labeled (-1 means unlabeled), some not
var features = new Matrix<double>(6, 2);
features[0, 0] = 1.0; features[0, 1] = 1.1;
features[1, 0] = 1.2; features[1, 1] = 0.9;
features[2, 0] = 0.8; features[2, 1] = 1.0;
features[3, 0] = 5.0; features[3, 1] = 5.1;
features[4, 0] = 5.2; features[4, 1] = 4.9;
features[5, 0] = 4.8; features[5, 1] = 5.0;
var labels = new Vector<double>(new double[] { 0, -1, -1, 1, -1, -1 });
            
// Propagate labels through similarity graph to unlabeled samples
var result = new AiModelBuilder<double, Matrix<double>, Vector<double>>()
    .ConfigureModel(new LabelPropagation<double>())
    .Build(features, labels);
            
// Predict labels for all samples including previously unlabeled
var prediction = result.Predict(features);
// Result is available in the returned value

Constructors

Constructor Summary
LabelPropagation() Initializes a new instance of the LabelPropagation class with default settings.
LabelPropagation(IKernelFunction<T> kernel, int maxIterations, T tolerance, int? seed) Initializes a new instance of the LabelPropagation class with specified parameters.

Methods

Method Summary
IFullModel<T, Matrix<T>, Vector<T>> WithParameters(Vector<T> parameters) Creates a new instance of the model with the specified parameters.
Matrix<T> PredictProbabilities(Matrix<T> input) Predicts class probabilities for each sample.
Vector<T> Predict(Matrix<T> input) Predicts class labels for new samples.