首页 > 解决方案 > 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

标签: pythonobjectmachine-learning

解决方案


当您运行以下行时(在回溯中注释掉):

auc = auc(recall, precision)

您将命名空间中的函数替换auc为 numpy 对象。再次调用auc抛出错误。


推荐阅读