DocumentationClassesNeighborhoodComponentsAnalysis

Class: NeighborhoodComponentsAnalysis

Neighborhood Components Analysis.

Neighborhood Component Analysis (NCA) is a machine learning algorithm for metric learning. It learns a linear transformation in a supervised fashion to improve the classification accuracy of a stochastic nearest neighbors rule in the transformed space.

Read more in the User Guide.

Python Reference

Constructors

new NeighborhoodComponentsAnalysis()

new NeighborhoodComponentsAnalysis(opts?): NeighborhoodComponentsAnalysis

Parameters

ParameterTypeDescription
opts?object-
opts.callback?anyIf not undefined, this function is called after every iteration of the optimizer, taking as arguments the current solution (flattened transformation matrix) and the number of iterations. This might be useful in case one wants to examine or store the transformation found after each iteration.
opts.init?ArrayLike[] | "auto" | "random" | "identity" | "pca" | "lda"Initialization of the linear transformation. Possible options are 'auto', 'pca', 'lda', 'identity', 'random', and a numpy array of shape (n_features_a, n_features_b).
opts.max_iter?numberMaximum number of iterations in the optimization.
opts.n_components?numberPreferred dimensionality of the projected space. If undefined it will be set to n_features.
opts.random_state?numberA pseudo random number generator object or a seed for it if int. If init='random', random_state is used to initialize the random transformation. If init='pca', random_state is passed as an argument to PCA when initializing the transformation. Pass an int for reproducible results across multiple function calls. See Glossary.
opts.tol?numberConvergence tolerance for the optimization.
opts.verbose?numberIf 0, no progress messages will be printed. If 1, progress messages will be printed to stdout. If > 1, progress messages will be printed and the disp parameter of scipy.optimize.minimize will be set to verbose \- 2.
opts.warm_start?booleanIf true and fit has been called before, the solution of the previous call to fit is used as the initial linear transformation (n_components and init will be ignored).

Returns NeighborhoodComponentsAnalysis

Defined in generated/neighbors/NeighborhoodComponentsAnalysis.ts:25

Properties

PropertyTypeDefault valueDefined in
_isDisposedbooleanfalsegenerated/neighbors/NeighborhoodComponentsAnalysis.ts:23
_isInitializedbooleanfalsegenerated/neighbors/NeighborhoodComponentsAnalysis.ts:22
_pyPythonBridgeundefinedgenerated/neighbors/NeighborhoodComponentsAnalysis.ts:21
idstringundefinedgenerated/neighbors/NeighborhoodComponentsAnalysis.ts:18
optsanyundefinedgenerated/neighbors/NeighborhoodComponentsAnalysis.ts:19

Accessors

components_

Get Signature

get components_(): Promise<ArrayLike[]>

The linear transformation learned during fitting.

Returns Promise<ArrayLike[]>

Defined in generated/neighbors/NeighborhoodComponentsAnalysis.ts:392


feature_names_in_

Get Signature

get feature_names_in_(): Promise<ArrayLike>

Names of features seen during fit. Defined only when X has feature names that are all strings.

Returns Promise<ArrayLike>

Defined in generated/neighbors/NeighborhoodComponentsAnalysis.ts:500


n_features_in_

Get Signature

get n_features_in_(): Promise<number>

Number of features seen during fit.

Returns Promise<number>

Defined in generated/neighbors/NeighborhoodComponentsAnalysis.ts:419


n_iter_

Get Signature

get n_iter_(): Promise<number>

Counts the number of iterations performed by the optimizer.

Returns Promise<number>

Defined in generated/neighbors/NeighborhoodComponentsAnalysis.ts:446


py

Get Signature

get py(): PythonBridge

Returns PythonBridge

Set Signature

set py(pythonBridge): void

Parameters

ParameterType
pythonBridgePythonBridge

Returns void

Defined in generated/neighbors/NeighborhoodComponentsAnalysis.ts:80


random_state_

Get Signature

get random_state_(): Promise<any>

Pseudo random number generator object used during initialization.

Returns Promise<any>

Defined in generated/neighbors/NeighborhoodComponentsAnalysis.ts:473

Methods

dispose()

dispose(): Promise<void>

Disposes of the underlying Python resources.

Once dispose() is called, the instance is no longer usable.

Returns Promise<void>

Defined in generated/neighbors/NeighborhoodComponentsAnalysis.ts:136


fit()

fit(opts): Promise<any>

Fit the model according to the given training data.

Parameters

ParameterTypeDescription
optsobject-
opts.X?ArrayLike[]The training samples.
opts.y?ArrayLikeThe corresponding training labels.

Returns Promise<any>

Defined in generated/neighbors/NeighborhoodComponentsAnalysis.ts:153


fit_transform()

fit_transform(opts): Promise<any[]>

Fit to data, then transform it.

Fits transformer to X and y with optional parameters fit_params and returns a transformed version of X.

Parameters

ParameterTypeDescription
optsobject-
opts.fit_params?anyAdditional fit parameters.
opts.X?ArrayLike[]Input samples.
opts.y?ArrayLikeTarget values (undefined for unsupervised transformations).

Returns Promise<any[]>

Defined in generated/neighbors/NeighborhoodComponentsAnalysis.ts:196


get_feature_names_out()

get_feature_names_out(opts): Promise<any>

Get output feature names for transformation.

The feature names out will prefixed by the lowercased class name. For example, if the transformer outputs 3 features, then the feature names out are: \["class_name0", "class_name1", "class_name2"\].

Parameters

ParameterTypeDescription
optsobject-
opts.input_features?anyOnly used to validate feature names with the names seen in fit.

Returns Promise<any>

Defined in generated/neighbors/NeighborhoodComponentsAnalysis.ts:244


get_metadata_routing()

get_metadata_routing(opts): Promise<any>

Get metadata routing of this object.

Please check User Guide on how the routing mechanism works.

Parameters

ParameterTypeDescription
optsobject-
opts.routing?anyA MetadataRequest encapsulating routing information.

Returns Promise<any>

Defined in generated/neighbors/NeighborhoodComponentsAnalysis.ts:282


init()

init(py): Promise<void>

Initializes the underlying Python resources.

This instance is not usable until the Promise returned by init() resolves.

Parameters

ParameterType
pyPythonBridge

Returns Promise<void>

Defined in generated/neighbors/NeighborhoodComponentsAnalysis.ts:93


set_output()

set_output(opts): Promise<any>

Set output container.

See Introducing the set_output API for an example on how to use the API.

Parameters

ParameterTypeDescription
optsobject-
opts.transform?"default" | "pandas" | "polars"Configure output of transform and fit_transform.

Returns Promise<any>

Defined in generated/neighbors/NeighborhoodComponentsAnalysis.ts:320


transform()

transform(opts): Promise<any>

Apply the learned transformation to the given data.

Parameters

ParameterTypeDescription
optsobject-
opts.X?ArrayLike[]Data samples.

Returns Promise<any>

Defined in generated/neighbors/NeighborhoodComponentsAnalysis.ts:356