gpt4 book ai didi

python - 更新 scikit-learn : 'SVC' object has no attribute '_probA' ?

转载 作者:行者123 更新时间:2023-12-04 00:15:53 32 4
gpt4 key购买 nike

我们更新到 Python 3.8.2 并且在使用 scikit-learn 时出现错误:

Traceback (most recent call last):
File "manage.py", line 16, in <module>
execute_from_command_line(sys.argv)
File "/home/ubuntu/myWebApp/.venv/lib/python3.8/site-packages/django/core/management/__init__.py", line 381, in execute_from_command_line
utility.execute()
File "/home/ubuntu/myWebApp/.venv/lib/python3.8/site-packages/django/core/management/__init__.py", line 375, in execute
self.fetch_command(subcommand).run_from_argv(self.argv)
File "/home/ubuntu/myWebApp/.venv/lib/python3.8/site-packages/django/core/management/base.py", line 316, in run_from_argv
self.execute(*args, **cmd_options)
File "/home/ubuntu/myWebApp/.venv/lib/python3.8/site-packages/django/core/management/base.py", line 353, in execute
output = self.handle(*args, **options)
File "/home/ubuntu/myWebApp/server_modules/rss_ml_score/management/commands/rssmlscore.py", line 22, in handle
run.build_and_predict(days=options['days'], rescore=options['rescore'])
File "/home/ubuntu/myWebApp/server_modules/rss_ml_score/utils/run.py", line 96, in build_and_predict
predict_all(filename)
File "/home/ubuntu/myWebApp/server_modules/rss_ml_score/models/predict_model.py", line 135, in predict_all
voting_predicted_hard, voting_predicted_soft = predict_from_multiple_estimator(fitted_estimators, X_predict_list,
File "/home/ubuntu/myWebApp/server_modules/rss_ml_score/models/train_model.py", line 66, in predict_from_multiple_estimator
pred_prob1 = np.asarray([clf.predict_proba(X)
File "/home/ubuntu/myWebApp/server_modules/rss_ml_score/models/train_model.py", line 66, in <listcomp>
pred_prob1 = np.asarray([clf.predict_proba(X)
File "/home/ubuntu/myWebApp/.venv/lib/python3.8/site-packages/sklearn/svm/_base.py", line 662, in _predict_proba
if self.probA_.size == 0 or self.probB_.size == 0:
File "/home/ubuntu/myWebApp/.venv/lib/python3.8/site-packages/sklearn/svm/_base.py", line 759, in probA_
return self._probA
AttributeError: 'SVC' object has no attribute '_probA'
除了sci-kit学习访问_probA,我还需要使用另一个库吗?
更新 以回应评论:
抛出错误的代码行是:
pred_prob1 = np.asarray([clf.predict_proba(X)
for clf, X in zip(estimators, X_list)])
...在 _base.py 中调用此行:
def _predict_proba(self, X):
X = self._validate_for_predict(X)
if self.probA_.size == 0 or self.probB_.size == 0:
...它调用这一行,也在 _base.py 中:
@property
def probA_(self):
return self._probA
...抛出错误:

AttributeError: 'SVC' object has no attribute '_probA'


所有这些都运行了好几个月,但即使更新到最新的 scikit-learn. 之后也无法正常工作

最佳答案

事实证明,我不得不使用用于训练我们目前拥有的模型的相同版本的 sci-kit (scikit-learn==0.21.2)。 scikit 的更高版本不适用于我们现有的代码/模型。如果我们想升级 scikit,我们必须使用新版本的 scikit 重新训练我们的模型。

关于python - 更新 scikit-learn : 'SVC' object has no attribute '_probA' ?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/63802563/

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