Hi Small!
My speculation is that you are treating your problem as a classification
problem, that is, you are trying to predict the number of days exactly.
I think you will get better results treating your use case as a regression.
A bit of explanation:
Let’s say that the actual number of days you are trying to predict is 14.
When training as classification, if your model predicts 14, it’s right, and
you get a low loss function. But if your model predicts 13 or 15, it’s
wrong, and it’s just as wrong as if it had predicted 3 or 22, even though
a prediction of 13 or 15 is really quite good, even if not perfect.
In a regression, you will penalize your model more for being way off (e.g.,
3 or 22) than for being close, but not perfect (e.g., 13 or 15).
Regression seems to me to be a better conceptual fit for what you are
actually trying to accomplish.
Furthermore, even though your use case is straightforward and easy to
describe, I could see it being quite a difficult problem if your measure of
success is getting your predictions exactly right,. Realistically, based on
your input data, how is your model supposed to predict 14 instead of 15
(for the example where the correct result is 14)? That seems hard, so an
accuracy rate of 30% doesn’t sound so bad.
To perform a regression, change your final Linear
layer to have
out_features = 1
, that is, Linear (512, 1)
, and use MSELoss
as
your loss criterion. (Let your predictions be floating-point numbers, e.g.,
“predicted number of days = 14.72.”)
Then measure your performance based not on how often your model
gets the number of days exactly right, but rather, on how close it usually
is. So use the mean-squared-error or root-mean-squared-error of your
predictions to judge how well your model is doing.
Best.
K. Frank