title: Unbalanced data and weighted cross entropy
body: <p>I'm trying to train a network with an unbalanced data. I have A (198 samples), B (436 samples), C (710 samples), D (272 samples) and I have read about the &quot;weighted_cross_entropy_with_logits&quot; but all the examples I found are for binary classification so I'm not very confident in how to set those weights.</p>
  <p>Total samples: 1616</p>
  <p>A_weight: 198/1616 = 0.12?</p>
  <p>The idea behind, if I understood, is to penalize the errors of the majority class and value more positively the hits in the minority one, right?</p>
  <p>My piece of code:</p>
  <pre><code>weights = tf.constant([0.12, 0.26, 0.43, 0.17])
  cost = tf.reduce_mean(tf.nn.weighted_cross_entropy_with_logits(logits=pred, targets=y, pos_weight=weights))
  </code></pre>
  <p>I have read <a href="https://stackoverflow.com/questions/40698709/tensorflow-interpretation-of-weight-in-weighted-cross-entropy">this one</a> and others examples with binary classification but still not very clear.</p>
  <p>Thanks in advance.</p>