在 Logistic 回归上制作 Precision_Recall 图

问题描述

我试图制作精确召回图但无济于事。我有一个程序,它使用 resnet50 从一组图像中提取特征并将它们存储为 hdf5 格式,使用逻辑回归根据使用 resnet50 模型学习的特征对图像进行分类。我尝试从 sklearn 添加代码来绘制逻辑回归分类过程结果的精确召回,但一直失败。我对此很陌生,如果有人可以告诉我我做错了什么并向我展示出路,我将不胜感激。 下面是我的代码

# the training and testing split,provided that this data was
# already shuffled *prior* to writing it to disk
db = h5py.File(args["db"],"r")
i = int(db["labels"].shape[0] * 0.75)

# define the set of parameters that we want to tune then start a
# grid search where we evaluate our model for each value of C
print("[INFO] tuning hyperparameters...")
params = {"C": [0.0001,0.001,0.01,0.1,1.0]}
model = OneVsRestClassifier(gridsearchcv(LogisticRegression(solver="lbfgs",multi_class="auto"),params,cv=3,n_jobs=args["jobs"]))
model.fit(db["features"][:i],db["labels"][:i])
#print("[INFO] best hyperparameters: {}".format(model.best_params_))

# generate a classification report for the model
print("[INFO] evaluating...")
preds = model.predict_proba(db["features"][i:])
#print(classification_report(db["labels"][i:],preds,#   target_names=db["label_names"]))

#Paul's try-out with Precision-Recall Plot
precision = dict()
recall = dict()
for i in range(5):
    precision[i],recall[i],_ = precision_recall_curve(db["labels"][i:],preds[:,i])
    plt.plot(recall[i],precision[i],lw=2,label='db["labels"][i:]')
    
plt.xlabel("recall")
plt.ylabel("precision")
plt.legend(loc="best")
plt.title("Precision vs. Recall Curve")
plt.show()

# compute the raw accuracy with extra precision
acc = accuracy_score(db["labels"][i:],preds)
print("[INFO] score: {}".format(acc))

# serialize the model to disk
print("[INFO] saving model...")
f = open(args["model"],"wb")
f.write(pickle.dumps(model.best_estimator_))
f.close()

# close the database
db.close()

它不断抛出的错误是: ValueError: multiclass format is not supported

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)