def perform(self, node, inputs, output_storage):
"""
Calculate ROC AUC score.
Parameters
----------
node : Apply instance
Symbolic inputs and outputs.
inputs : list
Sequence of inputs.
output_storage : list
List of mutable 1-element lists.
"""
if roc_auc_score is None:
raise RuntimeError("Could not import from sklearn.")
y_true, y_score = inputs
y_true = np.argmax(y_true, axis=1)
y_score = np.argmax(y_score, axis=1)
try:
TP = np.sum(y_true[y_score==1]==1)*1. #/ sum(y_true)
FP = np.sum(y_true[y_score==1]==0)*1. #/ (y_true.shape[0]-sum(y_true))
#TN = np.sum(truey[predy==0]==0)*1. / (truey.shape[0]-sum(truey))
FN = np.sum(y_true[y_score==0]==1)*1. #/ sum(y_true)
#prec = TP / (TP+FP+1e-6)
#reca = TP / (TP+FN+1e-6)
#f1 = 2*prec*reca / (prec+reca+1e-6)
f1 = 2*TP / (2*TP +FP +FN)
except ValueError:
f1 = np.nan
#rvalue = np.array((roc_auc, prec, reca, f1))
#[0][0]
output_storage[0][0] = theano._asarray(f1, dtype=config.floatX)
roc_auc.py 文件源码
python
阅读 33
收藏 0
点赞 0
评论 0
评论列表
文章目录