title: Adding Class Weights for imbalanced dataset in Convolutional Neural Network
body: <p>I have a dataset of images that has the following distribution:</p>
  
  <ul>
  <li>Class 0: 73,5% </li>
  <li>Class 1: 7% </li>
  <li>Class 2: 15%</li>
  <li>Class 3: 2,5% </li>
  <li>Class 4: 2%</li>
  </ul>
  
  <p>I think I need to add Class Weights to make up for the low amount of images in class 1, 2, 3 and 4.</p>
  
  <p>I have tried calculating the class weights by dividing class 0 with class 1, class 0 with class 2 and so forth.</p>
  
  <p>I'm assuming that class 0 corresponds to 1, as it doesnt need to be scaled? Not sure if that is correct though.</p>
  
  <pre><code>class_weights = np.array([1, 10.5, 4.9, 29.4, 36.75]) 
  </code></pre>
  
  <p>and added them to my fit function:</p>
  
  <pre><code>model.fit(x_train, y_train, batch_size=batch_size, class_weight=class_weights, epochs=epochs, validation_data=(x_test, y_test))
  </code></pre>
  
  <p>I'm unsure if I have calculated the weights correctly, and if this is even how it is supposed to be done?</p>
  
  <p>Hopefully anyone can help clarifying it.</p>