When i dont scale images in 0-1 range
images= np.array(images, dtype="uint8")
images are in 0-255 ( int ) The loss show unusual behaviour, very high spikes.
to prevent i need to add images = images/255.
So, why is it necessary to convert data into float (0 - 1), and int causing error. 0-255 should have also worked.
High Loss in SVM
Hello @mohituniyal2010,
Such a behaviour can have multiple causes. But the very first that comes into our mind or you can say, the reason that is most occuring is the scale of your value and those hefty multiplications and gradient updates.
If you carefully look at the gradients, they are multiplied by the input value X. So if the input value is of a high scale. It can sure explode the gradients or the error. Eventually its all more multiplication and more multiplication.
To be more clear, take the situation when the training is starting, like the 1st epoch, there, the weights are pure random. At that case, the errors will be at the maximum that your algo will ever touch, assuming proper hyperparameters. In that case, such a huge error can either overflow or as you said, can be huge enough to give the programmer a shock and as soon as you reduced the scale to 0-1, the scale of those multiplication changed as well.
Hope you got an understanding of why your errors got super high.
Happy Learning
Thanks
so, where ever we are using gradient descent, we should normalize our data in smaller range, otherwise multiplication of X values will cause higher error.
But, in the image classification video, and while coding also i saw the array had 2 options either -
- float values between 0 - 1
- int values between 0 - 255
prateek bhaiya chose float values, so if it cant handle 0-255 range of values then why the array is suggesting for int values as well?
Hello @mohituniyal2010,
This has nothing to do with the array being int or float. Its only the scale of your input values that we are concerned about. You can even use the scale 0-255 if you know how to handle the high errors(if any). Also, normalizing/standardizing the data before applying an algorithm is a highly appreciated technique.
I can now relate this better with my experiments results.
Thanks
I hope I’ve cleared your doubt. I ask you to please rate your experience here
Your feedback is very important. It helps us improve our platform and hence provide you
the learning experience you deserve.
On the off chance, you still have some questions or not find the answers satisfactory, you may reopen
the doubt.