Supervised and paired reductions#

LDA, Fisher Score and neighborhood components analysis use class labels. PLS, SIR and SAVE use response variables. CCA uses two aligned views [Cook, 2000, Duda et al., 2001, Fisher, 1936, Goldberger et al., 2004, Hotelling, 1936, Li, 1991, Wold et al., 1984].

import numpy as np

from believe14.linear import (
    CanonicalCorrelationAnalysis,
    FisherScore,
    LinearDiscriminantAnalysis,
    NeighborhoodComponentsAnalysis,
    PLSRegression,
    SlicedAverageVarianceEstimation,
    SlicedInverseRegression,
)

rng = np.random.default_rng(14)
labels = np.repeat(np.arange(3), 40)
centers = np.array(
    [[-1.5, 0.0, 0.0, 0.0, 0.0], [1.5, 0.0, 0.0, 0.0, 0.0], [0.0, 1.5, 0.0, 0.0, 0.0]]
)
X = centers[labels] + 0.55 * rng.normal(size=(120, 5))
target = 1.8 * X[:, 0] - 0.7 * X[:, 1] + 0.15 * rng.normal(size=120)
Y = np.column_stack(
    (
        X[:, 0] + 0.2 * rng.normal(size=120),
        X[:, 1] - 0.2 * rng.normal(size=120),
        rng.normal(size=120),
    )
)

models = [
    LinearDiscriminantAnalysis(2, regularization=1e-8).fit(X, labels),
    CanonicalCorrelationAnalysis(2).fit(X, Y),
    PLSRegression(2).fit(X, target),
    SlicedInverseRegression(2, n_slices=6).fit(X, target),
    SlicedAverageVarianceEstimation(2, n_slices=6).fit(X, target),
    FisherScore(2).fit(X, labels),
    NeighborhoodComponentsAnalysis(2, max_iter=200).fit(X, labels),
]

for model in models:
    assert model.diagnostics_.converged
    print(type(model).__name__, model.diagnostics_.solver)
LinearDiscriminantAnalysis range_space_generalized_eigh
CanonicalCorrelationAnalysis hotelling_support_svd
PLSRegression nipals_pls2
SlicedInverseRegression standardized_sir_eigh
SlicedAverageVarianceEstimation standardized_save_eigh
FisherScore fisher_between_within_ratio
NeighborhoodComponentsAnalysis nca_lbfgs

CCA validates row alignment and can transform one view or both views. PLS provides predict under its frozen NIPALS PLS2 convention. Fisher Score is a feature selector: get_support() identifies original columns and transform returns those columns without rotating them. The remaining estimators return supervised subspace coordinates for new feature rows. Neighborhood components analysis learns a distance for comparing observations. Its training criterion averages the probability of choosing a same-class neighbor.

See the cards for LDA, CCA, PLS2, SIR, SAVE, Fisher Score, and neighborhood components analysis.