Why Normalize Data in Machine Learning? Python and TensorFlow.js Examples

Machine-learning models work with numbers, but the numerical scale of those numbers can make a big difference during training. In this lesson we use a very simple example: student marks ranging from 0 to 100. We convert them to values between 0 and 1 before training a small PASS/FAIL neural network.

For example, 80 marks becomes 0.80. The scale changes, but the meaning of the data does not.

1. Python + TensorFlow Version

The Python example uses NumPy and TensorFlow. It first displays the original marks, normalizes them by dividing by 100, trains a small sigmoid neural network, and finally lets you enter a mark to obtain a PASS/FAIL prediction.

Open Python Program in a New Tab

2. HTML + JavaScript + TensorFlow.js Version

The browser version makes normalization visual and interactive. You can see the original marks beside their normalized values, experiment with your own mark, train a TensorFlow.js model, and then test the model directly in the browser.

Open JavaScript Program in a New Tab

What Should You Notice?

In both programs, normalization is simply: normalized value = original value / 100. Thus 10 becomes 0.10, 40 becomes 0.40, and 90 becomes 0.90. The neural network receives these smaller, consistently scaled values during training.

Normalization does not magically improve every model, and 0-to-1 scaling is not the only possible method. However, keeping numerical features on sensible and comparable scales often makes optimization easier and is an important preprocessing idea to understand when learning AI and machine learning.

Learn With Champak
Run both programs, change the input marks, and observe how the normalized values are used by the TensorFlow models.