My problem is sentence classification, a two-class prediction problem: Does the sentence belong to class "1" or class "0"? In order to tackle the problem, I use a CNN.
However, I want to force the model to punish errors on class "1" more, because it is much more important for me that the model predicts class "1" reliably, i.e., false positives on class "0" are tolerable.
For this, I changed the cost function. Whenever there is an error and the error is on class "1", a value of 2 is returned, otherwise 1 is returned. If there is no error, 0 is returned. This should have the effect that the cost increases if the prediction is "0", but it should have been "1", compared to the inverse case.
This is my code (sorry for the mess).
def class_imbalanced_errors(self,y_pred,y):
expr=lambda a,b: T.switch(T.neq(a,b),T.switch(T.neq(a,T.constant(1)),T.constant(1),T.constant(2)),T.constant(0))
x,y = theano.scan(expr,sequences=[y,y_pred])
return x
The function returns a vector of values 2,1, or 0, depending on the error types. The mean of this vector is then the final cost.
My question(s):
Is this the right approach to give different weights to the two classes? Does my implementation seem to be correct?