@@ -74,12 +74,9 @@ def _local_parallel_build_trees(
7474 "bootstrap" : bootstrap ,
7575 }
7676
77- if sklearn_version >= parse_version ("1.4" ):
78- # TODO: remove when the minimum supported version of scikit-learn will be 1.4
79- # support for missing values
80- params_parallel_build_trees ["missing_values_in_feature_mask" ] = (
81- missing_values_in_feature_mask
82- )
77+ params_parallel_build_trees ["missing_values_in_feature_mask" ] = (
78+ missing_values_in_feature_mask
79+ )
8380
8481 tree = _parallel_build_trees (** params_parallel_build_trees )
8582
@@ -469,20 +466,9 @@ def __init__(
469466 "min_impurity_decrease" : min_impurity_decrease ,
470467 "ccp_alpha" : ccp_alpha ,
471468 "max_samples" : max_samples ,
469+ "monotonic_cst" : monotonic_cst ,
472470 }
473- # TODO: remove when the minimum supported version of scikit-learn will be 1.4
474- if sklearn_version >= parse_version ("1.4" ):
475- # use scikit-learn support for monotonic constraints
476- params_random_forest ["monotonic_cst" ] = monotonic_cst
477- else :
478- if monotonic_cst is not None :
479- raise ValueError (
480- "Monotonic constraints are not supported for scikit-learn "
481- "version < 1.4."
482- )
483- # create an attribute for compatibility with other scikit-learn tools such
484- # as HTML representation.
485- self .monotonic_cst = monotonic_cst
471+
486472 super ().__init__ (** params_random_forest )
487473
488474 self .sampling_strategy = sampling_strategy
@@ -548,37 +534,26 @@ def fit(self, X, y, sample_weight=None):
548534 if issparse (y ):
549535 raise ValueError ("sparse multilabel-indicator for y is not supported." )
550536
551- # TODO: remove when the minimum supported version of scipy will be 1.4
552- # Support for missing values
553- if sklearn_version >= parse_version ("1.4" ):
554- ensure_all_finite = False
555- else :
556- ensure_all_finite = True
557-
558537 X , y = validate_data (
559538 self ,
560539 X = X ,
561540 y = y ,
562541 multi_output = True ,
563542 accept_sparse = "csc" ,
564543 dtype = DTYPE ,
565- ensure_all_finite = ensure_all_finite ,
544+ ensure_all_finite = False ,
566545 )
567546
568- # TODO: remove when the minimum supported version of scikit-learn will be 1.4
569- if sklearn_version >= parse_version ("1.4" ):
570- # _compute_missing_values_in_feature_mask checks if X has missing values and
571- # will raise an error if the underlying tree base estimator can't handle
572- # missing values. Only the criterion is required to determine if the tree
573- # supports missing values.
574- estimator = type (self .estimator )(criterion = self .criterion )
575- missing_values_in_feature_mask = (
576- estimator ._compute_missing_values_in_feature_mask (
577- X , estimator_name = self .__class__ .__name__
578- )
547+ # _compute_missing_values_in_feature_mask checks if X has missing values and
548+ # will raise an error if the underlying tree base estimator can't handle
549+ # missing values. Only the criterion is required to determine if the tree
550+ # supports missing values.
551+ estimator = type (self .estimator )(criterion = self .criterion )
552+ missing_values_in_feature_mask = (
553+ estimator ._compute_missing_values_in_feature_mask (
554+ X , estimator_name = self .__class__ .__name__
579555 )
580- else :
581- missing_values_in_feature_mask = None
556+ )
582557
583558 if sample_weight is not None :
584559 sample_weight = _check_sample_weight (sample_weight , X )
0 commit comments