edited by
1,597 views
1 1 vote

Please see example from the following link.

The question is leaning towards a programming code solution in Python as the link above shows. Involving sklearn and any other Python libraries.

Relative to the link, could there be a manual solution for L1 as well?

Could x include more dimensions for manual solutions? For example:

([[4,6,9,3], [8,1,2,5]])

25% Accept Rate Accepted 1 answers out of 4 questions

2 Answers

Best answer
2 2 votes

Found out the answer, thanks to a few reference sources.

Import the libraries:

import numpy as np
from sklearn.preprocessing import Normalizer as NRM

Manual L1 normalization:

If the data contained negative numbers, abs will find the correct value.

 

data = abs(np.array([[5, 8, 12, 15], [7,6,1,2], [4,1,0,3]]))
l1 = np.linalg.norm(data, ord=1, axis=1)
x_norm2 = data / l1[:,None]
x_norm2

"Undo" L1 normalization (turn normalization to raw numbers from data set):

Using the same variables as above

results = x_norm2*l1[:,None]
results

To verify the results, use the sklearn library:

normalizer_x = NRM(norm = "l1")
x_norm = normalizer_x.transform(data)
print(x_norm)

Results:

Here it is on repl.it.

References:

Stackoverflow

SciPy

edited by
0 0 votes
I think if we have the normalization factor, it will be easy, right? Do you have any specific example?

Related questions

3 3 votes
2 answers 2 answers
3.2k
3.2k views
akm asked Sep 25, 2018
3,239 views
How do I use the information provided in this link to apply in defining a L1-norm and L2-norm function in python?
0 0 votes
1 1 answer
894
894 views
rakesh asked Feb 10, 2020
894 views
I have a result string like this A, C, D, F, B,In my DB I have 10,000+ combinations like this 1. A, B, C, D 2. A, C, B, I, D, W, Z etc.... Now I want to search for my ...
0 0 votes
0 0 answers
1.5k
1.5k views
Frenzy asked Apr 27, 2022
1,522 views
I have a dataset with 7 labels in the target variable.X = data.drop('target', axis=1) Y = data['target'] Y.unique()array(['Normal_Weight', 'Overweight_Level_I', 'Overweig...
0 0 votes
0 0 answers
1.4k
1.4k views
nuroxyjames asked Jun 2, 2022
1,425 views
Is it possible to make a forecast of a future value of Air Temperature using Fast Fourier Transform, if yes, what should be the process or how you'll be able to do it. Th...
0 0 votes
0 0 answers
412
412 views
aaditi asked Nov 23, 2020
412 views