Skip to content
Advertisement

Why is the code not able to approximate the square function?

WHy does the following code not work as a square approximator? I am getting weird dimensions. When I tried plotting loss, the graph somehow does not show anything. I am a beginner with pytorch, so I would be grateful for any help.

JavaScript

Advertisement

Answer

Your data is ranging from -10000 to 10000! You need to standardize your data, otherwise you won’t be able to make your model learn:

JavaScript

Additionally, you could normalize your input with:

JavaScript

After 100 epochs:

enter image description here

User contributions licensed under: CC BY-SA
7 People found this is helpful
Advertisement