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 (opens in a new tab)
Constructors
constructor()
Signature
new NearestCentroid(opts?: object): NearestCentroid;
Parameters
Name | Type | Description |
---|---|---|
opts? | object | - |
opts.metric? | string | Metric to use for distance computation. See the documentation of scipy.spatial.distance (opens in a new tab) and the metrics listed in distance\_metrics for valid metric values. Note that “wminkowski”, “seuclidean” and “mahalanobis” are not supported. The centroids for the samples corresponding to each class is the point from which the sum of the distances (according to the metric) of all samples that belong to that particular class are minimized. If the "manhattan" metric is provided, this centroid is the median and for all other metrics, the centroid is now set to be the mean. Default Value 'euclidean' |
opts.shrink_threshold? | number | Threshold for shrinking centroids to remove features. |
Returns
Defined in: generated/neighbors/NearestCentroid.ts:25 (opens in a new tab)
Methods
dispose()
Disposes of the underlying Python resources.
Once dispose()
is called, the instance is no longer usable.
Signature
dispose(): Promise<void>;
Returns
Promise
<void
>
Defined in: generated/neighbors/NearestCentroid.ts:97 (opens in a new tab)
fit()
Fit the NearestCentroid model according to the given training data.
Signature
fit(opts: object): Promise<any>;
Parameters
Name | 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:114 (opens in a new tab)
get_metadata_routing()
Get metadata routing of this object.
Please check User Guide on how the routing mechanism works.
Signature
get_metadata_routing(opts: object): Promise<any>;
Parameters
Name | Type | Description |
---|---|---|
opts | object | - |
opts.routing? | any | A MetadataRequest encapsulating routing information. |
Returns
Promise
<any
>
Defined in: generated/neighbors/NearestCentroid.ts:156 (opens in a new tab)
init()
Initializes the underlying Python resources.
This instance is not usable until the Promise
returned by init()
resolves.
Signature
init(py: PythonBridge): Promise<void>;
Parameters
Name | Type |
---|---|
py | PythonBridge |
Returns
Promise
<void
>
Defined in: generated/neighbors/NearestCentroid.ts:57 (opens in a new tab)
predict()
Perform classification on an array of test vectors X
.
The predicted class C
for each sample in X
is returned.
Signature
predict(opts: object): Promise<ArrayLike>;
Parameters
Name | Type | Description |
---|---|---|
opts | object | - |
opts.X? | ArrayLike | Test samples. |
Returns
Promise
<ArrayLike
>
Defined in: generated/neighbors/NearestCentroid.ts:193 (opens in a new tab)
score()
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.
Signature
score(opts: object): Promise<number>;
Parameters
Name | Type | Description |
---|---|---|
opts | object | - |
opts.X? | ArrayLike [] | Test samples. |
opts.sample_weight? | ArrayLike | Sample weights. |
opts.y? | ArrayLike | True labels for X . |
Returns
Promise
<number
>
Defined in: generated/neighbors/NearestCentroid.ts:228 (opens in a new tab)
set_score_request()
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:
Signature
set_score_request(opts: object): Promise<any>;
Parameters
Name | 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:279 (opens in a new tab)
Properties
_isDisposed
boolean
=false
Defined in: generated/neighbors/NearestCentroid.ts:23 (opens in a new tab)
_isInitialized
boolean
=false
Defined in: generated/neighbors/NearestCentroid.ts:22 (opens in a new tab)
_py
PythonBridge
Defined in: generated/neighbors/NearestCentroid.ts:21 (opens in a new tab)
id
string
Defined in: generated/neighbors/NearestCentroid.ts:18 (opens in a new tab)
opts
any
Defined in: generated/neighbors/NearestCentroid.ts:19 (opens in a new tab)
Accessors
centroids_
Centroid of each class.
Signature
centroids_(): Promise<ArrayLike[]>;
Returns
Promise
<ArrayLike
[]>
Defined in: generated/neighbors/NearestCentroid.ts:315 (opens in a new tab)
classes_
The unique classes labels.
Signature
classes_(): Promise<any[]>;
Returns
Promise
<any
[]>
Defined in: generated/neighbors/NearestCentroid.ts:340 (opens in a new tab)
feature_names_in_
Names of features seen during fit. Defined only when X
has feature names that are all strings.
Signature
feature_names_in_(): Promise<ArrayLike>;
Returns
Promise
<ArrayLike
>
Defined in: generated/neighbors/NearestCentroid.ts:390 (opens in a new tab)
n_features_in_
Number of features seen during fit.
Signature
n_features_in_(): Promise<number>;
Returns
Promise
<number
>
Defined in: generated/neighbors/NearestCentroid.ts:365 (opens in a new tab)
py
Signature
py(): PythonBridge;
Returns
PythonBridge
Defined in: generated/neighbors/NearestCentroid.ts:44 (opens in a new tab)
Signature
py(pythonBridge: PythonBridge): void;
Parameters
Name | Type |
---|---|
pythonBridge | PythonBridge |
Returns
void
Defined in: generated/neighbors/NearestCentroid.ts:48 (opens in a new tab)