1
$\begingroup$

I have trained a multi-class CNN model using fastai. The model splits out probabilites for each of the three classes, which, of course, sum up to 1. The class with highest probability becomes the predicted class.

Is there any way I can convert them into 0 to 1 scale, where near to 0 value would mean class 1, near to 0.5 would mean class 2 and near to 1 would mean class 3?

$\endgroup$

2 Answers 2

1
$\begingroup$

You could maybe do something like this, it's a bit hackish \begin{equation} y = C_1\cdot 1 + C_2 \cdot 0.5 + C_3 \cdot 0 \end{equation} $y$ represents the output and its bounded $\in [0, 1]$. $C_i$ is probability for class $i$. This way when $C_1 \approx 1, C_2 \approx 0, C_3 \approx 0$ you have \begin{equation} y \approx 1\cdot 1 + 0.5 \cdot 0 + 0 \cdot 0 \approx 1 \end{equation} when $C_1 \approx 0, C_2 \approx 1, C_3 \approx 0 $ you have \begin{equation} y \approx 1\cdot 0 + 0.5 \cdot 1 + 0 \cdot 0 \approx 0.5 \end{equation} and when $C_1 \approx 0, C_2 \approx 0, C_3 \approx 1 $ you have \begin{equation} y \approx 1\cdot 0 + 0.5 \cdot 0 + 0 \cdot 1 \approx 0 \end{equation}

$\endgroup$
8
  • $\begingroup$ Thats what I thought to do and it would work in best scenario. If C1 = 0.5 and C3 = 0.5, then the y would be 0.5, which would be incorrect. Sorry, if I wasnt clear in the begining, the predicted probalitites for each class can be between 0 to 1, not just binary. $\endgroup$ Commented Dec 23, 2019 at 15:34
  • $\begingroup$ Right, the assumption is that model is well trained. If you have a model that gives you 50%-50% you might want to train a better model. $\endgroup$
    – Brale
    Commented Dec 23, 2019 at 15:35
  • $\begingroup$ @user1631306: What is the correct result for you if "If C1 = 0.5 and C3 = 0.5"? You say that a value of 0.5 would be incorrect. So what would you want the output to be, and why? $\endgroup$ Commented Dec 23, 2019 at 15:43
  • 2
    $\begingroup$ Alternatively, you could replace softmax with sigmoid and change labels for classes to 0, 0.5, 1. That's the only other solution I can think of because I'm not sure if there is practical way to make bijection from $R^3 \rightarrow R$ without doing some more abstract mathematical constructions. $\endgroup$
    – Brale
    Commented Dec 23, 2019 at 16:06
  • $\begingroup$ @Brale_: I should be ready for the worse scenario. Model usually predicts with high probability. But these are cell assay images and they are bound to have nearly equal probabilites in two or more classes. $\endgroup$ Commented Dec 23, 2019 at 16:10
0
$\begingroup$

In such cases, you can have just 1 final neuron and treat the problem as a regression problem where the output distance from all 3 classes is calculated and the class with least distance becomes the predicted class.

If you want independent values for 3 classes (such as [0.8, 0.5, 0.3]) which don't add up to 1, (something like multilabel/multiclass classification), you can use sigmoid in such cases( you won't get the probability ).

$\endgroup$
1
  • $\begingroup$ I am not worried about predicted class, thats been taken care of. I was wondering if somehow I could normalize the probablity score. Seems like I might be on wrong track and I am not asking the question correctly. $\endgroup$ Commented Dec 23, 2019 at 16:16

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .