glassbox.models.neighbors._knn¶
KNeighborsClassifier and KNeighborsRegressor.
BaseKNN
¶
Bases: BaseModel
Initialize the BaseKNN estimator.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
k
|
int
|
Number of neighbors to use. |
5
|
metric
|
DistanceMetric
|
Distance metric to compute distances. |
DistanceMetric.EUCLIDEAN
|
algorithm
|
SearchAlgorithm
|
Algorithm used to compute the nearest neighbors. |
SearchAlgorithm.BRUTE_FORCE
|
Source code in glassbox/models/neighbors/_knn.py
fit
¶
Fits the model to the training data.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
X
|
ndarray
|
Training data of shape (n_samples, n_features). |
required |
y
|
ndarray
|
Target values of shape (n_samples,). |
required |
Returns:
| Type | Description |
|---|---|
Self
|
The fitted model. |
Source code in glassbox/models/neighbors/_knn.py
predict
¶
Predicts target values for the given data.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
X
|
ndarray
|
Data to predict on, of shape (n_samples, n_features) or (n_features,). |
required |
**kwargs
|
Any
|
Additional keyword arguments. |
{}
|
Returns:
| Type | Description |
|---|---|
ndarray
|
Predicted target values. |
Source code in glassbox/models/neighbors/_knn.py
KNeighborsClassifier
¶
Bases: BaseKNN
Source code in glassbox/models/neighbors/_knn.py
KNeighborsRegressor
¶
Bases: BaseKNN