title: How to apply class weights in linear classifier for binary classification?
body: <p>This is the linear classifier that I am using to perform binary classification, here is code snippet:</p>
  
  <pre><code>my_optimizer = tf.train.AdagradOptimizer(learning_rate = learning_rate)
  my_optimizer = tf.contrib.estimator.clip_gradients_by_norm(my_optimizer,5.0)
  # Create a linear classifier object
  linear_classifier = tf.estimator.LinearClassifier(
            feature_columns = feature_columns, 
            optimizer = my_optimizer 
            )
  linear_classifier.train(input_fn = training_input_fn, steps = steps)
  </code></pre>
  
  <p>The dataset is imbalanced, there are only two classes yes/no. The number of NO class examples are 36548 while number of YES class examples are 4640. </p>
  
  <p>How can I apply balancing to this data? I have been searching around and I could find stuff related to class weights etc but I couldn't find how can I create class weights and how to apply to the train method of tensor flow. </p>
  
  <p>Here is how I am calculating losses:</p>
  
  <pre><code>training_probabilities = linear_classifier.predict(input_fn = training_predict_input_fn)
  training_probabilities = np.array([item['probabilities'] for item in training_probabilities])
  
  validation_probabilities = linear_classifier.predict(input_fn=validation_predict_input_fn)
  validation_probabilities = np.array([item['probabilities'] for item in validation_probabilities])
  
  training_log_loss = metrics.log_loss(training_targets, training_probabilities)
  validation_log_loss = metrics.log_loss(validation_targets, validation_probabilities)
  </code></pre>