Skip to content

MAINT Parameters validation for spectral_clustering #25378

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

Merged
merged 5 commits into from
Feb 7, 2023
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
3 changes: 2 additions & 1 deletion sklearn/cluster/_spectral.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
from scipy.sparse import csc_matrix

from ..base import BaseEstimator, ClusterMixin
from ..utils._param_validation import Interval, StrOptions
from ..utils._param_validation import Interval, StrOptions, validate_params
from ..utils import check_random_state, as_float_array
from ..metrics.pairwise import pairwise_kernels, KERNEL_PARAMS
from ..neighbors import kneighbors_graph, NearestNeighbors
Expand Down Expand Up @@ -190,6 +190,7 @@ def discretize(
return labels


@validate_params({"affinity": ["array-like", "sparse matrix"]})
def spectral_clustering(
affinity,
*,
Expand Down
1 change: 1 addition & 0 deletions sklearn/tests/test_public_functions.py
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,7 @@ def test_function_param_validation(func_module):

PARAM_VALIDATION_CLASS_WRAPPER_LIST = [
("sklearn.cluster.affinity_propagation", "sklearn.cluster.AffinityPropagation"),
("sklearn.cluster.spectral_clustering", "sklearn.cluster.SpectralClustering"),
("sklearn.covariance.ledoit_wolf", "sklearn.covariance.LedoitWolf"),
("sklearn.covariance.oas", "sklearn.covariance.OAS"),
("sklearn.decomposition.dict_learning", "sklearn.decomposition.DictionaryLearning"),
Expand Down