在auc(recall,precision)中,'numpy.float64'对象不可调用

7
程序运行时出现错误:['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
3个回答

15

当你运行以下这一行(在你的回溯中被注释掉):

```python # some line of code ```
时,发生了错误。
auc = auc(recall, precision)

您在命名空间中用numpy对象替换了函数auc。再次调用auc时出现错误。


1
明白了,有什么措施可以避免它发生吗? - Cagdas Kanar
2
通常情况下,您可以避免重新分配已经使用过的变量。这样,您的命名空间中的所有内容都具有单一且不变的定义。 - foglerit

1
您可以按照以下方式解决此问题:

from sklearn import metrics

metrics.auc(recall, precision)

0

你应该使用 print(auc(recall, precision))


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接