numpy.float64'对象无法在auc中调用(调用,精度)

时间:2019-05-25 11:49:48

标签: python object machine-learning

我运行时程序抛出['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 个答案:

答案 0 :(得分:1)

运行以下行(在回溯中注释):

auc = auc(recall, precision)

您用一个numpy对象替换了命名空间中的函数auc。再次调用auc会引发错误。

答案 1 :(得分:0)

您可以按以下方式对这个问题进行排序:

from sklearn import metrics

metrics.auc(recall, precision)

答案 2 :(得分:0)

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