2
$\begingroup$

My tensorflow ML algorithm gives me an ROC AUC of 0.81 using the contrib.metrics.streaming_auc() function, whereas using the same logits and labels in sklearn's function gives me a score of 0.58. How can this be?

When I reduce the number of thresholds in the tensorflow function, tensorflow too gives me significantly lower AUC, so can the explanation be in the two libraries different ways of calculating the AUC?

Relevant code snippets, first from building the tensorflow graph:

...
self.logits = tf.matmul(last_layer_outputs, weights) + bias
self.loss = tf.reduce_mean(tf.nn.sparse_softmax_cross_entropy_with_logits(
                                     self.logits,
                                     tf.argmax(self.y_placeholder,1)))
...
self.softmaxed_logits = tf.nn.softmax(self.logits)
(_, self.auc_update_op) = tf.contrib.metrics.streaming_auc(
                              predictions=self.softmaxed_logits,
                              labels=self.y_placeholder,
                              curve='ROC')
Then from asking sklearn.metrics and tensorflow for the AUC:
...
soft_logits = model_instance.sess.run(model_instance.softmaxed_logits,
                                      feed_dict=test_feed)
sklearn_auc = metrics.roc_auc_score(y_true=model_instance.T3SS_data.y_test,
                                    y_score=soft_logits)
tf_auc = model_instance.sess.run(model_instance.auc_update_op,
                                 feed_dict=test_feed)

$\endgroup$
2
  • $\begingroup$ Because the model they give are different $\endgroup$
    – SmallChess
    Commented Oct 12, 2016 at 9:26
  • $\begingroup$ @StudentT Am I understanding you right, that sklearn's and tensorflow's model of ROC AUC are different? Can you help me understand how, or is there a link, because from what I read on their respective documentations, it seems identical to me? $\endgroup$
    – Peter
    Commented Oct 12, 2016 at 10:43

2 Answers 2

2
$\begingroup$

The streaming_auc keeps accumulating the scores of repeated calls to it, so that you can use it, for example, to get the AUC of several batch runs all accumulated. It does not just calculate the current AUC.

In order to use it to get just the current AUC, you can reset the local variables it uses (e.g. running tf.initialize_local_variables()) before running its update operation.

$\endgroup$
1
$\begingroup$

NO ! its because Scikit learn does not calculate AUC by discretizing a curve with variable thresholds like is done in tensorflow! SKlearn uses your values

this has just burnt me.

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.