[ Tensorflow ] AUC 구하기

2020. 2. 21. 22:20분석 Python/Tensorflow

광고 한 번씩 눌러주세요. 블로그 운영에 큰 힘이 됩니다 :)

import tensorflow as tf
import numpy as np

a= np.random.uniform(size=(10,2)) 
prob = a / np.expand_dims(np.sum(a,axis =1 ),axis =1)
prob

target = np.random.randint(low=0, high =2 , size=10)
target = np.argmax(prob , axis = 1)
probs = tf.constant(prob)
labels = tf.constant(target)
proba = tf.slice(probs,[0,1],[-1,1])
auc_value , update_auc = tf.metrics.auc(tf.reshape(labels,shape=(-1,1)) , proba, curve='ROC')

#init = tf.initialize_all_variables()
sess = tf.Session()
init = tf.group(tf.global_variables_initializer(), tf.local_variables_initializer())
sess.run(init)


sess.run(auc_value , update_auc)

728x90