First, thank you.
I'm using Tensorflow 1.13 with Python 3. I'm trying to create a CNN classifier on data with 4 classes, one-hot encoded. However, the insights I need it to produce are really around spotting either classes 0 or 3. If it tells me a data row is of class 1 or 2, that's of little use to my goals. Output from sklearn classification_report
is below and I want to increase recall on classes 0 and 3 during model training. Precision would be nice, too.
precision recall f1-score support
0 0.13 0.42 0.20 1484
1 0.15 0.74 0.24 696
2 0.81 0.34 0.48 12325
3 0.13 0.23 0.17 1495
avg / total 0.65 0.35 0.41 16000
I'm relatively new to both python and TF, having gone through several tutorials, and am just now starting to build my own models. I've not really been able to stretch myself out past capabilities discussed in any of the learning courses I've watched. I know that Keras, for example, has custom loss function capability, but I'm not sure I understand how to integrate it into what I've already done. Relevant bits from my existing project are below.
# my current loss function, what I want to
# replace because just plain accuracy isn't
# terribly helpful
cross_entropy = tf.reduce_mean(tf.nn.softmax_cross_entropy_with_logits(labels=y_true,logits=y_pred))
# setting up the trainer
optimizer = tf.train.AdamOptimizer(learning_rate=0.0001)
train = optimizer.minimize(cross_entropy)
# run it
init = tf.global_variables_initializer()
with tf.Session() as sess:
sess.run(init)
for i in range(steps):
batch_x, batch_y = dataHelper.next_batch(100)
sess.run(train,feed_dict={x:batch_x,y_true:batch_y,hold_prob:0.5})
if (i + 1) % 100 == 0:
print('on step {}'.format(i))
preds_decoded = tf.argmax(y_pred,1)
trues_decoded = tf.argmax(y_true,1)
final_predictions, true_values = sess.run([preds_decoded, trues_decoded],
feed_dict={x:price_data_only_test,y_true:test_labels,hold_prob:1.0})
print(classification_report(y_true=true_values,y_pred=final_predictions))
```