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.
Constructors
new NearestCentroid()
new NearestCentroid(
opts
?):NearestCentroid
Parameters
Parameter | Type | Description |
---|---|---|
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 ? | number | Threshold for shrinking centroids to remove features. |
Returns NearestCentroid
Defined in generated/neighbors/NearestCentroid.ts:25
Properties
Property | Type | Default value | Defined in |
---|---|---|---|
_isDisposed | boolean | false | generated/neighbors/NearestCentroid.ts:23 |
_isInitialized | boolean | false | generated/neighbors/NearestCentroid.ts:22 |
_py | PythonBridge | undefined | generated/neighbors/NearestCentroid.ts:21 |
id | string | undefined | generated/neighbors/NearestCentroid.ts:18 |
opts | any | undefined | generated/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
Parameter | Type |
---|---|
pythonBridge | PythonBridge |
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
Parameter | Type | Description |
---|---|---|
opts | object | - |
opts.X ? | ArrayLike | Training 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 ? | ArrayLike | Target 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
Parameter | Type | Description |
---|---|---|
opts | object | - |
opts.routing ? | any | A 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
Parameter | Type |
---|---|
py | PythonBridge |
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
Parameter | Type | Description |
---|---|---|
opts | object | - |
opts.X ? | ArrayLike | Test 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
Parameter | Type | Description |
---|---|---|
opts | object | - |
opts.sample_weight ? | ArrayLike | Sample weights. |
opts.X ? | ArrayLike [] | Test samples. |
opts.y ? | ArrayLike | True 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
Parameter | Type | Description |
---|---|---|
opts | object | - |
opts.sample_weight ? | string | boolean | Metadata routing for sample_weight parameter in score . |
Returns Promise
<any
>
Defined in generated/neighbors/NearestCentroid.ts:268