Skip to content

Commit

Permalink
ENH Make get_param_names a class method to match Scikit-learn
Browse files Browse the repository at this point in the history
  • Loading branch information
dantegd committed Oct 7, 2024
1 parent 82483ac commit d63e222
Show file tree
Hide file tree
Showing 21 changed files with 42 additions and 21 deletions.
3 changes: 2 additions & 1 deletion python/cuml/cuml/_thirdparty/sklearn/preprocessing/_data.py
Original file line number Diff line number Diff line change
Expand Up @@ -326,7 +326,8 @@ def _reset(self):
del self.data_max_
del self.data_range_

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

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

def get_param_names(self):
@classmethod
def get_param_names(cls):
return super().get_param_names() + [
"strategy",
"fill_value",
Expand Down
3 changes: 2 additions & 1 deletion python/cuml/cuml/dask/cluster/dbscan.py
Original file line number Diff line number Diff line change
Expand Up @@ -160,5 +160,6 @@ def fit_predict(self, X, out_dtype="int32"):
self.fit(X, out_dtype)
return self.get_combined_model().labels_

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

def get_param_names(self):
@classmethod
def get_param_names(cls):
return list(self.kwargs.keys())
3 changes: 2 additions & 1 deletion python/cuml/cuml/dask/decomposition/pca.py
Original file line number Diff line number Diff line change
Expand Up @@ -215,7 +215,8 @@ def inverse_transform(self, X, delayed=True):
"""
return self._inverse_transform(X, n_dims=2, delayed=delayed)

def get_param_names(self):
@classmethod
def get_param_names(cls):
return list(self.kwargs.keys())

@staticmethod
Expand Down
3 changes: 2 additions & 1 deletion python/cuml/cuml/dask/decomposition/tsvd.py
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,8 @@ def inverse_transform(self, X, delayed=True):
"""
return self._inverse_transform(X, n_dims=2, delayed=delayed)

def get_param_names(self):
@classmethod
def get_param_names(cls):
return list(self.kwargs.keys())

@staticmethod
Expand Down
3 changes: 2 additions & 1 deletion python/cuml/cuml/dask/linear_model/linear_regression.py
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,8 @@ def predict(self, X, delayed=True):
"""
return self._predict(X, delayed=delayed)

def get_param_names(self):
@classmethod
def get_param_names(cls):
return list(self.kwargs.keys())

@staticmethod
Expand Down
3 changes: 2 additions & 1 deletion python/cuml/cuml/dask/linear_model/ridge.py
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,8 @@ def predict(self, X, delayed=True):
"""
return self._predict(X, delayed=delayed)

def get_param_names(self):
@classmethod
def get_param_names(cls):
return list(self.kwargs.keys())

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

def get_param_names(self):
@classmethod
def get_param_names(cls):
# Skip super() since we dont pass any extra parameters in __init__
return Base.get_param_names(self) + self._hyperparams

Expand Down
3 changes: 2 additions & 1 deletion python/cuml/cuml/feature_extraction/_tfidf.py
Original file line number Diff line number Diff line change
Expand Up @@ -301,7 +301,8 @@ def idf_(self, value):
(value, 0), shape=(n_features, n_features), dtype=cp.float32
)

def get_param_names(self):
@classmethod
def get_param_names(cls):
return super().get_param_names() + [
"norm",
"use_idf",
Expand Down
3 changes: 2 additions & 1 deletion python/cuml/cuml/linear_model/lasso.py
Original file line number Diff line number Diff line change
Expand Up @@ -165,5 +165,6 @@ def __init__(
verbose=verbose,
)

def get_param_names(self):
@classmethod
def get_param_names(cls):
return list(set(super().get_param_names()) - {"l1_ratio"})
3 changes: 2 additions & 1 deletion python/cuml/cuml/multiclass/multiclass.py
Original file line number Diff line number Diff line change
Expand Up @@ -192,7 +192,8 @@ def decision_function(self, X) -> CumlArray:
with cuml.internals.exit_internal_api():
return self.multiclass_estimator.decision_function(X)

def get_param_names(self):
@classmethod
def get_param_names(cls):
return super().get_param_names() + ["estimator", "strategy"]


Expand Down
3 changes: 2 additions & 1 deletion python/cuml/cuml/naive_bayes/naive_bayes.py
Original file line number Diff line number Diff line change
Expand Up @@ -724,7 +724,8 @@ def _joint_log_likelihood(self, X):

return cp.array(joint_log_likelihood).T

def get_param_names(self):
@classmethod
def get_param_names(cls):
return super().get_param_names() + ["priors", "var_smoothing"]


Expand Down
3 changes: 2 additions & 1 deletion python/cuml/cuml/neighbors/kernel_density.py
Original file line number Diff line number Diff line change
Expand Up @@ -225,7 +225,8 @@ def __init__(
if kernel not in VALID_KERNELS:
raise ValueError("invalid kernel: '{0}'".format(kernel))

def get_param_names(self):
@classmethod
def get_param_names(cls):
return super().get_param_names() + [
"bandwidth",
"kernel",
Expand Down
3 changes: 2 additions & 1 deletion python/cuml/cuml/preprocessing/LabelEncoder.py
Original file line number Diff line number Diff line change
Expand Up @@ -284,7 +284,8 @@ def inverse_transform(self, y: cudf.Series) -> cudf.Series:

return res

def get_param_names(self):
@classmethod
def get_param_names(cls):
return super().get_param_names() + [
"handle_unknown",
]
3 changes: 2 additions & 1 deletion python/cuml/cuml/preprocessing/TargetEncoder.py
Original file line number Diff line number Diff line change
Expand Up @@ -508,7 +508,8 @@ def _get_output_type(self, x):
return "numpy"
return "cupy"

def get_param_names(self):
@classmethod
def get_param_names(cls):
return [
"n_folds",
"smooth",
Expand Down
3 changes: 2 additions & 1 deletion python/cuml/cuml/preprocessing/encoders.py
Original file line number Diff line number Diff line change
Expand Up @@ -602,7 +602,8 @@ def get_feature_names(self, input_features=None):

return np.array(feature_names, dtype=object)

def get_param_names(self):
@classmethod
def get_param_names(cls):
return super().get_param_names() + [
"categories",
"drop",
Expand Down
3 changes: 2 additions & 1 deletion python/cuml/cuml/preprocessing/label.py
Original file line number Diff line number Diff line change
Expand Up @@ -287,7 +287,8 @@ def inverse_transform(self, y, threshold=None) -> CumlArray:

return invert_labels(y_mapped, self.classes_)

def get_param_names(self):
@classmethod
def get_param_names(cls):
return super().get_param_names() + [
"neg_label",
"pos_label",
Expand Down
3 changes: 2 additions & 1 deletion python/cuml/cuml/svm/linear_svc.py
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,8 @@ def loss(self, loss: str):
)
self.__loss = loss

def get_param_names(self):
@classmethod
def get_param_names(cls):
return list(
{
"handle",
Expand Down
3 changes: 2 additions & 1 deletion python/cuml/cuml/svm/linear_svr.py
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,8 @@ def loss(self, loss: str):
)
self.__loss = loss

def get_param_names(self):
@classmethod
def get_param_names(cls):
return list(
{
"handle",
Expand Down

0 comments on commit d63e222

Please sign in to comment.