ml_grid.model_classes.knn_wrapper_class
KNN Wrapper for GPU-accelerated KNN.
This module provides a scikit-learn compatible wrapper for the simbsig.neighbors.KNeighborsClassifier, with GPU support.
Classes
Initializes the KNNWrapper. |
Module Contents
- class ml_grid.model_classes.knn_wrapper_class.KNNWrapper(n_neighbors: int = 5, weights: str = 'uniform', algorithm: str = 'auto', leaf_size: int = 30, p: int = 2, metric: str = 'minkowski', metric_params: Dict[str, Any] | None = None, device: str | None = None)[source]
Initializes the KNNWrapper.
- Parameters:
n_neighbors (int) – Number of neighbors to use.
weights (str) – Weight function used in prediction.
algorithm (str) – Algorithm used to compute the nearest neighbors.
leaf_size (int) – Leaf size passed to BallTree or KDTree.
p (int) – Power parameter for the Minkowski metric.
metric (str) – The distance metric to use for the tree.
metric_params (Optional[Dict[str, Any]]) – Additional keyword arguments for the metric function. Defaults to None.
device (Optional[str]) – The device to use (‘gpu’ or ‘cpu’). If None, it auto-detects GPU availability. Defaults to None.
- model: simbsig.neighbors.KNeighborsClassifier | sklearn.neighbors.KNeighborsClassifier | None = None[source]
- fit(X: pandas.DataFrame | numpy.ndarray, y: pandas.Series | numpy.ndarray) KNNWrapper[source]
Fits the KNN model.
Initializes and fits the simbsig.neighbors.KNeighborsClassifier.
- Parameters:
X (Union[pd.DataFrame, np.ndarray]) – The training input samples.
y (Union[pd.Series, np.ndarray]) – The target values.
- Returns:
The fitted estimator.
- Return type:
- predict(X: pandas.DataFrame | numpy.ndarray) numpy.ndarray[source]
Predicts class labels for samples in X.
- Parameters:
X (Union[pd.DataFrame, np.ndarray]) – The input samples to predict.
- Returns:
The predicted class labels.
- Return type:
np.ndarray
- predict_proba(X: pandas.DataFrame | numpy.ndarray) numpy.ndarray[source]
Predicts class probabilities for samples in X.
- Parameters:
X (Union[pd.DataFrame, np.ndarray]) – The input samples.
- Returns:
The class probabilities of the input samples.
- Return type:
np.ndarray
- score(X: pandas.DataFrame | numpy.ndarray, y: pandas.Series | numpy.ndarray) float[source]
Returns the mean accuracy on the given test data and labels.
- Parameters:
X (Union[pd.DataFrame, np.ndarray]) – Test samples.
y (Union[pd.Series, np.ndarray]) – True labels for X.
- Returns:
Mean accuracy of self.predict(X) wrt. y.
- Return type:
- set_params(**parameters: Any) KNNWrapper[source]
Sets the parameters of this estimator.
- Parameters:
**parameters (Any) – Estimator parameters.
- Returns:
The instance with updated parameters.
- Return type: