diff --git a/python/cuml/cuml/_thirdparty/sklearn/preprocessing/_data.py b/python/cuml/cuml/_thirdparty/sklearn/preprocessing/_data.py index b510ff97ac..9d4cb89bba 100644 --- a/python/cuml/cuml/_thirdparty/sklearn/preprocessing/_data.py +++ b/python/cuml/cuml/_thirdparty/sklearn/preprocessing/_data.py @@ -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" ] @@ -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" @@ -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" ] @@ -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", @@ -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", @@ -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", @@ -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" diff --git a/python/cuml/cuml/_thirdparty/sklearn/preprocessing/_discretization.py b/python/cuml/cuml/_thirdparty/sklearn/preprocessing/_discretization.py index 5bafc40677..6bf6390fcf 100644 --- a/python/cuml/cuml/_thirdparty/sklearn/preprocessing/_discretization.py +++ b/python/cuml/cuml/_thirdparty/sklearn/preprocessing/_discretization.py @@ -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" diff --git a/python/cuml/cuml/_thirdparty/sklearn/preprocessing/_imputation.py b/python/cuml/cuml/_thirdparty/sklearn/preprocessing/_imputation.py index 8074ee4b54..2be0c81ff0 100644 --- a/python/cuml/cuml/_thirdparty/sklearn/preprocessing/_imputation.py +++ b/python/cuml/cuml/_thirdparty/sklearn/preprocessing/_imputation.py @@ -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", @@ -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", diff --git a/python/cuml/cuml/cluster/agglomerative.pyx b/python/cuml/cuml/cluster/agglomerative.pyx index cc2fd1021d..790db73362 100644 --- a/python/cuml/cuml/cluster/agglomerative.pyx +++ b/python/cuml/cuml/cluster/agglomerative.pyx @@ -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", diff --git a/python/cuml/cuml/cluster/dbscan.pyx b/python/cuml/cuml/cluster/dbscan.pyx index 139be36829..9480ccccf6 100644 --- a/python/cuml/cuml/cluster/dbscan.pyx +++ b/python/cuml/cuml/cluster/dbscan.pyx @@ -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", diff --git a/python/cuml/cuml/cluster/hdbscan/hdbscan.pyx b/python/cuml/cuml/cluster/hdbscan/hdbscan.pyx index e27f54cc85..0078b145c7 100644 --- a/python/cuml/cuml/cluster/hdbscan/hdbscan.pyx +++ b/python/cuml/cuml/cluster/hdbscan/hdbscan.pyx @@ -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", diff --git a/python/cuml/cuml/cluster/kmeans.pyx b/python/cuml/cuml/cluster/kmeans.pyx index a2de8da9a3..9ba1cb710a 100644 --- a/python/cuml/cuml/cluster/kmeans.pyx +++ b/python/cuml/cuml/cluster/kmeans.pyx @@ -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"] diff --git a/python/cuml/cuml/dask/cluster/dbscan.py b/python/cuml/cuml/dask/cluster/dbscan.py index 51c22abca6..b71e34682a 100644 --- a/python/cuml/cuml/dask/cluster/dbscan.py +++ b/python/cuml/cuml/dask/cluster/dbscan.py @@ -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. @@ -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()) diff --git a/python/cuml/cuml/dask/cluster/kmeans.py b/python/cuml/cuml/dask/cluster/kmeans.py index b014dc4fb2..3dfeced41f 100644 --- a/python/cuml/cuml/dask/cluster/kmeans.py +++ b/python/cuml/cuml/dask/cluster/kmeans.py @@ -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()) diff --git a/python/cuml/cuml/dask/decomposition/pca.py b/python/cuml/cuml/dask/decomposition/pca.py index 896eb58606..8cebb2764f 100644 --- a/python/cuml/cuml/dask/decomposition/pca.py +++ b/python/cuml/cuml/dask/decomposition/pca.py @@ -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. @@ -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 diff --git a/python/cuml/cuml/dask/decomposition/tsvd.py b/python/cuml/cuml/dask/decomposition/tsvd.py index d76d08bda2..67392b7555 100644 --- a/python/cuml/cuml/dask/decomposition/tsvd.py +++ b/python/cuml/cuml/dask/decomposition/tsvd.py @@ -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. @@ -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 diff --git a/python/cuml/cuml/dask/linear_model/linear_regression.py b/python/cuml/cuml/dask/linear_model/linear_regression.py index f8c5dfd7b0..98ffba672d 100644 --- a/python/cuml/cuml/dask/linear_model/linear_regression.py +++ b/python/cuml/cuml/dask/linear_model/linear_regression.py @@ -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. @@ -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 diff --git a/python/cuml/cuml/dask/linear_model/ridge.py b/python/cuml/cuml/dask/linear_model/ridge.py index 32db990979..2830f3ce38 100644 --- a/python/cuml/cuml/dask/linear_model/ridge.py +++ b/python/cuml/cuml/dask/linear_model/ridge.py @@ -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. @@ -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 diff --git a/python/cuml/cuml/decomposition/incremental_pca.py b/python/cuml/cuml/decomposition/incremental_pca.py index 70663ceeb8..925219d0bc 100644 --- a/python/cuml/cuml/decomposition/incremental_pca.py +++ b/python/cuml/cuml/decomposition/incremental_pca.py @@ -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", diff --git a/python/cuml/cuml/decomposition/pca.pyx b/python/cuml/cuml/decomposition/pca.pyx index 08f8f2ec6e..9433f724b9 100644 --- a/python/cuml/cuml/decomposition/pca.pyx +++ b/python/cuml/cuml/decomposition/pca.pyx @@ -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"] diff --git a/python/cuml/cuml/decomposition/tsvd.pyx b/python/cuml/cuml/decomposition/tsvd.pyx index dd8dfe0282..55caa84c9b 100644 --- a/python/cuml/cuml/decomposition/tsvd.pyx +++ b/python/cuml/cuml/decomposition/tsvd.pyx @@ -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): diff --git a/python/cuml/cuml/ensemble/randomforest_common.pyx b/python/cuml/cuml/ensemble/randomforest_common.pyx index a6dd918879..38c15eaca2 100644 --- a/python/cuml/cuml/ensemble/randomforest_common.pyx +++ b/python/cuml/cuml/ensemble/randomforest_common.pyx @@ -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 diff --git a/python/cuml/cuml/experimental/linear_model/lars.pyx b/python/cuml/cuml/experimental/linear_model/lars.pyx index 6a81b0bc23..4a836740c7 100644 --- a/python/cuml/cuml/experimental/linear_model/lars.pyx +++ b/python/cuml/cuml/experimental/linear_model/lars.pyx @@ -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'] diff --git a/python/cuml/cuml/feature_extraction/_tfidf.py b/python/cuml/cuml/feature_extraction/_tfidf.py index c4d7a5fd1b..2cf5974119 100644 --- a/python/cuml/cuml/feature_extraction/_tfidf.py +++ b/python/cuml/cuml/feature_extraction/_tfidf.py @@ -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", diff --git a/python/cuml/cuml/internals/base.pyx b/python/cuml/cuml/internals/base.pyx index ad6f761799..9813acbba4 100644 --- a/python/cuml/cuml/internals/base.pyx +++ b/python/cuml/cuml/internals/base.pyx @@ -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: @@ -271,7 +271,8 @@ class Base(TagsMixin, output += ' ' 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 @@ -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 @@ -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) diff --git a/python/cuml/cuml/kernel_ridge/kernel_ridge.pyx b/python/cuml/cuml/kernel_ridge/kernel_ridge.pyx index 98d1bd98de..6063f27c99 100644 --- a/python/cuml/cuml/kernel_ridge/kernel_ridge.pyx +++ b/python/cuml/cuml/kernel_ridge/kernel_ridge.pyx @@ -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", diff --git a/python/cuml/cuml/linear_model/elastic_net.pyx b/python/cuml/cuml/linear_model/elastic_net.pyx index cae04051e1..a8e6b75a3d 100644 --- a/python/cuml/cuml/linear_model/elastic_net.pyx +++ b/python/cuml/cuml/linear_model/elastic_net.pyx @@ -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", diff --git a/python/cuml/cuml/linear_model/lasso.py b/python/cuml/cuml/linear_model/lasso.py index 9b0aafa5ef..65a30be791 100644 --- a/python/cuml/cuml/linear_model/lasso.py +++ b/python/cuml/cuml/linear_model/lasso.py @@ -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"}) diff --git a/python/cuml/cuml/linear_model/linear_regression.pyx b/python/cuml/cuml/linear_model/linear_regression.pyx index ba38ba1711..35a73c111f 100644 --- a/python/cuml/cuml/linear_model/linear_regression.pyx +++ b/python/cuml/cuml/linear_model/linear_regression.pyx @@ -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): diff --git a/python/cuml/cuml/linear_model/logistic_regression.pyx b/python/cuml/cuml/linear_model/logistic_regression.pyx index 1d08d2f102..aa5283fef7 100644 --- a/python/cuml/cuml/linear_model/logistic_regression.pyx +++ b/python/cuml/cuml/linear_model/logistic_regression.pyx @@ -535,8 +535,8 @@ class LogisticRegression(UniversalBase, self.solver_model.intercept_ = value @classmethod - def get_param_names(cls): - return super().get_param_names() + [ + def _get_param_names(cls): + return super()._get_param_names() + [ "penalty", "tol", "C", diff --git a/python/cuml/cuml/linear_model/mbsgd_classifier.pyx b/python/cuml/cuml/linear_model/mbsgd_classifier.pyx index 6f13288f8d..3a7fcc772e 100644 --- a/python/cuml/cuml/linear_model/mbsgd_classifier.pyx +++ b/python/cuml/cuml/linear_model/mbsgd_classifier.pyx @@ -214,8 +214,8 @@ class MBSGDClassifier(Base, return self @classmethod - def get_param_names(cls): - return super().get_param_names() + [ + def _get_param_names(cls): + return super()._get_param_names() + [ "loss", "penalty", "alpha", diff --git a/python/cuml/cuml/linear_model/mbsgd_regressor.pyx b/python/cuml/cuml/linear_model/mbsgd_regressor.pyx index 1a2a4b52b8..a738eb6d74 100644 --- a/python/cuml/cuml/linear_model/mbsgd_regressor.pyx +++ b/python/cuml/cuml/linear_model/mbsgd_regressor.pyx @@ -208,8 +208,8 @@ class MBSGDRegressor(Base, return self @classmethod - def get_param_names(cls): - return super().get_param_names() + [ + def _get_param_names(cls): + return super()._get_param_names() + [ "loss", "penalty", "alpha", diff --git a/python/cuml/cuml/linear_model/ridge.pyx b/python/cuml/cuml/linear_model/ridge.pyx index 92a94ddf9e..ae84f1002a 100644 --- a/python/cuml/cuml/linear_model/ridge.pyx +++ b/python/cuml/cuml/linear_model/ridge.pyx @@ -357,8 +357,8 @@ class Ridge(UniversalBase, return self @classmethod - def get_param_names(cls): - return super().get_param_names() + \ + def _get_param_names(cls): + return super()._get_param_names() + \ ['solver', 'fit_intercept', 'normalize', 'alpha'] def get_attr_names(self): diff --git a/python/cuml/cuml/manifold/t_sne.pyx b/python/cuml/cuml/manifold/t_sne.pyx index 7d608167a1..11ade2ffe2 100644 --- a/python/cuml/cuml/manifold/t_sne.pyx +++ b/python/cuml/cuml/manifold/t_sne.pyx @@ -691,8 +691,8 @@ class TSNE(UniversalBase, return state @classmethod - def get_param_names(cls): - return super().get_param_names() + [ + def _get_param_names(cls): + return super()._get_param_names() + [ "n_components", "perplexity", "early_exaggeration", diff --git a/python/cuml/cuml/manifold/umap.pyx b/python/cuml/cuml/manifold/umap.pyx index dc5f037467..c873461a95 100644 --- a/python/cuml/cuml/manifold/umap.pyx +++ b/python/cuml/cuml/manifold/umap.pyx @@ -910,8 +910,8 @@ class UMAP(UniversalBase, super().gpu_to_cpu() @classmethod - def get_param_names(cls): - return super().get_param_names() + [ + def _get_param_names(cls): + return super()._get_param_names() + [ "n_neighbors", "n_components", "n_epochs", diff --git a/python/cuml/cuml/multiclass/multiclass.py b/python/cuml/cuml/multiclass/multiclass.py index 45671a275b..61a79e1d31 100644 --- a/python/cuml/cuml/multiclass/multiclass.py +++ b/python/cuml/cuml/multiclass/multiclass.py @@ -193,8 +193,8 @@ def decision_function(self, X) -> CumlArray: return self.multiclass_estimator.decision_function(X) @classmethod - def get_param_names(cls): - return super().get_param_names() + ["estimator", "strategy"] + def _get_param_names(cls): + return super()._get_param_names() + ["estimator", "strategy"] class OneVsRestClassifier(MulticlassClassifier): @@ -266,8 +266,9 @@ def __init__( strategy="ovr", ) - def get_param_names(self): - param_names = super().get_param_names() + @classmethod + def _get_param_names(cls): + param_names = super()._get_param_names() param_names.remove("strategy") return param_names @@ -340,7 +341,8 @@ def __init__( strategy="ovo", ) - def get_param_names(self): - param_names = super().get_param_names() + @classmethod + def _get_param_names(cls): + param_names = super()._get_param_names() param_names.remove("strategy") return param_names diff --git a/python/cuml/cuml/naive_bayes/naive_bayes.py b/python/cuml/cuml/naive_bayes/naive_bayes.py index b393090ea6..701f88862e 100644 --- a/python/cuml/cuml/naive_bayes/naive_bayes.py +++ b/python/cuml/cuml/naive_bayes/naive_bayes.py @@ -725,8 +725,8 @@ def _joint_log_likelihood(self, X): return cp.array(joint_log_likelihood).T @classmethod - def get_param_names(cls): - return super().get_param_names() + ["priors", "var_smoothing"] + def _get_param_names(cls): + return super()._get_param_names() + ["priors", "var_smoothing"] class _BaseDiscreteNB(_BaseNB): @@ -1059,8 +1059,9 @@ def _count_sparse( self.feature_count_ = self.feature_count_ + counts self.class_count_ = self.class_count_ + class_c - def get_param_names(self): - return super().get_param_names() + [ + @classmethod + def _get_param_names(cls): + return super()._get_param_names() + [ "alpha", "fit_prior", "class_prior", @@ -1374,8 +1375,9 @@ def _update_feature_log_prob(self, alpha): smoothed_cc.reshape(-1, 1) ) - def get_param_names(self): - return super().get_param_names() + ["binarize"] + @classmethod + def _get_param_names(cls): + return super()._get_param_names() + ["binarize"] class ComplementNB(_BaseDiscreteNB): @@ -1537,8 +1539,9 @@ def _update_feature_log_prob(self, alpha): feature_log_prob = -logged self.feature_log_prob_ = feature_log_prob - def get_param_names(self): - return super().get_param_names() + ["norm"] + @classmethod + def _get_param_names(cls): + return super()._get_param_names() + ["norm"] class CategoricalNB(_BaseDiscreteNB): diff --git a/python/cuml/cuml/neighbors/kernel_density.py b/python/cuml/cuml/neighbors/kernel_density.py index ceb88e91b2..3af2107995 100644 --- a/python/cuml/cuml/neighbors/kernel_density.py +++ b/python/cuml/cuml/neighbors/kernel_density.py @@ -226,8 +226,8 @@ def __init__( raise ValueError("invalid kernel: '{0}'".format(kernel)) @classmethod - def get_param_names(cls): - return super().get_param_names() + [ + def _get_param_names(cls): + return super()._get_param_names() + [ "bandwidth", "kernel", "metric", diff --git a/python/cuml/cuml/neighbors/kneighbors_classifier.pyx b/python/cuml/cuml/neighbors/kneighbors_classifier.pyx index 0751bf4c5c..ed72909203 100644 --- a/python/cuml/cuml/neighbors/kneighbors_classifier.pyx +++ b/python/cuml/cuml/neighbors/kneighbors_classifier.pyx @@ -299,5 +299,5 @@ class KNeighborsClassifier(ClassifierMixin, if len(final_classes) == 1 else tuple(final_classes) @classmethod - def get_param_names(cls): - return super().get_param_names() + ["weights"] + def _get_param_names(cls): + return super()._get_param_names() + ["weights"] diff --git a/python/cuml/cuml/neighbors/kneighbors_regressor.pyx b/python/cuml/cuml/neighbors/kneighbors_regressor.pyx index c9ec8f1b93..75fcfce5c6 100644 --- a/python/cuml/cuml/neighbors/kneighbors_regressor.pyx +++ b/python/cuml/cuml/neighbors/kneighbors_regressor.pyx @@ -235,5 +235,5 @@ class KNeighborsRegressor(RegressorMixin, return results @classmethod - def get_param_names(cls): - return super().get_param_names() + ["weights"] + def _get_param_names(cls): + return super()._get_param_names() + ["weights"] diff --git a/python/cuml/cuml/neighbors/nearest_neighbors.pyx b/python/cuml/cuml/neighbors/nearest_neighbors.pyx index 0c0ebb09a3..202d65ca8b 100644 --- a/python/cuml/cuml/neighbors/nearest_neighbors.pyx +++ b/python/cuml/cuml/neighbors/nearest_neighbors.pyx @@ -421,8 +421,8 @@ class NearestNeighbors(UniversalBase, return self @classmethod - def get_param_names(cls): - return super().get_param_names() + \ + def _get_param_names(cls): + return super()._get_param_names() + \ ["n_neighbors", "algorithm", "metric", "p", "metric_params", "algo_params", "n_jobs"] diff --git a/python/cuml/cuml/preprocessing/LabelEncoder.py b/python/cuml/cuml/preprocessing/LabelEncoder.py index ba6c1975ab..960935e61f 100644 --- a/python/cuml/cuml/preprocessing/LabelEncoder.py +++ b/python/cuml/cuml/preprocessing/LabelEncoder.py @@ -285,7 +285,7 @@ def inverse_transform(self, y: cudf.Series) -> cudf.Series: return res @classmethod - def get_param_names(cls): - return super().get_param_names() + [ + def _get_param_names(cls): + return super()._get_param_names() + [ "handle_unknown", ] diff --git a/python/cuml/cuml/preprocessing/TargetEncoder.py b/python/cuml/cuml/preprocessing/TargetEncoder.py index d0df2fbf66..a6e7524cf0 100644 --- a/python/cuml/cuml/preprocessing/TargetEncoder.py +++ b/python/cuml/cuml/preprocessing/TargetEncoder.py @@ -509,7 +509,7 @@ def _get_output_type(self, x): return "cupy" @classmethod - def get_param_names(cls): + def _get_param_names(cls): return [ "n_folds", "smooth", @@ -522,7 +522,7 @@ def get_params(self, deep=False): Returns a dict of all params owned by this class. """ 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 diff --git a/python/cuml/cuml/preprocessing/encoders.py b/python/cuml/cuml/preprocessing/encoders.py index 7874aaf4dc..943f3c294c 100644 --- a/python/cuml/cuml/preprocessing/encoders.py +++ b/python/cuml/cuml/preprocessing/encoders.py @@ -603,8 +603,8 @@ def get_feature_names(self, input_features=None): return np.array(feature_names, dtype=object) @classmethod - def get_param_names(cls): - return super().get_param_names() + [ + def _get_param_names(cls): + return super()._get_param_names() + [ "categories", "drop", "sparse", @@ -768,8 +768,9 @@ def inverse_transform(self, X): r = DataFrame(result) return _get_output(self.output_type, self.input_type, r, self.dtype) - def get_param_names(self): - return super().get_param_names() + [ + @classmethod + def _get_param_names(cls): + return super()._get_param_names() + [ "categories", "dtype", "handle_unknown", diff --git a/python/cuml/cuml/preprocessing/label.py b/python/cuml/cuml/preprocessing/label.py index 742383188d..20aac36ac8 100644 --- a/python/cuml/cuml/preprocessing/label.py +++ b/python/cuml/cuml/preprocessing/label.py @@ -288,8 +288,8 @@ def inverse_transform(self, y, threshold=None) -> CumlArray: return invert_labels(y_mapped, self.classes_) @classmethod - def get_param_names(cls): - return super().get_param_names() + [ + def _get_param_names(cls): + return super()._get_param_names() + [ "neg_label", "pos_label", "sparse_output", diff --git a/python/cuml/cuml/random_projection/random_projection.pyx b/python/cuml/cuml/random_projection/random_projection.pyx index 18c61b606e..81811a4849 100644 --- a/python/cuml/cuml/random_projection/random_projection.pyx +++ b/python/cuml/cuml/random_projection/random_projection.pyx @@ -446,8 +446,8 @@ class GaussianRandomProjection(Base, random_state=random_state) @classmethod - def get_param_names(cls): - return Base.get_param_names() + [ + def _get_param_names(cls): + return Base._get_param_names() + [ "n_components", "eps", "random_state" @@ -590,8 +590,9 @@ class SparseRandomProjection(Base, dense_output=dense_output, random_state=random_state) - def get_param_names(self): - return Base.get_param_names(self) + [ + @classmethod + def _get_param_names(cls): + return Base._get_param_names() + [ "n_components", "density", "eps", diff --git a/python/cuml/cuml/solvers/cd.pyx b/python/cuml/cuml/solvers/cd.pyx index a6874f7025..ba6c5ac12b 100644 --- a/python/cuml/cuml/solvers/cd.pyx +++ b/python/cuml/cuml/solvers/cd.pyx @@ -360,8 +360,8 @@ class CD(Base, return preds @classmethod - def get_param_names(cls): - return super().get_param_names() + [ + def _get_param_names(cls): + return super()._get_param_names() + [ "loss", "alpha", "l1_ratio", diff --git a/python/cuml/cuml/solvers/qn.pyx b/python/cuml/cuml/solvers/qn.pyx index 6d04242ee4..72f51c25b2 100644 --- a/python/cuml/cuml/solvers/qn.pyx +++ b/python/cuml/cuml/solvers/qn.pyx @@ -171,7 +171,7 @@ IF GPUBUILD == 1: return x def __init__(self, **kwargs): - allowed_keys = set(self.get_param_names()) + allowed_keys = set(self._get_param_names()) for key, val in kwargs.items(): if key in allowed_keys: setattr(self, key, val) @@ -183,7 +183,7 @@ IF GPUBUILD == 1: self.params[key] = val @classmethod - def get_param_names(cls): + def _get_param_names(cls): return cls.get_param_defaults().keys() def __str__(self): @@ -950,8 +950,9 @@ class QN(Base, else: self.intercept_ = CumlArray.zeros(shape=_num_classes) - def get_param_names(self): - return super().get_param_names() + \ + @classmethod + def _get_param_names(cls): + return super()._get_param_names() + \ ['loss', 'fit_intercept', 'l1_strength', 'l2_strength', 'max_iter', 'tol', 'linesearch_max_iter', 'lbfgs_memory', 'warm_start', 'delta', 'penalty_normalized'] diff --git a/python/cuml/cuml/solvers/sgd.pyx b/python/cuml/cuml/solvers/sgd.pyx index 6e10fab9a8..b6c452cc30 100644 --- a/python/cuml/cuml/solvers/sgd.pyx +++ b/python/cuml/cuml/solvers/sgd.pyx @@ -503,8 +503,8 @@ class SGD(Base, return preds @classmethod - def get_param_names(cls): - return super().get_param_names() + [ + def _get_param_names(cls): + return super()._get_param_names() + [ "loss", "penalty", "alpha", diff --git a/python/cuml/cuml/svm/linear.pyx b/python/cuml/cuml/svm/linear.pyx index ff84b33d5b..c5ff47cde9 100644 --- a/python/cuml/cuml/svm/linear.pyx +++ b/python/cuml/cuml/svm/linear.pyx @@ -146,13 +146,13 @@ cdef class LSVMPWrapper_: self.params[key] = val def __init__(self, **kwargs): - allowed_keys = set(self.get_param_names()) + allowed_keys = set(self._get_param_names()) for key, val in kwargs.items(): if key in allowed_keys: setattr(self, key, val) @classmethod - def get_param_names(cls): + def _get_param_names(cls): cdef LinearSVMParams ps return ps.keys() @@ -213,7 +213,7 @@ def __add_prop(prop_name): )) -for prop_name in LSVMPWrapper().get_param_names(): +for prop_name in LSVMPWrapper()._get_param_names(): if not hasattr(LSVMPWrapper, prop_name): __add_prop(prop_name) del __add_prop @@ -595,7 +595,7 @@ class LinearSVM(Base, metaclass=WithReexportedParams): return state def __init__(self, **kwargs): - # `tol` is special in that it's not present in get_param_names, + # `tol` is special in that it's not present in _get_param_names, # so having a special logic here does not affect pickling/cloning. tol = kwargs.pop('tol', None) if tol is not None: @@ -605,8 +605,8 @@ class LinearSVM(Base, metaclass=WithReexportedParams): self.change_tol = tol * default_to_ratio # All arguments are optional (they have defaults), # yet we need to check for unused arguments - allowed_keys = set(self.get_param_names()) - super_keys = set(super().get_param_names()) + allowed_keys = set(self._get_param_names()) + super_keys = set(super()._get_param_names()) remaining_kwargs = {} for key, val in kwargs.items(): if key not in allowed_keys or key in super_keys: diff --git a/python/cuml/cuml/svm/linear_svc.py b/python/cuml/cuml/svm/linear_svc.py index bb53ecb633..40df6f0808 100644 --- a/python/cuml/cuml/svm/linear_svc.py +++ b/python/cuml/cuml/svm/linear_svc.py @@ -174,7 +174,7 @@ def loss(self, loss: str): self.__loss = loss @classmethod - def get_param_names(cls): + def _get_param_names(cls): return list( { "handle", @@ -192,7 +192,7 @@ def get_param_names(cls): "grad_tol", "change_tol", "multi_class", - }.union(super().get_param_names()) + }.union(super()._get_param_names()) ) def fit(self, X, y, sample_weight=None, convert_dtype=True) -> "LinearSVM": diff --git a/python/cuml/cuml/svm/linear_svr.py b/python/cuml/cuml/svm/linear_svr.py index 93c2c13389..3f9b8040d9 100644 --- a/python/cuml/cuml/svm/linear_svr.py +++ b/python/cuml/cuml/svm/linear_svr.py @@ -153,7 +153,7 @@ def loss(self, loss: str): self.__loss = loss @classmethod - def get_param_names(cls): + def _get_param_names(cls): return list( { "handle", @@ -169,5 +169,5 @@ def get_param_names(cls): "grad_tol", "change_tol", "epsilon", - }.union(super().get_param_names()) + }.union(super()._get_param_names()) ) diff --git a/python/cuml/cuml/svm/svc.pyx b/python/cuml/cuml/svm/svc.pyx index d62d4729b0..290f5bc2a2 100644 --- a/python/cuml/cuml/svm/svc.pyx +++ b/python/cuml/cuml/svm/svc.pyx @@ -703,8 +703,8 @@ class SVC(SVMBase, return super().predict(X, False) @classmethod - def get_param_names(cls): - params = super().get_param_names() + \ + def _get_param_names(cls): + params = super()._get_param_names() + \ ["probability", "random_state", "class_weight", "multiclass_strategy"] diff --git a/python/cuml/cuml/svm/svm_base.pyx b/python/cuml/cuml/svm/svm_base.pyx index bd4f5c5681..9b68147f2b 100644 --- a/python/cuml/cuml/svm/svm_base.pyx +++ b/python/cuml/cuml/svm/svm_base.pyx @@ -662,8 +662,8 @@ class SVMBase(Base, return preds @classmethod - def get_param_names(cls): - return super().get_param_names() + [ + def _get_param_names(cls): + return super()._get_param_names() + [ "C", "kernel", "degree", diff --git a/python/cuml/cuml/tests/explainer/test_explainer_common.py b/python/cuml/cuml/tests/explainer/test_explainer_common.py index 5ee4e5f52b..659f8c365e 100644 --- a/python/cuml/cuml/tests/explainer/test_explainer_common.py +++ b/python/cuml/cuml/tests/explainer/test_explainer_common.py @@ -1,5 +1,5 @@ # -# 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. @@ -141,7 +141,7 @@ def test_get_tag_from_model_func(model): for tag in _default_tags: res = get_tag_from_model_func( - func=mod.get_param_names, tag=tag, default="FFF" + func=mod._get_param_names, tag=tag, default="FFF" ) if tag != "preferred_input_order": @@ -153,7 +153,7 @@ def test_get_handle_from_cuml_model_func(model): mod = create_dummy_model(model) handle = get_handle_from_cuml_model_func( - mod.get_param_names, create_new=True + mod._get_param_names, create_new=True ) assert isinstance(handle, Handle) diff --git a/python/cuml/cuml/tests/test_base.py b/python/cuml/cuml/tests/test_base.py index dc70c8cf22..0cd01acabb 100644 --- a/python/cuml/cuml/tests/test_base.py +++ b/python/cuml/cuml/tests/test_base.py @@ -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. @@ -36,7 +36,7 @@ def test_base_class_usage(): # Ensure base class returns the 3 main properties needed by all classes base = cuml.Base() base.handle.sync() - base_params = base.get_param_names() + base_params = base._get_param_names() assert "handle" in base_params assert "verbose" in base_params @@ -160,10 +160,10 @@ def get_param_doc(param_doc_obj, name: str): @pytest.mark.parametrize("child_class", list(all_base_children.keys())) # ignore ColumnTransformer init warning @pytest.mark.filterwarnings("ignore:Transformers are required") -def test_base_children_get_param_names(child_class: str): +def test_base_children__get_param_names(child_class: str): """ This test ensures that the arguments in `Base.__init__` are available in - all derived classes `get_param_names` + all derived classes `_get_param_names` """ klass = all_base_children[child_class] @@ -183,9 +183,9 @@ def test_base_children_get_param_names(child_class: str): # Create an instance obj = klass(*bound.args, **bound.kwargs) - param_names = obj.get_param_names() + param_names = obj._get_param_names() - # Now ensure the base parameters are included in get_param_names + # Now ensure the base parameters are included in _get_param_names for name, param in sig.parameters.items(): if param.name == "output_mem_type": continue # TODO(wphicks): Add this to all algos diff --git a/python/cuml/cuml/tsa/arima.pyx b/python/cuml/cuml/tsa/arima.pyx index e93f871cb2..3513362013 100644 --- a/python/cuml/cuml/tsa/arima.pyx +++ b/python/cuml/cuml/tsa/arima.pyx @@ -578,13 +578,10 @@ class ARIMA(Base): setattr(self, "{}_".format(param_name), array) @classmethod - def get_param_names(cls): - raise NotImplementedError - - def get_param_names(self): + def _get_param_names(cls): """ .. warning:: ARIMA is unable to be cloned at this time. - The methods: `get_param_names()`, `get_params` and + The methods: `_get_param_names()`, `get_params` and `set_params` will raise ``NotImplementedError`` """ raise NotImplementedError("ARIMA is unable to be cloned via " @@ -593,7 +590,7 @@ class ARIMA(Base): def get_params(self, deep=True): """ .. warning:: ARIMA is unable to be cloned at this time. - The methods: `get_param_names()`, `get_params` and + The methods: `_get_param_names()`, `get_params` and `set_params` will raise ``NotImplementedError`` """ raise NotImplementedError("ARIMA is unable to be cloned via " @@ -602,7 +599,7 @@ class ARIMA(Base): def set_params(self, **params): """ .. warning:: ARIMA is unable to be cloned at this time. - The methods: `get_param_names()`, `get_params` and + The methods: `_get_param_names()`, `get_params` and `set_params` will raise ``NotImplementedError`` """ raise NotImplementedError("ARIMA is unable to be cloned via " diff --git a/python/cuml/cuml/tsa/holtwinters.pyx b/python/cuml/cuml/tsa/holtwinters.pyx index f22f363051..685e92fdea 100644 --- a/python/cuml/cuml/tsa/holtwinters.pyx +++ b/python/cuml/cuml/tsa/holtwinters.pyx @@ -577,8 +577,8 @@ class ExponentialSmoothing(Base): raise ValueError("Fit() the model to get season values") @classmethod - def get_param_names(cls): - return super().get_param_names() + [ + def _get_param_names(cls): + return super()._get_param_names() + [ "endog", "seasonal", "seasonal_periods", diff --git a/wiki/python/ESTIMATOR_GUIDE.md b/wiki/python/ESTIMATOR_GUIDE.md index a387df111d..84528608cd 100644 --- a/wiki/python/ESTIMATOR_GUIDE.md +++ b/wiki/python/ESTIMATOR_GUIDE.md @@ -15,7 +15,7 @@ This guide is meant to help developers follow the correct patterns when creating - [Returning Arrays](#returning-arrays) - [Estimator Design](#estimator-design) - [Initialization](#initialization) - - [Implementing `get_param_names()`](#implementing-get_param_names) + - [Implementing `_get_param_names()`](#implementing-_get_param_names) - [Estimator Tags and cuML Specific Tags](#estimator-tags-and-cuml-specific-tags) - [Estimator Array-Like Attributes](#estimator-array-like-attributes) - [Estimator Methods](#estimator-methods) @@ -77,10 +77,11 @@ At a high level, all cuML Estimators must: def predict(self, X) -> CumlArray: ... ``` -6. Implement `get_param_names()` including values returned by `super().get_param_names()` +6. Implement `_get_param_names()` including values returned by `super()._get_param_names()` ```python - def get_param_names(self): - return super().get_param_names() + [ + @classmethod + def _get_param_names(cls): + return super()._get_param_names() + [ "eps", "min_samples", ] @@ -254,19 +255,20 @@ def __init__(self, my_option="option1"): This will break cloning since the value of `self.my_option` is not a valid input to `__init__`. Instead, `my_option` should be saved as an attribute as-is. -### Implementing `get_param_names()` +### Implementing `_get_param_names()` -To support cloning, estimators need to implement the function `get_param_names()`. The returned value should be a list of strings of all estimator attributes that are necessary to duplicate the estimator. This method is used in `Base.get_params()` which will collect the collect the estimator param values from this list and pass this dictionary to a new estimator constructor. Therefore, all strings returned by `get_param_names()` should be arguments in `__init__()` otherwise an invalid argument exception will be raised. Most estimators implement `get_param_names()` similar to: +To support cloning, estimators need to implement the function `_get_param_names()`. The returned value should be a list of strings of all estimator attributes that are necessary to duplicate the estimator. This method is used in `Base.get_params()` which will collect the collect the estimator param values from this list and pass this dictionary to a new estimator constructor. Therefore, all strings returned by `_get_param_names()` should be arguments in `__init__()` otherwise an invalid argument exception will be raised. Most estimators implement `_get_param_names()` similar to: ```python -def get_param_names(self): - return super().get_param_names() + [ +@classmethod +def _get_param_names(cls): + return super()._get_param_names() + [ "eps", "min_samples", ] ``` -**Note:** Be sure to include `super().get_param_names()` in the returned list to properly set the `super()` attributes. +**Note:** Be sure to include `super()._get_param_names()` in the returned list to properly set the `super()` attributes. ### Estimator Tags and cuML-Specific Tags