How to normalize data using NumPy or Pandas

When it comes to machine learning, working with normalized numbers may lead to faster convergence while training the models. Here we will show how you can normalize your dataset in Python using either NumPy or Pandas.


To normalize a NumPy array, you can use:

import numpy as np

data = np.loadtxt('data.txt')

for col in range(data.shape[1]):
    data[:,col] -= np.average(data[:,col])
    data[:,col] /= np.std(data[:,col])

Here data.shape[1] is the number of columns in the dataset, and we are using NumPy to normalize the average and standard deviation of each column to 0 and 1 respectively.


Normalizing a Pandas dataframe is even easier:

import pandas as pd

df = pd.read_csv('data.csv')

df = (df-df.mean())/df.std()

This will normalize each column of the dataframe.

Symbolic regression example with Python visualization

Symbolic regression is a machine learning technique capable of generating models that are explicit and easy to understand.

In this tutorial, we are going to generate our first symbolic regression model. For that we are going to use the TuringBot software. After generating the model, we are going to visualize the results using a Python library (Matplotlib).

Read More