What is mean normalization in machine learning?
In our previous article, we discussed min-max normalization. Mean normalization is very similar to min-max normalization. The difference is instead of the minimum value, the mean value of the column is subtracted in the numerator. The denominator is the same, i.e. the difference between the maximum and the minimum value.
In other words, the mean value of a numerical column is subtracted from each value of the column. And then, the result is used as a numerator. Then, the minimum value of the column is subtracted from the maximum value of the column. And the result is used as a denominator. We divide the numerator by the denominator and the result is used to replace the value of the column.
How to perform mean normalization using Python?
Let’s read the titanic dataset. The age column of the dataset contains the age of the passengers. We can use the following Python code to perform mean normalization on the age column of the dataset.
import seaborn df = seaborn.load_dataset("titanic") mean_age = df["age"].mean() max_age = df["age"].max() min_age = df["age"].min() df["age"] = (df["age"] - mean_age)/(max_age - mean_age) print(df.head())
The output of the above program will be:
survived pclass sex age ... deck embark_town alive alone 0 0 3 male -0.153061 ... NaN Southampton no False 1 1 1 female 0.165025 ... C Cherbourg yes False 2 1 3 female -0.073540 ... NaN Southampton yes True 3 1 1 female 0.105383 ... C Southampton yes False 4 0 3 male 0.105383 ... NaN Southampton no True [5 rows x 15 columns]






0 Comments