MCPcopy
hub / github.com/scikit-learn/scikit-learn / _changed_params

Function _changed_params

sklearn/utils/_pprint.py:91–114  ·  view source on GitHub ↗

Return dict (param_name: value) of parameters that were given to estimator with non-default values.

(estimator)

Source from the content-addressed store, hash-verified

89
90
91def _changed_params(estimator):
92 """Return dict (param_name: value) of parameters that were given to
93 estimator with non-default values."""
94
95 params = estimator.get_params(deep=False)
96 init_params = inspect.signature(estimator.__init__).parameters
97 init_params = {name: param.default for name, param in init_params.items()}
98
99 def has_changed(k, v):
100 if k not in init_params: # happens if k is part of a **kwargs
101 return True
102 if init_params[k] == inspect._empty: # k has no default value
103 return True
104 # try to avoid calling repr on nested estimators
105 if isinstance(v, BaseEstimator) and v.__class__ != init_params[k].__class__:
106 return True
107 # Use repr as a last resort. It may be expensive.
108 if repr(v) != repr(init_params[k]) and not (
109 is_scalar_nan(init_params[k]) and is_scalar_nan(v)
110 ):
111 return True
112 return False
113
114 return {k: v for k, v in params.items() if has_changed(k, v)}
115
116
117class _EstimatorPrettyPrinter(pprint.PrettyPrinter):

Callers 2

_pprint_estimatorMethod · 0.85
_safe_reprFunction · 0.85

Calls 2

has_changedFunction · 0.85
get_paramsMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…