Skip to content

MAINT Parameters validation for sklearn.cluster.dbscan #24866

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

Closed
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
19 changes: 18 additions & 1 deletion sklearn/cluster/_dbscan.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,28 @@
from ..metrics.pairwise import _VALID_METRICS
from ..base import BaseEstimator, ClusterMixin
from ..utils.validation import _check_sample_weight
from ..utils._param_validation import Interval, StrOptions
from ..utils._param_validation import Interval, StrOptions, validate_params
from ..neighbors import NearestNeighbors
from ._dbscan_inner import dbscan_inner


@validate_params(
{
"X": ["array-like", "sparse matrix"],
"eps": [Interval(Real, 0.0, None, closed="neither")],
"min_samples": [Interval(Integral, 1, None, closed="left")],
"metric": [
StrOptions(set(_VALID_METRICS) | {"precomputed"}),
callable,
],
"metric_params": [dict, None],
"algorithm": [StrOptions({"auto", "ball_tree", "kd_tree", "brute"})],
"leaf_size": [Interval(Integral, 1, None, closed="left")],
"p": [Interval(Real, 0.0, None, closed="left"), None],
"sample_weight": ["array-like", None],
"n_jobs": [Integral, None],
}
)
def dbscan(
X,
eps=0.5,
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 @@ -10,6 +10,7 @@

PARAM_VALIDATION_FUNCTION_LIST = [
"sklearn.cluster.kmeans_plusplus",
"sklearn.cluster.dbscan",
]


Expand Down