DocumentationClassesNearestCentroid

Class: NearestCentroid

Nearest centroid classifier.

Each class is represented by its centroid, with test samples classified to the class with the nearest centroid.

Read more in the User Guide.

Python Reference

Constructors

new NearestCentroid()

new NearestCentroid(opts?): NearestCentroid

Parameters

ParameterTypeDescription
opts?object-
opts.metric?"euclidean" | "manhattan"Metric to use for distance computation. If metric="euclidean", the centroid for the samples corresponding to each class is the arithmetic mean, which minimizes the sum of squared L1 distances. If metric="manhattan", the centroid is the feature-wise median, which minimizes the sum of L1 distances.
opts.shrink_threshold?numberThreshold for shrinking centroids to remove features.

Returns NearestCentroid

Defined in generated/neighbors/NearestCentroid.ts:25

Properties

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

Accessors

centroids_

Get Signature

get centroids_(): Promise<ArrayLike[]>

Centroid of each class.

Returns Promise<ArrayLike[]>

Defined in generated/neighbors/NearestCentroid.ts:302


classes_

Get Signature

get classes_(): Promise<any[]>

The unique classes labels.

Returns Promise<any[]>

Defined in generated/neighbors/NearestCentroid.ts:327


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/NearestCentroid.ts:377


n_features_in_

Get Signature

get n_features_in_(): Promise<number>

Number of features seen during fit.

Returns Promise<number>

Defined in generated/neighbors/NearestCentroid.ts:352


py

Get Signature

get py(): PythonBridge

Returns PythonBridge

Set Signature

set py(pythonBridge): void

Parameters

ParameterType
pythonBridgePythonBridge

Returns void

Defined in generated/neighbors/NearestCentroid.ts:44

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/NearestCentroid.ts:96


fit()

fit(opts): Promise<any>

Fit the NearestCentroid model according to the given training data.

Parameters

ParameterTypeDescription
optsobject-
opts.X?ArrayLikeTraining vector, where n_samples is the number of samples and n_features is the number of features. Note that centroid shrinking cannot be used with sparse matrices.
opts.y?ArrayLikeTarget values.

Returns Promise<any>

Defined in generated/neighbors/NearestCentroid.ts:113


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/NearestCentroid.ts:152


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/NearestCentroid.ts:57


predict()

predict(opts): Promise<ArrayLike>

Perform classification on an array of test vectors X.

The predicted class C for each sample in X is returned.

Parameters

ParameterTypeDescription
optsobject-
opts.X?ArrayLikeTest samples.

Returns Promise<ArrayLike>

Defined in generated/neighbors/NearestCentroid.ts:188


score()

score(opts): Promise<number>

Return the mean accuracy on the given test data and labels.

In multi-label classification, this is the subset accuracy which is a harsh metric since you require for each sample that each label set be correctly predicted.

Parameters

ParameterTypeDescription
optsobject-
opts.sample_weight?ArrayLikeSample weights.
opts.X?ArrayLike[]Test samples.
opts.y?ArrayLikeTrue labels for X.

Returns Promise<number>

Defined in generated/neighbors/NearestCentroid.ts:222


set_score_request()

set_score_request(opts): Promise<any>

Request metadata passed to the score method.

Note that this method is only relevant if enable_metadata_routing=True (see sklearn.set_config). Please see User Guide on how the routing mechanism works.

The options for each parameter are:

Parameters

ParameterTypeDescription
optsobject-
opts.sample_weight?string | booleanMetadata routing for sample_weight parameter in score.

Returns Promise<any>

Defined in generated/neighbors/NearestCentroid.ts:268