I am working on a regression task, using cnn for feature extraction and fully-connected layers for generating regression values.

However, the target value of each input data is an integer. There are five possible target values: 1 representing 'hate', 2 representing 'dislike', ... , and the final target value 5 representing 'love'. (I know the task can also be considered as a classification task, but I need to implement it as a regression task.)

The evaluation metrics are rmse and mae. I want to make the DNN generate intergers as regression results, which can make the evaluation metrics better. At present, the DNN network will generate for example 4.012 for target value 4. (Is there any other method than threshold? Or any method for learning the threshold automatically at the same time?. I am thinking about adding a classification layer connected to the second hidden layer to help the network learn the interger constraint.)

  • 1
    $\begingroup$ or you can consider it a classification problem , look for best classifier algorithm and dimensionality reduction method , both ca give you a v.good accuracy $\endgroup$ Apr 24 at 15:52

1 Answer 1


What you’re doing is an ordinal regression task, which TensorFlow seems to support, and I recommend looking into this approach. At the same time, remember Box’s famous quote.

All models are wrong, but some are useful.

Perhaps you can get a useful model by forcing this into the wrong approach.

Once you accept that you’re forcing the problem into the wrong machinery to solve it, the easiest way to predict one of your ordinal levels is to force your data into a standard regression problem and round the predictions to the nearest integer, constrained to your range. TensorFlow allows for custom loss functions. This article seems to explain it decently. I would write the loss function to first round the prediction to the nearest integer, then use an if statement to constrain that rounded value to 1-5. Then write something for square or absolute loss, based on the rounded and constrained prediction.

Alternatively, you may prefer to use a continuous loss function that already exists in your software, such as MSE or MAE, and then just evaluate the rounded and constrained predictions.


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.