The Cross-Entropy Loss function is one of the most used losses for classification problems. It tells us how well a machine learning model classifies a dataset compared to the ground truth labels.
The Binary Cross-Entropy Loss is a special case when we have only 2 classes.
π
The most important part to understand is this one - this is the core of the whole formula!
Here, Y denotes the ground-truth label, while ΕΆ is the predicted probability of the classifier.
Let's look at a simple example before we talk about the logarithm... π
Imagine we have a bunch of photos and we want to classify each one as being a photo of a bird or not.
All photos are manually so that Y=1 for all bird photos and Y=0 for the rest.
The classifier (say a NN) outputs a probability of the photo containing a bird, like ΕΆ=0.9
π
Now, let's look a the logarithm.
Since ΕΆ is a number between 0 and 1, log ΕΆ will be a negative number increasing up to 0.
Let's take an example of a bird photo (Y=1):
βͺοΈ Classifier predicts 99% bird, so we get -0.01
βͺοΈ Classifier predicts 5% bird, so we get -3
That's weird π
For a loss, we want a value close to 0 if the classifier is right and a large value when the classifier is wrong. In the example above it was the opposite!
Fortunately, this is easy to fix - we just need to multiply the value by -1 and can interpret the value as an error π€·ββοΈ
π
If the photo is labeled as no being a bird, then we have Y=0 and so the whole term becomes 0.
That's why we have the second part - the negative case. Here we just take 1-Y and 1-ΕΆ for the probabilities. We are interested in the probability of the photo not being a bird.
π
Combining both we get the error for one data sample (one photo). Note that one of the terms will always be 0, depending on how the photo is labeled.
This is actually the case if we have more than 2 classes as well when using one-hot encoding!
OK, almost done with that part π
Now, you should have a feeling of how the core of the formula works, but why do we use a logarithm?
I won't go into detail, but let's just say this is a common way to formulate optimization problems in math - the logarithm makes all multiplications to sums.
Now the rest π
We know how to compute the loss for one sample, so now we just take the mean over all samples in our dataset (or minibatch) to compute the loss.
Remember - we need to multiply everything by -1 so that we can invert the value and interpret it as a loss (low good, high bad).
π
Where to find it in your ML framework?
The Cross-Entropy Loss is sometimes also called Log Loss or Negative Log Loss.
And if it is easier for you to read code than formulas, here is a simple implementation and two examples of a good (low loss) and a bad classifier (high loss).
Every Friday I repost one of my old threads so more people get the chance to see them. During the rest of the week, I post new content on machine learning and web3.
If you are interested in seeing more, follow me @haltakov
β’ β’ β’
Missing some Tweet in this thread? You can try to
force a refresh
How can I prove to you that I know a secret, without revealing any information about the secret itself?
This is called a zero-knowledge proof and it is a super interesting area of cryptography! But how does it work?
Thread π§΅
Let's start with an example
Peggie and Victor travel between cities A and B. There are two paths - a long path and a short path. The problem is that there is a gate on the short path for which you need a password.
Peggie knows the password, but Victor doesn't.
π
Victor wants to buy the password from Peggie so he can use the short path.
But what if Victor pays Peggie, but she lied and she didn't know the password? How can Peggie prove to Victor she knows the password, without actually revealing it?
Rescue Toadz looks like a regular NFT collection at first - you can mint a toad and you get an NFT in your wallet.
100% of the mint fee is directly sent to @Unchainfund - an organization that provides humanitarian aid to Ukraine and that has already raised $9M!
π
@ianbydesign@RescueToadz@Unchainfund@cryptoadzNFT The process is completely trustless and automatic! All the logic is coded in the smart contract which cannot be changed and which everybody can inspect.
You trust the code, not us! We have no way to steal the funds even if we wanted (we don't π).
Principal Component Analysis is a commonly used method for dimensionality reduction.
It's a good example of how fairly complex math can have an intuitive explanation and be easy to use in practice.
Let's start from the application of PCA π
Dimensionality Reduction
This is one of the common uses of PCA in machine learning.
Imagine you want to predict house prices. You get a large table of many houses and different features for them like size, number of rooms, location, age, etc.
Some features seem correlated π
Correlated features
For example, the size of the house is correlated with the number of rooms. Bigger houses tend to have more rooms.
Another example could be the age and the year the house was built - they give us pretty much the same information.
For regression problems you can use one of several loss functions:
βͺοΈ MSE
βͺοΈ MAE
βͺοΈ Huber loss
But which one is best? When should you prefer one instead of the other?
Thread π§΅
Let's first quickly recap what each of the loss functions does. After that, we can compare them and see the differences based on some examples.
π
Mean Square Error (MSE)
For every sample, MSE takes the difference between the ground truth and the model's prediction and computes its square. Then, the average over all samples is computed.