Thanks to visit codestin.com
Credit goes to github.com

Skip to content
Merged
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
4 changes: 2 additions & 2 deletions sklearn/neighbors/_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -667,7 +667,7 @@ class from an array representing our data set and ask who's
if self.effective_metric_ == 'precomputed':
X = _check_precomputed(X)
else:
X = check_array(X, accept_sparse='csr')
X = self._validate_data(X, accept_sparse='csr', reset=False)
else:
query_is_train = True
X = self._fit_X
Expand Down Expand Up @@ -982,7 +982,7 @@ class from an array representing our data set and ask who's
if self.effective_metric_ == 'precomputed':
X = _check_precomputed(X)
else:
X = check_array(X, accept_sparse='csr')
X = self._validate_data(X, accept_sparse='csr', reset=False)
else:
query_is_train = True
X = self._fit_X
Expand Down
7 changes: 3 additions & 4 deletions sklearn/neighbors/_classification.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
from ._base import _check_weights, _get_weights
from ._base import NeighborsBase, KNeighborsMixin, RadiusNeighborsMixin
from ..base import ClassifierMixin
from ..utils import check_array
from ..utils.validation import _deprecate_positional_args


Expand Down Expand Up @@ -192,7 +191,7 @@ def predict(self, X):
y : ndarray of shape (n_queries,) or (n_queries, n_outputs)
Class labels for each data sample.
"""
X = check_array(X, accept_sparse='csr')
X = self._validate_data(X, accept_sparse='csr', reset=False)

neigh_dist, neigh_ind = self.kneighbors(X)
classes_ = self.classes_
Expand Down Expand Up @@ -236,7 +235,7 @@ def predict_proba(self, X):
The class probabilities of the input samples. Classes are ordered
by lexicographic order.
"""
X = check_array(X, accept_sparse='csr')
X = self._validate_data(X, accept_sparse='csr', reset=False)

neigh_dist, neigh_ind = self.kneighbors(X)

Expand Down Expand Up @@ -545,7 +544,7 @@ def predict_proba(self, X):
by lexicographic order.
"""

X = check_array(X, accept_sparse='csr')
X = self._validate_data(X, accept_sparse='csr', reset=False)
n_queries = _num_samples(X)

neigh_dist, neigh_ind = self.radius_neighbors(X)
Expand Down
2 changes: 1 addition & 1 deletion sklearn/neighbors/_nca.py
Original file line number Diff line number Diff line change
Expand Up @@ -263,7 +263,7 @@ def transform(self, X):
"""

check_is_fitted(self)
X = check_array(X)
X = self._validate_data(X, reset=False)

return np.dot(X, self.components_.T)

Expand Down
4 changes: 2 additions & 2 deletions sklearn/neighbors/_nearest_centroid.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
from ..base import BaseEstimator, ClassifierMixin
from ..metrics.pairwise import pairwise_distances
from ..preprocessing import LabelEncoder
from ..utils.validation import check_array, check_is_fitted
from ..utils.validation import check_is_fitted
from ..utils.validation import _deprecate_positional_args
from ..utils.sparsefuncs import csc_median_axis_0
from ..utils.multiclass import check_classification_targets
Expand Down Expand Up @@ -201,6 +201,6 @@ def predict(self, X):
"""
check_is_fitted(self)

X = check_array(X, accept_sparse='csr')
X = self._validate_data(X, accept_sparse='csr', reset=False)
return self.classes_[pairwise_distances(
X, self.centroids_, metric=self.metric).argmin(axis=1)]
5 changes: 2 additions & 3 deletions sklearn/neighbors/_regression.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
from ._base import _get_weights, _check_weights
from ._base import NeighborsBase, KNeighborsMixin, RadiusNeighborsMixin
from ..base import RegressorMixin
from ..utils import check_array
from ..utils.validation import _deprecate_positional_args
from ..utils.deprecation import deprecated

Expand Down Expand Up @@ -203,7 +202,7 @@ def predict(self, X):
y : ndarray of shape (n_queries,) or (n_queries, n_outputs), dtype=int
Target values.
"""
X = check_array(X, accept_sparse='csr')
X = self._validate_data(X, accept_sparse='csr', reset=False)

neigh_dist, neigh_ind = self.kneighbors(X)

Expand Down Expand Up @@ -392,7 +391,7 @@ def predict(self, X):
dtype=double
Target values.
"""
X = check_array(X, accept_sparse='csr')
X = self._validate_data(X, accept_sparse='csr', reset=False)

neigh_dist, neigh_ind = self.radius_neighbors(X)

Expand Down
1 change: 0 additions & 1 deletion sklearn/tests/test_common.py
Original file line number Diff line number Diff line change
Expand Up @@ -279,7 +279,6 @@ def test_search_cv(estimator, check, request):
'multiclass',
'multioutput',
'naive_bayes',
'neighbors',
'pipeline',
'random_projection',
'semi_supervised',
Expand Down