8000 exp: create custom RealNotInt type · jeremiedbb/scikit-learn@718523f · GitHub
[go: up one dir, main page]

Skip to content

Commit 718523f

Browse files
committed
exp: create custom RealNotInt type
1 parent b510e44 commit 718523f

File tree

18 files changed

+80
-58
lines changed

18 files changed

+80
-58
lines changed

sklearn/cluster/_optics.py

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
from ..metrics.pairwise import _VALID_METRICS
2121
from ..utils import gen_batches, get_chunk_n_rows
2222
from ..utils._param_validation import Interval, HasMethods, StrOptions, validate_params
23+
from ..utils._param_validation import RealNotInt
2324
from ..utils.validation import check_memory
2425
from ..neighbors import NearestNeighbors
2526
from ..base import BaseEstimator, ClusterMixin
@@ -233,7 +234,7 @@ class OPTICS(ClusterMixin, BaseEstimator):
233234
_parameter_constraints: dict = {
234235
"min_samples": [
235236
Interval(Integral, 2, None, closed="left"),
236-
Interval("real_not_int", 0, 1, closed="both"),
237+
Interval(RealNotInt, 0, 1, closed="both"),
237238
],
238239
"max_eps": [Interval(Real, 0, None, closed="both")],
239240
"metric": [StrOptions(set(_VALID_METRICS) | {"precomputed"}), callable],
@@ -245,7 +246,7 @@ class OPTICS(ClusterMixin, BaseEstimator):
245246
"predecessor_correction": ["boolean"],
246247
"min_cluster_size": [
247248
Interval(Integral, 2, None, closed="left"),
248-
Interval("real_not_int", 0, 1, closed="right"),
249+
Interval(RealNotInt, 0, 1, closed="right"),
249250
None,
250251
],
251252
"algorithm": [StrOptions({"auto", "brute", "ball_tree", "kd_tree"})],
@@ -431,7 +432,7 @@ def _compute_core_distances_(X, neighbors, min_samples, working_memory):
431432
"X": [np.ndarray, "sparse matrix"],
432433
"min_samples": [
433434
Interval(Integral, 2, None, closed="left"),
434-
Interval("real_not_int", 0, 1, closed="both"),
435+
Interval(RealNotInt, 0, 1, closed="both"),
435436
],
436437
"max_eps": [Interval(Real, 0, None, closed="both")],
437438
"metric": [StrOptions(set(_VALID_METRICS) | {"precomputed"}), callable],
@@ -724,11 +725,11 @@ def cluster_optics_dbscan(*, reachability, core_distances, ordering, eps):
724725
"ordering": [np.ndarray],
725726
"min_samples": [
726727
Interval(Integral, 2, None, closed="left"),
727-
Interval("real_not_int", 0, 1, closed="both"),
728+
Interval(RealNotInt, 0, 1, closed="both"),
728729
],
729730
"min_cluster_size": [
730731
Interval(Integral, 2, None, closed="left"),
731-
Interval("real_not_int", 0, 1, closed="both"),
732+
Interval(RealNotInt, 0, 1, closed="both"),
732733
None,
733734
],
734735
"xi": [Interval(Real, 0, 1, closed="both")],

sklearn/decomposition/_pca.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
from ..utils.extmath import stable_cumsum
2828
from ..utils.validation import check_is_fitted
2929
from ..utils._param_validation import Interval, StrOptions
30+
from ..utils._param_validation import RealNotInt
3031

3132

3233
def _assess_dimension(spectrum, rank, n_samples):
@@ -363,7 +364,7 @@ class PCA(_BasePCA):
363364
_parameter_constraints: dict = {
364365
"n_components": [
365366
Interval(Integral, 0, None, closed="left"),
366-
Interval("real_not_int", 0, 1, closed="neither"),
367+
Interval(RealNotInt, 0, 1, closed="neither"),
367368
StrOptions({"mle"}),
368369
None,
369370
],

sklearn/ensemble/_bagging.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
from ..utils.multiclass import check_classification_targets
2323
from ..utils.random import sample_without_replacement
2424
from ..utils._param_validation import Interval, HasMethods, StrOptions
25+
from ..utils._param_validation import RealNotInt
2526
from ..utils.validation import has_fit_parameter, check_is_fitted, _check_sample_weight
2627
from ..utils._tags import _safe_tags
2728
from ..utils.parallel import delayed, Parallel
@@ -248,11 +249,11 @@ class BaseBagging(BaseEnsemble, metaclass=ABCMeta):
248249
"n_estimators": [Interval(Integral, 1, None, closed="left")],
249250
"max_samples": [
250251
Interval(Integral, 1, None, closed="left"),
251-
Interval("real_not_int", 0, 1, closed="right"),
252+
Interval(RealNotInt, 0, 1, closed="right"),
252253
],
253254
"max_features": [
254255
Interval(Integral, 1, None, closed="left"),
255-
Interval("real_not_int", 0, 1, closed="right"),
256+
Interval(RealNotInt, 0, 1, closed="right"),
256257
],
257258
"bootstrap": ["boolean"],
258259
"bootstrap_features": ["boolean"],

sklearn/ensemble/_forest.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,7 @@ class calls the ``fit`` method of each sub-estimator on random samples
7474
)
7575
from ..utils.validation import _num_samples
7676
from ..utils._param_validation import Interval, StrOptions
77+
from ..utils._param_validation import RealNotInt
7778

7879

7980
__all__ = [
@@ -206,7 +207,7 @@ class BaseForest(MultiOutputMixin, BaseEnsemble, metaclass=ABCMeta):
206207
"warm_start": ["boolean"],
207208
"max_samples": [
208209
None,
209-
Interval("real_not_int", 0.0, 1.0, closed="right"),
210+
Interval(RealNotInt, 0.0, 1.0, closed="right"),
210211
Interval(Integral, 1, None, closed="left"),
211212
],
212213
}

sklearn/ensemble/_hist_gradient_boosting/gradient_boosting.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
_check_monotonic_cst,
2828
)
2929
from ...utils._param_validation import Interval, StrOptions
30+
from ...utils._param_validation import RealNotInt
3031
from ...utils._openmp_helpers import _openmp_effective_n_threads
3132
from ...utils.multiclass import check_classification_targets
3233
from ...metrics import check_scoring
@@ -103,7 +104,7 @@ class BaseHistGradientBoosting(BaseEstimator, ABC):
103104
],
104105
"n_iter_no_change": [Interval(Integral, 1, None, closed="left")],
105106
"validation_fraction": [
106-
Interval("real_not_int", 0, 1, closed="neither"),
107+
Interval(RealNotInt, 0, 1, closed="neither"),
107108
Interval(Integral, 1, None, closed="left"),
108109
None,
109110
],

sklearn/ensemble/_iforest.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
< 2851 /code>
1717
get_chunk_n_rows,
1818
)
1919
from ..utils._param_validation import Interval, StrOptions
20+
from ..utils._param_validation import RealNotInt
2021
from ..utils.validation import check_is_fitted, _num_samples
2122
from ..base import OutlierMixin
2223

@@ -206,7 +207,7 @@ class IsolationForest(OutlierMixin, BaseBagging):
206207
"max_samples": [
207208
StrOptions({"auto"}),
208209
Interval(Integral, 1, None, closed="left"),
209-
Interval("real_not_int", 0, 1, closed="right"),
210+
Interval(RealNotInt, 0, 1, closed="right"),
210211
],
211212
"contamination": [
212213
StrOptions({"auto"}),

sklearn/feature_extraction/image.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
from ..base import BaseEstimator, TransformerMixin
1919
from ..utils import check_array, check_random_state
2020
from ..utils._param_validation import Hidden, Interval, validate_params
21+
from ..utils._param_validation import RealNotInt
2122

2223
__all__ = [
2324
"PatchExtractor",
@@ -343,7 +344,7 @@ def _extract_patches(arr, patch_shape=8, extraction_step=1):
343344
"image": [np.ndarray],
344345
"patch_size": [tuple, list],
345346
"max_patches": [
346-
Interval("real_not_int", 0, 1, closed="neither"),
347+
Interval(RealNotInt, 0, 1, closed="neither"),
347348
Interval(Integral, 1, None, closed="left"),
348349
None,
349350
],
@@ -542,7 +543,7 @@ class PatchExtractor(TransformerMixin, BaseEstimator):
542543
"patch_size": [tuple, None],
543544
"max_patches": [
544545
None,
545-
Interval("real_not_int", 0, 1, closed="neither"),
546+
Interval(RealNotInt, 0, 1, closed="neither"),
546547
Interval(Integral, 1, None, closed="left"),
547548
],
548549
"random_state": ["random_state"],

sklearn/feature_extraction/text.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@
3232
from ..utils import _IS_32BIT
3333
from ..exceptions import NotFittedError
3434
from ..utils._param_validation import StrOptions, Interval, HasMethods
35+
from ..utils._param_validation import RealNotInt
3536

3637

3738
__all__ = [
@@ -1148,11 +1149,11 @@ class CountVectorizer(_VectorizerMixin, BaseEstimator):
11481149
"ngram_range": [tuple],
11491150
"analyzer": [StrOptions({"word", "char", "char_wb"}), callable],
11501151
"max_df": [
1151-
Interval("real_not_int", 0, 1, closed="both"),
1152+
Interval(RealNotInt, 0, 1, closed="both"),
11521153
Interval(Integral, 1, None, closed="left"),
11531154
],
11541155
"min_df": [
1155-
Interval("real_not_int", 0, 1, closed="both"),
1156+
Interval(RealNotInt, 0, 1, closed="both"),
11561157
Interval(Integral, 1, None, closed="left"),
11571158
],
11581159
"max_features": [Interval(Integral, 1, None, closed="left"), None],

sklearn/feature_selection/_rfe.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
from ..utils.metaestimators import available_if
1515
from ..utils.metaestimators import _safe_split
1616
from ..utils._param_validation import HasMethods, Interval
17+
from ..utils._param_validation import RealNotInt
1718
from ..utils._tags import _safe_tags
1819
from ..utils.validation import check_is_fitted
1920
from ..utils.parallel import delayed, Parallel
@@ -187,12 +188,12 @@ class RFE(SelectorMixin, MetaEstimatorMixin, BaseEstimator):
187188
"estimator": [HasMethods(["fit"])],
188189
"n_features_to_select": [
189190
None,
190-
Interval("real_not_int", 0, 1, closed="right"),
191+
Interval(RealNotInt, 0, 1, closed="right"),
191192
Interval(Integral, 0, None, closed="neither"),
192193
],
193194
"step": [
194195
Interval(Integral, 0, None, closed="neither"),
195-
Interval("real_not_int", 0, 1, closed="neither"),
196+
Interval(RealNotInt, 0, 1, closed="neither"),
196197
],
197198
"verbose": ["verbose"],
198199
"importance_getter": [str, callable],

sklearn/feature_selection/_sequential.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
from ._base import SelectorMixin
1111
from ..base import BaseEstimator, MetaEstimatorMixin, clone
1212
from ..utils._param_validation import HasMethods, Hidden, Interval, StrOptions
13+
from ..utils._param_validation import RealNotInt
1314
from ..utils._tags import _safe_tags
1415
from ..utils.validation import check_is_fitted
1516
from ..model_selection import cross_val_score
@@ -154,7 +155,7 @@ class SequentialFeatureSelector(SelectorMixin, MetaEstimatorMixin, BaseEstimator
154155
"estimator": [HasMethods(["fit"])],
155156
"n_features_to_select": [
156157
StrOptions({"auto", "warn"}, deprecated={"warn"}),
157-
Interval("real_not_int", 0, 1, closed="right"),
158+
Interval(RealNotInt, 0, 1, closed="right"),
158159
Interval(Integral, 0, None, closed="neither"),
159160
Hidden(None),
160161
],

0 commit comments

Comments
 (0)
0