@@ -300,6 +300,37 @@ def _check_params(self, params):
300300 (key , self .__class__ .__name__ , str (legal_params )))
301301
302302
303+ def _get_param_names (self ):
304+ """Get parameter names for the estimator"""
305+ # fetch the constructor or the original constructor before
306+ # deprecation wrapping if any
307+ init = getattr (self .__init__ , "deprecated_original" , self .__init__ )
308+ if init is object .__init__ :
309+ # No explicit constructor to introspect
310+ return []
311+
312+ # introspect the constructor arguments to find the model parameters
313+ # to represent
314+ init_signature = inspect .signature (init )
315+ # Consider the constructor parameters excluding 'self'
316+ parameters = [
317+ p
318+ for p in init_signature .parameters .values ()
319+ if p .name != "self" and p .kind != p .VAR_KEYWORD
320+ ]
321+ for p in parameters :
322+ if p .kind == p .VAR_POSITIONAL :
323+ raise RuntimeError (
324+ "scikit-learn estimators should always "
325+ "specify their parameters in the signature"
326+ " of their __init__ (no varargs)."
327+ " %s with constructor %s doesn't "
328+ " follow this convention." % ("dummy" , init_signature )
329+ )
330+ # Extract and sort argument names excluding 'self'
331+ return sorted ([p .name for p in parameters ])
332+
333+
303334 def _filter_params (self , func , override = {}, prefix = "" ):
304335 kwargs = {}
305336 args = inspect .getfullargspec (func ).args
0 commit comments