diff --git a/python/cuml/cuml/ensemble/randomforest_common.pyx b/python/cuml/cuml/ensemble/randomforest_common.pyx index 8fd9d2ad7d..99f5e9142d 100644 --- a/python/cuml/cuml/ensemble/randomforest_common.pyx +++ b/python/cuml/cuml/ensemble/randomforest_common.pyx @@ -322,7 +322,6 @@ class BaseRandomForestModel(Base, InteropMixin): min_impurity_decrease=0.0, max_batch_size=4096, random_state=None, - criterion=None, n_streams=4, oob_score=False, verbose=False, @@ -644,8 +643,8 @@ class BaseRandomForestModel(Base, InteropMixin): ) self.n_outputs_ = 1 self._treelite_model_bytes = (tl_bytes[:tl_bytes_len]) - # Ensure cached nvforest model is reset - self._nvforest_model = None + # Reload nvforest model + self._nvforest_model = self.as_nvforest() # Compute OOB score if requested if self.oob_score: diff --git a/python/cuml/cuml/ensemble/randomforestclassifier.py b/python/cuml/cuml/ensemble/randomforestclassifier.py index 299b5941b7..a251b04865 100644 --- a/python/cuml/cuml/ensemble/randomforestclassifier.py +++ b/python/cuml/cuml/ensemble/randomforestclassifier.py @@ -190,16 +190,42 @@ def _attrs_to_cpu(self, model): def __init__( self, *, + n_estimators=100, split_criterion="gini", + bootstrap=True, + max_samples=1.0, + max_depth="deprecated", + max_leaves=-1, + max_features="sqrt", + n_bins=128, + min_samples_leaf=1, + min_samples_split=2, + min_impurity_decrease=0.0, + max_batch_size=4096, + random_state=None, + n_streams=4, + oob_score=False, verbose=False, output_type=None, - **kwargs, ): super().__init__( split_criterion=split_criterion, + n_estimators=n_estimators, + bootstrap=bootstrap, + max_samples=max_samples, + max_depth=max_depth, + max_leaves=max_leaves, + max_features=max_features, + n_bins=n_bins, + min_samples_leaf=min_samples_leaf, + min_samples_split=min_samples_split, + min_impurity_decrease=min_impurity_decrease, + max_batch_size=max_batch_size, + random_state=random_state, + n_streams=n_streams, + oob_score=oob_score, verbose=verbose, output_type=output_type, - **kwargs, ) @nvtx.annotate( diff --git a/python/cuml/cuml/ensemble/randomforestregressor.py b/python/cuml/cuml/ensemble/randomforestregressor.py index 9139c840a7..556e6d9cc6 100644 --- a/python/cuml/cuml/ensemble/randomforestregressor.py +++ b/python/cuml/cuml/ensemble/randomforestregressor.py @@ -160,18 +160,42 @@ class RandomForestRegressor(BaseRandomForestModel, RegressorMixin): def __init__( self, *, + n_estimators=100, split_criterion="mse", + bootstrap=True, + max_samples=1.0, + max_depth="deprecated", + max_leaves=-1, max_features=1.0, + n_bins=128, + min_samples_leaf=1, + min_samples_split=2, + min_impurity_decrease=0.0, + max_batch_size=4096, + random_state=None, + n_streams=4, + oob_score=False, verbose=False, output_type=None, - **kwargs, ): super().__init__( + n_estimators=n_estimators, split_criterion=split_criterion, + bootstrap=bootstrap, + max_samples=max_samples, + max_depth=max_depth, + max_leaves=max_leaves, max_features=max_features, + n_bins=n_bins, + min_samples_leaf=min_samples_leaf, + min_samples_split=min_samples_split, + min_impurity_decrease=min_impurity_decrease, + max_batch_size=max_batch_size, + random_state=random_state, + n_streams=n_streams, + oob_score=oob_score, verbose=verbose, output_type=output_type, - **kwargs, ) @nvtx.annotate( diff --git a/python/cuml/cuml/neighbors/kneighbors_classifier.pyx b/python/cuml/cuml/neighbors/kneighbors_classifier.pyx index 2f528fa334..e1c5a912fb 100644 --- a/python/cuml/cuml/neighbors/kneighbors_classifier.pyx +++ b/python/cuml/cuml/neighbors/kneighbors_classifier.pyx @@ -74,6 +74,36 @@ class KNeighborsClassifier(ClassifierMixin, FMajorInputTagMixin, NeighborsBase): - [callable] : a user-defined function which accepts an array of distances, and returns an array of the same shape containing the weights. + p : float (default=2) + Parameter for the Minkowski metric. When p = 1, this is equivalent to + manhattan distance (l1), and euclidean distance (l2) for p = 2. For + arbitrary p, minkowski distance (lp) is used. + algo_params : dict, optional (default=None) + Used to configure the nearest neighbor algorithm to be used. + If set to None, parameters will be generated automatically. + Parameters for algorithm ``'brute'`` when inputs are sparse: + + - batch_size_index : (int) number of rows in each batch of \ + index array + - batch_size_query : (int) number of rows in each batch of \ + query array + + Parameters for algorithm ``'ivfflat'``: + + - nlist: (int) number of cells to partition dataset into + - nprobe: (int) at query time, number of cells used for search + + Parameters for algorithm ``'ivfpq'``: + + - nlist: (int) number of cells to partition dataset into + - nprobe: (int) at query time, number of cells used for search + - M: (int) number of subquantizers + - n_bits: (int) bits allocated per subquantizer + - usePrecomputedTables : (bool) whether to use precomputed tables + metric_params : dict, optional (default = None) + Additional keyword arguments for the metric function. + n_jobs : int (default = None) + Ignored, here for scikit-learn API compatibility. verbose : int or boolean, default=False Sets logging level. It must be one of `cuml.common.logger.level_*`. See :ref:`verbosity-levels` for more info. @@ -154,12 +184,28 @@ class KNeighborsClassifier(ClassifierMixin, FMajorInputTagMixin, NeighborsBase): def __init__( self, *, + n_neighbors=5, + algorithm="auto", + metric="euclidean", weights="uniform", + p=2, + algo_params=None, + metric_params=None, + n_jobs=None, # Ignored, here for sklearn API compatibility verbose=False, output_type=None, - **kwargs, ): - super().__init__(verbose=verbose, output_type=output_type, **kwargs) + super().__init__( + n_neighbors=n_neighbors, + algorithm=algorithm, + metric=metric, + p=p, + algo_params=algo_params, + metric_params=metric_params, + n_jobs=n_jobs, + verbose=verbose, + output_type=output_type, + ) self.weights = weights @generate_docstring(convert_dtype_cast='np.float32') diff --git a/python/cuml/cuml/neighbors/kneighbors_regressor.pyx b/python/cuml/cuml/neighbors/kneighbors_regressor.pyx index 648f6b8fa4..a24f786f21 100644 --- a/python/cuml/cuml/neighbors/kneighbors_regressor.pyx +++ b/python/cuml/cuml/neighbors/kneighbors_regressor.pyx @@ -76,6 +76,36 @@ class KNeighborsRegressor(RegressorMixin, FMajorInputTagMixin, NeighborsBase): - [callable] : a user-defined function which accepts an array of distances, and returns an array of the same shape containing the weights. + p : float (default=2) + Parameter for the Minkowski metric. When p = 1, this is equivalent to + manhattan distance (l1), and euclidean distance (l2) for p = 2. For + arbitrary p, minkowski distance (lp) is used. + algo_params : dict, optional (default=None) + Used to configure the nearest neighbor algorithm to be used. + If set to None, parameters will be generated automatically. + Parameters for algorithm ``'brute'`` when inputs are sparse: + + - batch_size_index : (int) number of rows in each batch of \ + index array + - batch_size_query : (int) number of rows in each batch of \ + query array + + Parameters for algorithm ``'ivfflat'``: + + - nlist: (int) number of cells to partition dataset into + - nprobe: (int) at query time, number of cells used for search + + Parameters for algorithm ``'ivfpq'``: + + - nlist: (int) number of cells to partition dataset into + - nprobe: (int) at query time, number of cells used for search + - M: (int) number of subquantizers + - n_bits: (int) bits allocated per subquantizer + - usePrecomputedTables : (bool) whether to use precomputed tables + metric_params : dict, optional (default = None) + Additional keyword arguments for the metric function. + n_jobs : int (default = None) + Ignored, here for scikit-learn API compatibility. verbose : int or boolean, default=False Sets logging level. It must be one of `cuml.common.logger.level_*`. See :ref:`verbosity-levels` for more info. @@ -156,12 +186,28 @@ class KNeighborsRegressor(RegressorMixin, FMajorInputTagMixin, NeighborsBase): def __init__( self, *, + n_neighbors=5, + algorithm="auto", + metric="euclidean", weights="uniform", + p=2, + algo_params=None, + metric_params=None, + n_jobs=None, # Ignored, here for sklearn API compatibility verbose=False, output_type=None, - **kwargs, ): - super().__init__(verbose=verbose, output_type=output_type, **kwargs) + super().__init__( + n_neighbors=n_neighbors, + algorithm=algorithm, + metric=metric, + p=p, + algo_params=algo_params, + metric_params=metric_params, + n_jobs=n_jobs, + verbose=verbose, + output_type=output_type, + ) self.weights = weights @generate_docstring(convert_dtype_cast='np.float32') diff --git a/python/cuml/cuml/neighbors/nearest_neighbors.pyx b/python/cuml/cuml/neighbors/nearest_neighbors.pyx index 43af59d66b..229c18fc79 100644 --- a/python/cuml/cuml/neighbors/nearest_neighbors.pyx +++ b/python/cuml/cuml/neighbors/nearest_neighbors.pyx @@ -559,13 +559,13 @@ class NeighborsBase(Base, InteropMixin, CMajorInputTagMixin, SparseInputTagMixin self, *, n_neighbors=5, - verbose=False, algorithm="auto", metric="euclidean", p=2, algo_params=None, metric_params=None, n_jobs=None, # Ignored, here for sklearn API compatibility + verbose=False, output_type=None, ): super().__init__(verbose=verbose, output_type=output_type) diff --git a/python/cuml/tests/test_sklearn_compatibility.py b/python/cuml/tests/test_sklearn_compatibility.py index 017234f856..351bdc1264 100644 --- a/python/cuml/tests/test_sklearn_compatibility.py +++ b/python/cuml/tests/test_sklearn_compatibility.py @@ -118,24 +118,18 @@ }, RandomForestRegressor: { "check_estimator_tags_renamed": "No support for modern tags infrastructure", - "check_do_not_raise_errors_in_init_or_set_params": "RandomForestRegressor raises errors in init or set_params", "check_regressor_data_not_an_array": "RandomForestRegressor does not handle non-array data", - "check_dict_unchanged": "RandomForestRegressor modifies input dictionaries", }, RandomForestClassifier: { "check_estimator_tags_renamed": "No support for modern tags infrastructure", - "check_do_not_raise_errors_in_init_or_set_params": "RandomForestClassifier raises errors in init or set_params", "check_classifier_data_not_an_array": "RandomForestClassifier does not handle non-array data", - "check_dict_unchanged": "RandomForestClassifier modifies input dictionaries", }, KNeighborsClassifier: { "check_estimator_tags_renamed": "No support for modern tags infrastructure", - "check_do_not_raise_errors_in_init_or_set_params": "KNeighborsClassifier raises errors in init or set_params", "check_classifier_data_not_an_array": "KNeighborsClassifier does not handle non-array data", }, KNeighborsRegressor: { "check_estimator_tags_renamed": "No support for modern tags infrastructure", - "check_do_not_raise_errors_in_init_or_set_params": "KNeighborsRegressor raises errors in init or set_params", "check_regressor_data_not_an_array": "KNeighborsRegressor does not handle non-array data", "check_supervised_y_2d": "KNeighborsRegressor does not handle 2D y", }, @@ -182,7 +176,7 @@ }, TSNE: { "check_estimator_tags_renamed": "No support for modern tags infrastructure", - "check_dont_overwrite_parameters": "TSNE overwrites parameters during fit", + "check_dont_overwrite_parameters": "TSNE only supports n_components = 2", "check_pipeline_consistency": "TSNE results are not deterministic", "check_methods_sample_order_invariance": "TSNE results depend on sample order", "check_methods_subset_invariance": "TSNE results depend on data subset",