Unblock all features
Sign in to track progress, get AI help and save conversations.
The first version of our model is bad, the predictions probably will not match the real values in many cases. But how bad is it? Can we measure it?
We can measure the model's performance if we have a test set data to compare with. Imagine we have a dataset where humans manually reviewed and labeled each message.
| Message | Label |
|---|---|
| Can you review my report? | not spam |
| Thanks for your help! | not spam |
| Happy birthday!! | not spam |
Now we can compare the model's predictions with the real labels from the test set for each message. The model is good when the results are the same and bad when they are different.
The metric that does it is called accuracy. The accuracy is a percentage of correct predictions over the whole dataset.
We consider the prediction as not spam if the predicted spam score is less than 0.5 (the threshold) and as spam otherwise.
For our current model , the accuracy for the above test set is 40%.
This is how our model is currently performing, and our goal is to improve it.
The other way to evaluate the model is using a loss function. It measures how wrong the actual predicted values are instead of collapsing them to yes/no labels.
There are different formulas for the loss function. For our binary classification task we will use cross-entropy:
It is basically the average of losses for each test case. For each message the formula collapses and only one of two terms is left:
The minus sign is needed to make the result always positive as of a positive number smaller than 1 is always negative.
The ensures the errors are punished more when the model is confidently wrong. E.g.
For our current model , the loss value for the above test set is 0.84.
We will use both the loss function and accuracy to measure the model.
The accuracy is simple, and it is easy to intuitively understand how the model performs.
The loss function is more detailed, and we will need these details to improve our model.