Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[experiment] Verify diverging parameters do not impact SVM fit/predict quality. #2213

Draft
wants to merge 5 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 0 additions & 16 deletions onedal/neighbors/neighbors.py
Original file line number Diff line number Diff line change
Expand Up @@ -415,17 +415,6 @@ def _get_daal_params(self, data):
return params

def _onedal_fit(self, X, y, queue):
gpu_device = queue is not None and queue.sycl_device.is_gpu
if self.effective_metric_ == "euclidean" and not gpu_device:
params = self._get_daal_params(X)
if self._fit_method == "brute":
train_alg = bf_knn_classification_training

else:
train_alg = kdtree_knn_classification_training

return train_alg(**params).compute(X, y).model

policy = self._get_policy(queue, X, y)
X_table, y_table = to_table(X, y, queue=queue)
params = self._get_onedal_params(X_table, y)
Expand All @@ -436,11 +425,6 @@ def _onedal_fit(self, X, y, queue):
return train_alg.model

def _onedal_predict(self, model, X, params, queue):
if type(self._onedal_model) is kdtree_knn_classification_model:
return kdtree_knn_classification_prediction(**params).compute(X, model)
elif type(self._onedal_model) is bf_knn_classification_model:
return bf_knn_classification_prediction(**params).compute(X, model)

policy = self._get_policy(queue, X)
X = to_table(X, queue=queue)
if hasattr(self, "_onedal_model"):
Expand Down
15 changes: 6 additions & 9 deletions sklearnex/neighbors/knn_classification.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@
# limitations under the License.
# ===============================================================================

import numpy as np

from sklearn.metrics import accuracy_score
from sklearn.neighbors._classification import (
KNeighborsClassifier as _sklearn_KNeighborsClassifier,
Expand Down Expand Up @@ -113,8 +115,6 @@ def fit(self, X, y):
@wrap_output_data
def predict(self, X):
check_is_fitted(self)
if sklearn_check_version("1.0"):
self._check_feature_names(X, reset=False)
return dispatch(
self,
"predict",
Expand All @@ -128,8 +128,6 @@ def predict(self, X):
@wrap_output_data
def predict_proba(self, X):
check_is_fitted(self)
if sklearn_check_version("1.0"):
self._check_feature_names(X, reset=False)
return dispatch(
self,
"predict_proba",
Expand All @@ -143,8 +141,6 @@ def predict_proba(self, X):
@wrap_output_data
def score(self, X, y, sample_weight=None):
check_is_fitted(self)
if sklearn_check_version("1.0"):
self._check_feature_names(X, reset=False)
return dispatch(
self,
"score",
Expand All @@ -160,8 +156,6 @@ def score(self, X, y, sample_weight=None):
@wrap_output_data
def kneighbors(self, X=None, n_neighbors=None, return_distance=True):
check_is_fitted(self)
if sklearn_check_version("1.0") and X is not None:
self._check_feature_names(X, reset=False)
return dispatch(
self,
"kneighbors",
Expand All @@ -175,6 +169,7 @@ def kneighbors(self, X=None, n_neighbors=None, return_distance=True):
)

def _onedal_fit(self, X, y, queue=None):
X, y = validate_data(self, X, y, dtype=[np.float64, np.float32], accept_sparse="csr")
onedal_params = {
"n_neighbors": self.n_neighbors,
"weights": self.weights,
Expand All @@ -187,7 +182,6 @@ def _onedal_fit(self, X, y, queue=None):
requires_y = self._get_tags()["requires_y"]
except KeyError:
requires_y = False

self._onedal_estimator = onedal_KNeighborsClassifier(**onedal_params)
self._onedal_estimator.requires_y = requires_y
self._onedal_estimator.effective_metric_ = self.effective_metric_
Expand All @@ -197,14 +191,17 @@ def _onedal_fit(self, X, y, queue=None):
self._save_attributes()

def _onedal_predict(self, X, queue=None):
X = validate_data(self, X, dtype=[np.float64, np.float32], accept_sparse="csr", reset=False)
return self._onedal_estimator.predict(X, queue=queue)

def _onedal_predict_proba(self, X, queue=None):
X = validate_data(self, X, dtype=[np.float64, np.float32], accept_sparse="csr", reset=False)
return self._onedal_estimator.predict_proba(X, queue=queue)

def _onedal_kneighbors(
self, X=None, n_neighbors=None, return_distance=True, queue=None
):
X = validate_data(self, X, dtype=[np.float64, np.float32], accept_sparse="csr", reset=False)
return self._onedal_estimator.kneighbors(
X, n_neighbors, return_distance, queue=queue
)
Expand Down
Loading