NCA<T>

Models & Types ยท AiDotNet.Preprocessing.DimensionalityReduction

Neighborhood Components Analysis (NCA) for supervised dimensionality reduction.

Inheritance: TransformerBase<T, Matrix<T>, Matrix<T>> โ†’ NCA<T>

For Beginners

NCA learns a space where k-NN works well:

  • Points with same label are pulled closer together
  • Points with different labels are pushed apart
  • The learned transformation is linear (a matrix)
  • Can be used for feature extraction before classification

Use cases:

  • Preprocessing for k-NN classifiers
  • Metric learning for distance-based methods
  • Visualization with class structure preserved
  • Feature extraction for classification tasks

How It Works

NCA is a supervised dimensionality reduction algorithm that learns a linear transformation to maximize the expected leave-one-out classification accuracy in the transformed space. It uses stochastic neighbor assignment for soft nearest-neighbor classification.

The algorithm:

  1. Define soft neighbor probabilities using softmax over distances
  2. Compute expected leave-one-out classification accuracy
  3. Optimize transformation matrix using gradient descent
  4. Project data using learned transformation

Constructors

Constructor Summary
NCA(int nComponents, int maxIter, double learningRate, double tol, int? randomState, int[] columnIndices) Creates a new instance of NCA.

Properties

Property Summary
Matrix<T> TransformationMatrix { get; } Gets the learned transformation matrix.
bool SupportsInverseTransform { get; } Gets whether this transformer supports inverse transformation.
int NComponents { get; } Gets the number of components (dimensions).

Methods

Method Summary
Matrix<T> FitTransformSupervised(Matrix<T> data, int[] labels) Fits NCA using the provided data and labels, then transforms the data.
string[] GetFeatureNamesOut(string[] inputFeatureNames) Gets the output feature names after transformation.