python - numpy.float64' 对象在 auc 中不可调用(召回,精度)
问题描述
['numpy.float64' object is not callable]
我运行时程序抛出错误:
auc(recall, precision)
直到今天我都能成功运行它。我将不胜感激任何帮助,谢谢!我也用 () 试过了,但没有用。
fit_logreg = LogisticRegression(class_weight='balanced', verbose=0)
fit_logreg.set_params(penalty = 'l2',
C = 0.00001,
n_jobs=-1,
verbose=0
)
###########################################################
###4#TRAIN THE FITTING MODEL ON THE TRAINING DATASET###
###########################################################
# fit a model
fit_logreg.fit(trainX, trainy)
# score the test dataset
predictions_logreg = fit_logreg.predict(testX)
#predictions_logreg = predictions_logreg.values.ravel()
###########################################################
###5#OOB ERROR AND CLASSIFICATION SUCCESS METRICS###
###########################################################
##ROC AUC SCORE
roc_auc_score(testy, predictions_logreg,average='macro')
##RECALL-PRECISION CURVE
# predict probabilities
probs = fit_logreg.predict_proba(testX)
# keep probabilities for the positive outcome only
probs = probs[:, 1]
# predict class values
yhat = predictions_logreg
# calculate precision-recall curve
precision, recall, thresholds = precision_recall_curve(testy, probs)
# calculate F1 score
f1 = f1_score(testy, yhat)
# calculate precision-recall AUC
auc(recall, precision)
这是我得到的错误:
TypeErrorTraceback (most recent call last)
<ipython-input-1-74f87a22f33a> in <module>()
68 # calculate precision-recall AUC
69 #auc = auc(recall, precision)
---> 70 auc(recall, precision)
TypeError: 'numpy.float64' object is not callable
解决方案
当您运行以下行时(在回溯中注释掉):
auc = auc(recall, precision)
您将命名空间中的函数替换auc
为 numpy 对象。再次调用auc
抛出错误。
推荐阅读
- if-statement - 我是否需要为嵌套的 IF 函数使用 ELIF 函数
- r - 并行处理-R中的Foraech和for循环
- bash - AWS EKS CLI 命令 - 如果/否则不起作用
- ruby - 运行命令 bundler install 时出错
- java - 是否可以忽略某种方法在 Hystrix 统计中的成功?
- junit - 我可以将其称为 JUnit 测试中的存根吗?
- excel - 根据其他工作簿中其他工作表中的单元格值(月份名称)选择要复制到的工作表
- json - python3:为一个值过滤 JSON 文件
- apache-kafka - Kafka 保留政策未按预期工作
- ios - 通过 IAP 的内容订阅模式