What is maximum absolute scaling in machine learning?
In the maximum absolute scaling, each value of a numerical column is divided by the maximum value of the column. And the result is used to replace the original value of the column. In other words,
How to perform maximum absolute scaling using sklearn?
We can use the MaxAbsScaler class from the sklearn.preprocessing module to perform maximum absolute scaling in Python.
Let’s read the titanic dataset. The age column of the dataset contains the age of the passengers. Let’s perform the maximum absolute scaling on the age column of the dataset. We can use the following Python code for that purpose.
import seaborn from sklearn.preprocessing import MaxAbsScaler df = seaborn.load_dataset("titanic") max_abs_scaler = MaxAbsScaler() df[["age"]] = max_abs_scaler.fit_transform(df[["age"]]) print(df.head())
Here, we are using the fit_transform() method of the MaxAbsScaler to learn from the dataset and then, transform the dataset. The output of the above program will be:
survived pclass sex age ... deck embark_town alive alone 0 0 3 male 0.2750 ... NaN Southampton no False 1 1 1 female 0.4750 ... C Cherbourg yes False 2 1 3 female 0.3250 ... NaN Southampton yes True 3 1 1 female 0.4375 ... C Southampton yes False 4 0 3 male 0.4375 ... NaN Southampton no True [5 rows x 15 columns]






0 Comments