我的目标是拥有三个最准确的预测标签。
通过使用此解决方案
clf = svm.SVC(
kernel='rbf',
C=51,
gamma=1,
probability=True
).fit(X,y)
predictions=[]
with open('model.pkl', 'rb') as f:
clf = pickle.load(f)
for line in X:
output=clf.predict(X)
#predictions.append(output)
df['prediction'] = output
# you add the list to the dataframe, then save the datframe to new csv
print(df)
我能够检索预测的标签。但是,当我添加clf.predict_proba(X)
如下
clf = svm.SVC(
kernel='rbf',
C=51,
gamma=1,
probability=True
).fit(X,y)
predictions=[]
with open('model.pkl', 'rb') as f:
clf = pickle.load(f)
for line in X:
output=clf.predict(X)
output_prob=clf.predict_proba(X)
#predictions.append(output)
df['prediction'] = output
# you add the list to the dataframe, then save the datframe to new csv
print(df)
我有以下错误:
AttributeError: predict_proba is not available when probability=False
根据 Scikit文档,应该像我一样明确定义为 True 的概率
clf = svm.SVC(
kernel='rbf',
C=51,
gamma=1,
probability=True
).fit(X,y)
如何解决这个问题?
谢谢
下面的代码使用从 pickle 文件加载的模型覆盖您的 clf 变量,其概率属性可能为 False。
with open('model.pkl', 'rb') as f:
clf = pickle.load(f)
因此,您没有使用在代码的第一部分创建的 SVC 实例。
根据此概率必须在调用 fit 之前启用,因此您无法在从 pickle 文件加载的模型中更改它。
您必须使用自己的训练模型(您创建并调用适合的模型)或使用另一个预训练模型(从 pickle 文件加载)并启用 proabiblity 属性。
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句