Skip to content

Commit

Permalink
passing tests
Browse files Browse the repository at this point in the history
  • Loading branch information
divyegala committed Nov 6, 2024
1 parent 00c14d6 commit d46c31d
Show file tree
Hide file tree
Showing 54 changed files with 177 additions and 162 deletions.
34 changes: 20 additions & 14 deletions python/cuml/cuml/_thirdparty/sklearn/preprocessing/_data.py
Original file line number Diff line number Diff line change
Expand Up @@ -327,8 +327,8 @@ def _reset(self):
del self.data_range_

@classmethod
def get_param_names(cls):
return super().get_param_names() + [
def _get_param_names(cls):
return super()._get_param_names() + [
"feature_range",
"copy"
]
Expand Down Expand Up @@ -652,8 +652,9 @@ def _reset(self):
del self.mean_
del self.var_

def get_param_names(self):
return super().get_param_names() + [
@classmethod
def _get_param_names(cls):
return super()._get_param_names() + [
"with_mean",
"with_std",
"copy"
Expand Down Expand Up @@ -956,8 +957,9 @@ def _reset(self):
del self.n_samples_seen_
del self.max_abs_

def get_param_names(self):
return super().get_param_names() + [
@classmethod
def _get_param_names(cls):
return super()._get_param_names() + [
"copy"
]

Expand Down Expand Up @@ -1206,8 +1208,9 @@ def __init__(self, *, with_centering=True, with_scaling=True,
self.quantile_range = quantile_range
self.copy = copy

def get_param_names(self):
return super().get_param_names() + [
@classmethod
def _get_param_names(cls):
return super()._get_param_names() + [
"with_centering",
"with_scaling",
"quantile_range",
Expand Down Expand Up @@ -1479,8 +1482,9 @@ def __init__(self, degree=2, *, interaction_only=False, include_bias=True,
self.include_bias = include_bias
self.order = order

def get_param_names(self):
return super().get_param_names() + [
@classmethod
def _get_param_names(cls):
return super()._get_param_names() + [
"degree",
"interaction_only",
"include_bias",
Expand Down Expand Up @@ -2274,8 +2278,9 @@ def __init__(self, *, n_quantiles=1000, output_distribution='uniform',
self.random_state = random_state
self.copy = copy

def get_param_names(self):
return super().get_param_names() + [
@classmethod
def _get_param_names(cls):
return super()._get_param_names() + [
"n_quantiles",
"output_distribution",
"ignore_implicit_zeros",
Expand Down Expand Up @@ -2798,8 +2803,9 @@ def __init__(self, method='yeo-johnson', *, standardize=True, copy=True):
self.standardize = standardize
self.copy = copy

def get_param_names(self):
return super().get_param_names() + [
@classmethod
def _get_param_names(cls):
return super()._get_param_names() + [
"method",
"standardize",
"copy"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -159,8 +159,8 @@ def __init__(self, n_bins=5, *, encode='onehot', strategy='quantile'):
self.strategy = strategy

@classmethod
def get_param_names(cls):
return super().get_param_names() + [
def _get_param_names(cls):
return super()._get_param_names() + [
"n_bins",
"encode",
"strategy"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -244,8 +244,8 @@ def __init__(self, *, missing_values=np.nan, strategy="mean",
self.copy = copy

@classmethod
def get_param_names(cls):
return super().get_param_names() + [
def _get_param_names(cls):
return super()._get_param_names() + [
"strategy",
"fill_value",
"verbose",
Expand Down Expand Up @@ -545,8 +545,9 @@ def __init__(self, *, missing_values=np.nan, features="missing-only",
self.sparse = sparse
self.error_on_new = error_on_new

def get_param_names(self):
return super().get_param_names() + [
@classmethod
def _get_param_names(cls):
return super()._get_param_names() + [
"missing_values",
"features",
"sparse",
Expand Down
4 changes: 2 additions & 2 deletions python/cuml/cuml/cluster/agglomerative.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -280,8 +280,8 @@ class AgglomerativeClustering(Base, ClusterMixin, CMajorInputTagMixin):
return self.fit(X).labels_

@classmethod
def get_param_names(cls):
return super().get_param_names() + [
def _get_param_names(cls):
return super()._get_param_names() + [
"n_clusters",
"affinity",
"metric",
Expand Down
4 changes: 2 additions & 2 deletions python/cuml/cuml/cluster/dbscan.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -467,8 +467,8 @@ class DBSCAN(UniversalBase,
return self.labels_

@classmethod
def get_param_names(cls):
return super().get_param_names() + [
def _get_param_names(cls):
return super()._get_param_names() + [
"eps",
"min_samples",
"max_mbytes_per_batch",
Expand Down
4 changes: 2 additions & 2 deletions python/cuml/cuml/cluster/hdbscan/hdbscan.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -1113,8 +1113,8 @@ class HDBSCAN(UniversalBase, ClusterMixin, CMajorInputTagMixin):
self._cpu_to_gpu_interop_prepped = True

@classmethod
def get_param_names(cls):
return super().get_param_names() + [
def _get_param_names(cls):
return super()._get_param_names() + [
"metric",
"min_cluster_size",
"max_cluster_size",
Expand Down
4 changes: 2 additions & 2 deletions python/cuml/cuml/cluster/kmeans.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -697,8 +697,8 @@ class KMeans(UniversalBase,
return self.transform(X, convert_dtype=convert_dtype)

@classmethod
def get_param_names(cls):
return super().get_param_names() + \
def _get_param_names(cls):
return super()._get_param_names() + \
['n_init', 'oversampling_factor', 'max_samples_per_batch',
'init', 'max_iter', 'n_clusters', 'random_state',
'tol', "convert_dtype"]
Expand Down
4 changes: 2 additions & 2 deletions python/cuml/cuml/dask/cluster/dbscan.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Copyright (c) 2020-2023, NVIDIA CORPORATION.
# Copyright (c) 2020-2024, NVIDIA CORPORATION.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -160,5 +160,5 @@ def fit_predict(self, X, out_dtype="int32"):
self.fit(X, out_dtype)
return self.get_combined_model().labels_

def get_param_names(self):
def _get_param_names(self):
return list(self.kwargs.keys())
2 changes: 1 addition & 1 deletion python/cuml/cuml/dask/cluster/kmeans.py
Original file line number Diff line number Diff line change
Expand Up @@ -302,5 +302,5 @@ def score(self, X, sample_weight=None):
cp.asarray(self.client.compute(scores, sync=True)) * -1.0
)

def get_param_names(self):
def _get_param_names(self):
return list(self.kwargs.keys())
4 changes: 2 additions & 2 deletions python/cuml/cuml/dask/decomposition/pca.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Copyright (c) 2019-2023, NVIDIA CORPORATION.
# Copyright (c) 2019-2024, NVIDIA CORPORATION.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -215,7 +215,7 @@ def inverse_transform(self, X, delayed=True):
"""
return self._inverse_transform(X, n_dims=2, delayed=delayed)

def get_param_names(self):
def _get_param_names(self):
return list(self.kwargs.keys())

@staticmethod
Expand Down
4 changes: 2 additions & 2 deletions python/cuml/cuml/dask/decomposition/tsvd.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Copyright (c) 2019-2023, NVIDIA CORPORATION.
# Copyright (c) 2019-2024, NVIDIA CORPORATION.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -177,7 +177,7 @@ def inverse_transform(self, X, delayed=True):
"""
return self._inverse_transform(X, n_dims=2, delayed=delayed)

def get_param_names(self):
def _get_param_names(self):
return list(self.kwargs.keys())

@staticmethod
Expand Down
4 changes: 2 additions & 2 deletions python/cuml/cuml/dask/linear_model/linear_regression.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Copyright (c) 2019-2023, NVIDIA CORPORATION.
# Copyright (c) 2019-2024, NVIDIA CORPORATION.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -106,7 +106,7 @@ def predict(self, X, delayed=True):
"""
return self._predict(X, delayed=delayed)

def get_param_names(self):
def _get_param_names(self):
return list(self.kwargs.keys())

@staticmethod
Expand Down
4 changes: 2 additions & 2 deletions python/cuml/cuml/dask/linear_model/ridge.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Copyright (c) 2019-2023, NVIDIA CORPORATION.
# Copyright (c) 2019-2024, NVIDIA CORPORATION.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -114,7 +114,7 @@ def predict(self, X, delayed=True):
"""
return self._predict(X, delayed=delayed)

def get_param_names(self):
def _get_param_names(self):
return list(self.kwargs.keys())

@staticmethod
Expand Down
4 changes: 2 additions & 2 deletions python/cuml/cuml/decomposition/incremental_pca.py
Original file line number Diff line number Diff line change
Expand Up @@ -449,9 +449,9 @@ def transform(self, X, convert_dtype=False) -> CumlArray:
return super().transform(X)

@classmethod
def get_param_names(cls):
def _get_param_names(cls):
# Skip super() since we dont pass any extra parameters in __init__
return Base.get_param_names() + [
return Base._get_param_names() + [
"n_components",
"whiten",
"copy",
Expand Down
4 changes: 2 additions & 2 deletions python/cuml/cuml/decomposition/pca.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -726,8 +726,8 @@ class PCA(UniversalBase,
return t_input_data

@classmethod
def get_param_names(cls):
return super().get_param_names() + \
def _get_param_names(cls):
return super()._get_param_names() + \
["copy", "iterated_power", "n_components", "svd_solver", "tol",
"whiten", "random_state"]

Expand Down
4 changes: 2 additions & 2 deletions python/cuml/cuml/decomposition/tsvd.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -483,8 +483,8 @@ class TruncatedSVD(UniversalBase,
return t_input_data

@classmethod
def get_param_names(cls):
return super().get_param_names() + \
def _get_param_names(cls):
return super()._get_param_names() + \
["algorithm", "n_components", "n_iter", "random_state", "tol"]

def get_attr_names(self):
Expand Down
4 changes: 2 additions & 2 deletions python/cuml/cuml/ensemble/randomforest_common.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -383,8 +383,8 @@ class BaseRandomForestModel(Base):
return preds

@classmethod
def get_param_names(cls):
return super().get_param_names() + BaseRandomForestModel._param_names
def _get_param_names(cls):
return super()._get_param_names() + BaseRandomForestModel._param_names

def set_params(self, **params):
self.treelite_serialized_model = None
Expand Down
4 changes: 2 additions & 2 deletions python/cuml/cuml/experimental/linear_model/lars.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -398,7 +398,7 @@ class Lars(Base, RegressorMixin):
return preds

@classmethod
def get_param_names(cls):
return super().get_param_names() + \
def _get_param_names(cls):
return super()._get_param_names() + \
['copy_X', 'fit_intercept', 'fit_path', 'n_nonzero_coefs',
'normalize', 'precompute', 'eps']
4 changes: 2 additions & 2 deletions python/cuml/cuml/feature_extraction/_tfidf.py
Original file line number Diff line number Diff line change
Expand Up @@ -302,8 +302,8 @@ def idf_(self, value):
)

@classmethod
def get_param_names(cls):
return super().get_param_names() + [
def _get_param_names(cls):
return super()._get_param_names() + [
"norm",
"use_idf",
"smooth_idf",
Expand Down
13 changes: 7 additions & 6 deletions python/cuml/cuml/internals/base.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,7 @@ class Base(TagsMixin,
# inference logic goes here
@classmethod
def get_param_names(cls):
def _get_param_names(cls):
# return a list of hyperparam names supported by this algo
# stream and handle example:
Expand Down Expand Up @@ -271,7 +271,8 @@ class Base(TagsMixin,
output += ' <sk_model_ attribute used>'
return output

def get_param_names(self):
@classmethod
def _get_param_names(cls):
"""
Returns a list of hyperparameter names owned by this class. It is
expected that every child class overrides this method and appends its
Expand All @@ -283,12 +284,12 @@ class Base(TagsMixin,
def get_params(self, deep=True):
"""
Returns a dict of all params owned by this class. If the child class
has appropriately overridden the `get_param_names` method and does not
has appropriately overridden the `_get_param_names` method and does not
need anything other than what is there in this method, then it doesn't
have to override this method
"""
params = dict()
variables = self.get_param_names()
variables = self._get_param_names()
for key in variables:
var_value = getattr(self, key, None)
params[key] = var_value
Expand All @@ -298,12 +299,12 @@ class Base(TagsMixin,
"""
Accepts a dict of params and updates the corresponding ones owned by
this class. If the child class has appropriately overridden the
`get_param_names` method and does not need anything other than what is,
`_get_param_names` method and does not need anything other than what is,
there in this method, then it doesn't have to override this method
"""
if not params:
return self
variables = self.get_param_names()
variables = self._get_param_names()
for key, value in params.items():
if key not in variables:
raise ValueError("Bad param '%s' passed to set_params" % key)
Expand Down
4 changes: 2 additions & 2 deletions python/cuml/cuml/kernel_ridge/kernel_ridge.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -227,8 +227,8 @@ class KernelRidge(Base, RegressorMixin):
self.kernel_params = kernel_params

@classmethod
def get_param_names(cls):
return super().get_param_names() + [
def _get_param_names(cls):
return super()._get_param_names() + [
"alpha",
"kernel",
"gamma",
Expand Down
4 changes: 2 additions & 2 deletions python/cuml/cuml/linear_model/elastic_net.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -273,8 +273,8 @@ class ElasticNet(UniversalBase,
return self

@classmethod
def get_param_names(cls):
return super().get_param_names() + [
def _get_param_names(cls):
return super()._get_param_names() + [
"alpha",
"l1_ratio",
"fit_intercept",
Expand Down
4 changes: 2 additions & 2 deletions python/cuml/cuml/linear_model/lasso.py
Original file line number Diff line number Diff line change
Expand Up @@ -166,5 +166,5 @@ def __init__(
)

@classmethod
def get_param_names(cls):
return list(set(super().get_param_names()) - {"l1_ratio"})
def _get_param_names(cls):
return list(set(super()._get_param_names()) - {"l1_ratio"})
4 changes: 2 additions & 2 deletions python/cuml/cuml/linear_model/linear_regression.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -492,8 +492,8 @@ class LinearRegression(LinearPredictMixin,
return super()._predict(X, convert_dtype=convert_dtype)

@classmethod
def get_param_names(cls):
return super().get_param_names() + \
def _get_param_names(cls):
return super()._get_param_names() + \
['algorithm', 'fit_intercept', 'copy_X', 'normalize']

def get_attr_names(self):
Expand Down
Loading

0 comments on commit d46c31d

Please sign in to comment.