Skip to content
Merged
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
5 changes: 2 additions & 3 deletions python/cuml/cuml/ensemble/randomforest_common.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -644,8 +643,8 @@ class BaseRandomForestModel(Base, InteropMixin):
)
self.n_outputs_ = 1
self._treelite_model_bytes = <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:
Expand Down
30 changes: 28 additions & 2 deletions python/cuml/cuml/ensemble/randomforestclassifier.py
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
28 changes: 26 additions & 2 deletions python/cuml/cuml/ensemble/randomforestregressor.py
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
50 changes: 48 additions & 2 deletions python/cuml/cuml/neighbors/kneighbors_classifier.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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,
)
Comment thread
coderabbitai[bot] marked this conversation as resolved.
self.weights = weights

@generate_docstring(convert_dtype_cast='np.float32')
Expand Down
50 changes: 48 additions & 2 deletions python/cuml/cuml/neighbors/kneighbors_regressor.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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,
)
Comment thread
coderabbitai[bot] marked this conversation as resolved.
self.weights = weights

@generate_docstring(convert_dtype_cast='np.float32')
Expand Down
2 changes: 1 addition & 1 deletion python/cuml/cuml/neighbors/nearest_neighbors.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
8 changes: 1 addition & 7 deletions python/cuml/tests/test_sklearn_compatibility.py
Original file line number Diff line number Diff line change
Expand Up @@ -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",
},
Expand Down Expand Up @@ -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",
Expand Down
Loading