r"""Get parameters for this estimator. Parameters ---------- deep : bool, optional If True, will return the parameters for this estimator and contained subobjects that are estimators. Returns ------- params : mapping of string
(self, deep=True)
| 933 | return sorted([p.name for p in parameters]) |
| 934 | |
| 935 | def get_params(self, deep=True): |
| 936 | r"""Get parameters for this estimator. |
| 937 | |
| 938 | Parameters |
| 939 | ---------- |
| 940 | deep : bool, optional |
| 941 | If True, will return the parameters for this estimator and |
| 942 | contained subobjects that are estimators. |
| 943 | |
| 944 | Returns |
| 945 | ------- |
| 946 | params : mapping of string to any |
| 947 | Parameter names mapped to their values. |
| 948 | """ |
| 949 | out = dict() |
| 950 | for key in self._get_param_names(): |
| 951 | # We need deprecation warnings to always be on in order to |
| 952 | # catch deprecated param values. |
| 953 | # This is set in utils/__init__.py but it gets overwritten |
| 954 | # when running under python3 somehow. |
| 955 | warnings.simplefilter("always", DeprecationWarning) |
| 956 | try: |
| 957 | with warnings.catch_warnings(record=True) as w: |
| 958 | value = getattr(self, key, None) |
| 959 | if len(w) and isinstance(w[0].category, DeprecationWarning): |
| 960 | # if the parameter is deprecated, don't show it |
| 961 | continue |
| 962 | finally: |
| 963 | warnings.filters.pop(0) |
| 964 | |
| 965 | # XXX: should we rather test if instance of estimator? |
| 966 | if deep and hasattr(value, "get_params"): |
| 967 | deep_items = value.get_params().items() |
| 968 | out.update((key + "__" + k, val) for k, val in deep_items) |
| 969 | out[key] = value |
| 970 | return out |
| 971 | |
| 972 | def set_params(self, **params): |
| 973 | r"""Set the parameters of this estimator. |