MaxAbsScaler
To bring values into range [-1, 1]
we have to use the next formula:
Here we have the following values:
- x_scaled - normalized feature element,
- x - unnormalized feature element,
- max(x) -- maximum feature element.
There is a function in the sklearn library that normalizes data according to the formula given above: MaxAbsScaler()
. In order to work with this function, it must first be imported in such a way:
1from sklearn.preprocessing import MaxAbsScaler
Let's look at an example of how we apply this normalization to a very simple array.
12345678910from sklearn.preprocessing import MaxAbsScaler data = [[10, 5, -6],[11, -9, 4],[-10, 0, 1]] # Normalizer initialization scaler = MaxAbsScaler() # Dataset transfer and transformation scaler.fit(data) scaled_data = scaler.transform(data) print('Data before normalization', data) print('Data after normalization', scaled_data)
If you run this code you will get two different arrays: before and after normalization. And this function really works, because you can make sure that data after using MaxAbsScaler()
function really lie within an interval [-1, 1]
. Look below.v
It's time to practice!
Swipe to start coding
You have a numpy array. Please, normalize this array into range [-1, 1]
.
Oplossing
Bedankt voor je feedback!
single
Vraag AI
Vraag AI
Vraag wat u wilt of probeer een van de voorgestelde vragen om onze chat te starten.
Vat dit hoofdstuk samen
Explain code
Explain why doesn't solve task
Awesome!
Completion rate improved to 12.5
MaxAbsScaler
Veeg om het menu te tonen
To bring values into range [-1, 1]
we have to use the next formula:
Here we have the following values:
- x_scaled - normalized feature element,
- x - unnormalized feature element,
- max(x) -- maximum feature element.
There is a function in the sklearn library that normalizes data according to the formula given above: MaxAbsScaler()
. In order to work with this function, it must first be imported in such a way:
1from sklearn.preprocessing import MaxAbsScaler
Let's look at an example of how we apply this normalization to a very simple array.
12345678910from sklearn.preprocessing import MaxAbsScaler data = [[10, 5, -6],[11, -9, 4],[-10, 0, 1]] # Normalizer initialization scaler = MaxAbsScaler() # Dataset transfer and transformation scaler.fit(data) scaled_data = scaler.transform(data) print('Data before normalization', data) print('Data after normalization', scaled_data)
If you run this code you will get two different arrays: before and after normalization. And this function really works, because you can make sure that data after using MaxAbsScaler()
function really lie within an interval [-1, 1]
. Look below.v
It's time to practice!
Swipe to start coding
You have a numpy array. Please, normalize this array into range [-1, 1]
.
Oplossing
Bedankt voor je feedback!
Awesome!
Completion rate improved to 12.5single