MCPcopy Create free account
hub / github.com/PythonOT/POT / set_params

Method set_params

ot/utils.py:972–1012  ·  view source on GitHub ↗

r"""Set the parameters of this estimator. The method works on simple estimators as well as on nested objects (such as pipelines). The latter have parameters of the form `` __ `` so that it's possible to update each component of a nested object.

(self, **params)

Source from the content-addressed store, hash-verified

970 return out
971
972 def set_params(self, **params):
973 r"""Set the parameters of this estimator.
974
975 The method works on simple estimators as well as on nested objects
976 (such as pipelines). The latter have parameters of the form
977 ``<component>__<parameter>`` so that it&#x27;s possible to update each
978 component of a nested object.
979
980 Returns
981 -------
982 self
983 """
984 if not params:
985 # Simple optimisation to gain speed (inspect is slow)
986 return self
987 valid_params = self.get_params(deep=True)
988 # for key, value in iteritems(params):
989 for key, value in params.items():
990 split = key.split("__", 1)
991 if len(split) > 1:
992 # nested objects case
993 name, sub_name = split
994 if name not in valid_params:
995 raise ValueError(
996 "Invalid parameter %s for estimator %s. "
997 "Check the list of available parameters "
998 "with `estimator.get_params().keys()`." % (name, self)
999 )
1000 sub_object = valid_params[name]
1001 sub_object.set_params(**{sub_name: value})
1002 else:
1003 # simple objects case
1004 if key not in valid_params:
1005 raise ValueError(
1006 "Invalid parameter %s for estimator %s. "
1007 "Check the list of available parameters "
1008 "with `estimator.get_params().keys()`."
1009 % (key, self.__class__.__name__)
1010 )
1011 setattr(self, key, value)
1012 return self
1013
1014
1015class UndefinedParameter(Exception):

Callers 1

test_BaseEstimatorFunction · 0.80

Calls 1

get_paramsMethod · 0.95

Tested by 1

test_BaseEstimatorFunction · 0.64