3939from sklearn .utils .validation import (
4040 check_is_fitted ,
4141 check_consistent_length ,
42- check_array )
42+ check_array ,
43+ check_X_y )
4344
4445from onedal .datatypes import _check_array , _num_features , _num_samples
4546
@@ -339,8 +340,6 @@ def _onedal_ready(self, X, y, sample_weight):
339340 self ._validate_params ()
340341 else :
341342 self ._check_parameters ()
342- if sample_weight is not None :
343- sample_weight = self .check_sample_weight (sample_weight , X )
344343
345344 correct_sparsity = not sp .issparse (X )
346345 correct_ccp_alpha = self .ccp_alpha == 0.0
@@ -526,6 +525,8 @@ def _onedal_cpu_supported(self, method_name, *data):
526525 ready , X , y , sample_weight = self ._onedal_ready (* data )
527526 if not ready :
528527 return False
528+ elif sp .issparse (X ):
529+ return False
529530 elif sp .issparse (y ):
530531 return False
531532 elif sp .issparse (sample_weight ):
@@ -534,6 +535,8 @@ def _onedal_cpu_supported(self, method_name, *data):
534535 return False
535536 elif self .warm_start :
536537 return False
538+ elif self .oob_score and not daal_check_version ((2023 , 'P' , 101 )):
539+ return False
537540 elif not self .n_outputs_ == 1 :
538541 return False
539542 elif hasattr (self , 'estimators_' ):
@@ -563,14 +566,20 @@ def _onedal_gpu_supported(self, method_name, *data):
563566 ready , X , y , sample_weight = self ._onedal_ready (* data )
564567 if not ready :
565568 return False
569+ elif sp .issparse (X ):
570+ return False
566571 elif sp .issparse (y ):
567572 return False
573+ elif sp .issparse (sample_weight ):
574+ return False
568575 elif not sample_weight : # `sample_weight` is not supported.
569576 return False
570577 elif not self .ccp_alpha == 0.0 :
571578 return False
572579 elif self .warm_start :
573580 return False
581+ elif self .oob_score :
582+ return False
574583 elif not self .n_outputs_ == 1 :
575584 return False
576585 elif hasattr (self , 'estimators_' ):
@@ -596,9 +605,33 @@ def _onedal_gpu_supported(self, method_name, *data):
596605 f'Unknown method { method_name } in { self .__class__ .__name__ } ' )
597606
598607 def _onedal_fit (self , X , y , sample_weight = None , queue = None ):
599- X , y = make2d (np .asarray (X )), make2d (np .asarray (y ))
608+ if sklearn_check_version ('1.2' ):
609+ X , y = self ._validate_data (
610+ X , y , multi_output = False , accept_sparse = False ,
611+ dtype = [np .float64 , np .float32 ]
612+ )
613+ else :
614+ X , y = check_X_y (
615+ X , y , accept_sparse = False , dtype = [np .float64 , np .float32 ],
616+ multi_output = False
617+ )
600618
601- y = check_array (y , ensure_2d = False )
619+ if sample_weight is not None :
620+ sample_weight = self .check_sample_weight (sample_weight , X )
621+
622+ y = np .atleast_1d (y )
623+ if y .ndim == 2 and y .shape [1 ] == 1 :
624+ warnings .warn (
625+ "A column-vector y was passed when a 1d array was"
626+ " expected. Please change the shape of y to "
627+ "(n_samples,), for example using ravel()." ,
628+ DataConversionWarning ,
629+ stacklevel = 2 ,
630+ )
631+ if y .ndim == 1 :
632+ # reshape is necessary to preserve the data contiguity against vs
633+ # [:, np.newaxis] that does not.
634+ y = np .reshape (y , (- 1 , 1 ))
602635
603636 y , expanded_class_weight = self ._validate_y_class_weight (y )
604637
@@ -620,7 +653,7 @@ def _onedal_fit(self, X, y, sample_weight=None, queue=None):
620653 "Training data only contain information about one class." )
621654
622655 if self .oob_score :
623- err = 'out_of_bag_error|out_of_bag_error_per_observation '
656+ err = 'out_of_bag_error_accuracy|out_of_bag_error_decision_function '
624657 else :
625658 err = 'none'
626659
@@ -664,35 +697,35 @@ def _onedal_fit(self, X, y, sample_weight=None, queue=None):
664697 return self
665698
666699 def _onedal_predict (self , X , queue = None ):
700+ X = check_array (X , dtype = [np .float32 , np .float64 ])
701+ check_is_fitted (self )
667702 if sklearn_check_version ("1.0" ):
668703 self ._check_feature_names (X , reset = False )
669- X = check_array (
670- X ,
671- accept_sparse = False , # is not supported
672- dtype = [np .float64 , np .float32 ]
673- )
674704
675705 res = self ._onedal_estimator .predict (X , queue = queue )
676706 return np .take (self .classes_ ,
677707 res .ravel ().astype (np .int64 , casting = 'unsafe' ))
678708
679709 def _onedal_predict_proba (self , X , queue = None ):
710+ X = check_array (X , dtype = [np .float64 , np .float32 ])
680711 check_is_fitted (self )
681712 if sklearn_check_version ('0.23' ):
682713 self ._check_n_features (X , reset = False )
683714 if sklearn_check_version ("1.0" ):
684715 self ._check_feature_names (X , reset = False )
685- X = check_array (
686- X ,
687- accept_sparse = False , # is not supported
688- dtype = [np .float64 , np .float32 ]
689- )
690716 return self ._onedal_estimator .predict_proba (X , queue = queue )
691717
692718
693719class RandomForestRegressor (sklearn_RandomForestRegressor , BaseRandomForest ):
694720 __doc__ = sklearn_RandomForestRegressor .__doc__
695721
722+ if sklearn_check_version ('1.2' ):
723+ _parameter_constraints : dict = {
724+ ** sklearn_RandomForestRegressor ._parameter_constraints ,
725+ "max_bins" : [Interval (numbers .Integral , 2 , None , closed = "left" )],
726+ "min_bin_size" : [Interval (numbers .Integral , 1 , None , closed = "left" )]
727+ }
728+
696729 if sklearn_check_version ('1.0' ):
697730 def __init__ (
698731 self ,
@@ -862,6 +895,8 @@ def _onedal_cpu_supported(self, method_name, *data):
862895 return False
863896 elif self .warm_start :
864897 return False
898+ elif self .oob_score and not daal_check_version ((2023 , 'P' , 101 )):
899+ return False
865900 elif not self .n_outputs_ == 1 :
866901 return False
867902 elif hasattr (self , 'estimators_' ):
@@ -903,6 +938,8 @@ def _onedal_gpu_supported(self, method_name, *data):
903938 return False
904939 elif self .warm_start :
905940 return False
941+ elif self .oob_score :
942+ return False
906943 elif not self .n_outputs_ == 1 :
907944 return False
908945 elif hasattr (self , 'estimators_' ):
@@ -949,7 +986,7 @@ def _onedal_fit(self, X, y, sample_weight=None, queue=None):
949986 rs_ = check_random_state (self .random_state )
950987
951988 if self .oob_score :
952- err = 'out_of_bag_error|out_of_bag_error_per_observation '
989+ err = 'out_of_bag_error_r2|out_of_bag_error_prediction '
953990 else :
954991 err = 'none'
955992
@@ -986,11 +1023,7 @@ def _onedal_fit(self, X, y, sample_weight=None, queue=None):
9861023 def _onedal_predict (self , X , queue = None ):
9871024 if sklearn_check_version ("1.0" ):
9881025 self ._check_feature_names (X , reset = False )
989- X = check_array (
990- X ,
991- accept_sparse = False ,
992- dtype = [np .float64 , np .float32 ]
993- )
1026+ X = self ._validate_X_predict (X )
9941027 return self ._onedal_estimator .predict (X , queue = queue )
9951028
9961029 @wrap_output_data
0 commit comments