gpt4 book ai didi

python - FutureWarning get_params 来自 scikit-learn

转载 作者:行者123 更新时间:2023-12-03 21:49:25 24 4
gpt4 key购买 nike

我收到警告

File "[...]\lib\threading.py", line 890, in _bootstrap
self._bootstrap_inner()
File "[...]\lib\threading.py", line 932, in _bootstrap_inner
self.run()
File "C:\Program Files\JetBrains\PyCharm 2019.1.3\plugins\python\helpers\pydev\_pydevd_bundle\pydevd_comm.py", line 216, in run
self._on_run()
File "C:\Program Files\JetBrains\PyCharm 2019.1.3\plugins\python\helpers\pydev\_pydev_bundle\pydev_console_commands.py", line 30, in _on_run
values.append(pydevd_thrift.var_to_struct(var_obj, name, evaluate_full_value=True))
File "C:\Program Files\JetBrains\PyCharm 2019.1.3\plugins\python\helpers\pydev\_pydevd_bundle\pydevd_thrift.py", line 305, in var_to_struct
value = format % v
File "[...]\lib\site-packages\sklearn\base.py", line 263, in __repr__
repr_ = pp.pformat(self)
File "[...]\lib\pprint.py", line 153, in pformat
self._format(object, sio, 0, 0, {}, 0)
File "[...]\lib\pprint.py", line 170, in _format
rep = self._repr(object, context, level)
File "[...]\lib\pprint.py", line 404, in _repr
repr, readable, recursive = self.format(object, context.copy(),
File "[...]\lib\site-packages\sklearn\utils\_pprint.py", line 169, in format
return _safe_repr(object, context, maxlevels, level,
File "[...]\lib\site-packages\sklearn\utils\_pprint.py", line 415, in _safe_repr
params = object.get_params(deep=False)
File "[...]\lib\site-packages\sklearn\base.py", line 193, in get_params
warnings.warn('From version 0.24, get_params will raise an '
File "[...]\lib\warnings.py", line 109, in _showwarnmsg
sw(msg.message, msg.category, msg.filename, msg.lineno,
File "<input>", line 59, in warn_with_traceback
[...]\lib\site-packages\sklearn\base.py:193: FutureWarning: From version 0.24, get_params will raise an AttributeError if a parameter cannot be retrieved as an instance attribute. Previously it would return None.
warnings.warn('From version 0.24, get_params will raise an '
尝试使用 sklearn 时。我不知道如何找出如何解决这个问题。显然,这对你来说是很少的信息,但我什至不知道从哪里开始追踪这个问题。
我唯一可以添加的是,当我尝试实例化我编写的继承自 CalibratedClassifierCV 的类时会发生这种情况。 .
我该如何解决这个问题?

最佳答案

我想,我能够靠运气找到答案。如 scikit-learn 的 documentation 中所述,初始化必须看起来像

def __init__(self, param1=1, param2=2):
self.param1 = param1
self.param2 = param2
我犯的错误是写了类似的东西
def __init__(self, param1=1, param2=2):
self.param1 = param1
self.param2_ = param2
注意下划线。必须避免这种情况,因为它会干扰方法 set_paramsget_params .的确,我的警告源于后者。
此外,尾随下划线用于 estimated attributes :

Attributes that have been estimated from the data must always have a name ending with trailing underscore, for example the coefficients of some regression estimator would be stored in a coef_ attribute after fit has been called.

The estimated attributes are expected to be overridden when you call fit a second time.

关于python - FutureWarning get_params 来自 scikit-learn,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/63251437/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com