Keras: class weights (class_weight) for one-hot encoding : <p>I'd like to use class_weight argument in keras model.fit to handle the imbalanced training data. By looking at some documents, I understood we can pass a dictionary like this:</p>

<pre><code>class_weight = {0 : 1,
    1: 1,
    2: 5}
</code></pre>

<p>(In this example, class-2 will get higher penalty in the loss function.)</p>

<p>The problem is that my network's output has one-hot encoding i.e. class-0 = (1, 0, 0), class-1 = (0, 1, 0), and class-3 = (0, 0, 1).</p>

<p>How can we use the class_weight for one-hot encoded output?</p>

<p>By looking at <a href="https://github.com/fchollet/keras/blob/d89afdfd82e6e27b850d910890f4a4059ddea331/keras/engine/training.py#L1307" rel="noreferrer">some codes in Keras</a>, it looks like <code>_feed_output_names</code> contain a list of output classes, but in my case, <code>model.output_names</code>/<code>model._feed_output_names</code> returns <code>['dense_1']</code></p>

<p>Related: <a href="https://datascience.stackexchange.com/questions/13490/how-to-set-class-weights-for-imbalanced-classes-in-keras">How to set class weights for imbalanced classes in Keras?</a></p>
