gpt4 book ai didi

python - 'LinearSVC' 对象没有属性 'classes_'

转载 作者:太空宇宙 更新时间:2023-11-03 12:05:28 24 4
gpt4 key购买 nike

我有几个图像样本,我想预测这些图像是否包含文本/字符。

当我尝试在这一步运行我的代码时出现错误:

model = cPickle.load(f)
is_text = model.predict(image_samples)

image_samples 是我的样本,模型看起来像这样:

Pipeline(steps=[
('hog', HOGFeatures(cells_per_block=(2, 2), orientations=10,
pixels_per_cell=(5, 5), size=(20, 20))),
('clf', LinearSVC(C=2.0, class_weight=None, dual=True,
fit_intercept=True,
intercept_scaling=1, loss='l2', max_iter=None,
multi_class='ovr', penalty='l2',
random_state=None, tol=0.0001, verbose=0))
])

我得到的错误信息是:

File "/home/parallels/Desktop/Python/ImageTextRecognition-master/userimageski.py", line 104, in select_text_among_candidates
is_text = model.predict(self.candidates['flattened'])

File "/usr/local/lib/python2.7/dist-packages/sklearn/utils/metaestimators.py", line 37, in <lambda>
out = lambda *args, **kwargs: self.fn(obj, *args, **kwargs)

File "/usr/local/lib/python2.7/dist-packages/sklearn/pipeline.py", line 180, in predict
return self.steps[-1][-1].predict(Xt)

File "/usr/local/lib/python2.7/dist-packages/sklearn/linear_model/base.py", line 228, in predict
return self.classes_[indices]
AttributeError: 'LinearSVC' object has no attribute 'classes_'

谁能帮帮我?非常感谢

最佳答案

我遇到了同样的问题。这实际上是 sklearn 版本的问题。在终端中运行 python2.7 并检查 >>> import sklearn >>> sklearn.__version__ 如果你有比当前版本更早的版本和截至目前的 0.17.1是最新的,那么你需要升级 sklearn 。只需执行 sudo pip install -U scikit-learn 即可升级并重新运行代码

关于python - 'LinearSVC' 对象没有属性 'classes_',我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33327530/

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