Skip to content Skip to sidebar Skip to footer

Scikit-learn: How To Normalize Row Values Horizontally?

I would like to normalize the values below horizontally instead of vertically. The code read csv file provided after the code and output a new csv file with normalized values. How

Solution 1:

You can simply operate on the transpose, and take a transpose of the result:

minmax_scale = preprocessing.MinMaxScaler(feature_range=(0, 1)).fit(x.T)

X_minmax=minmax_scale.transform(x.T).T

Solution 2:

Oneliner answer without use of sklearn:

X_minmax = np.transpose( (x-np.min(x,axis=1))/(np.max(x, axis=1)-np.min(x,axis=1)))

This is about 8x faster than using the MinMaxScaler from preprocessing.

Post a Comment for "Scikit-learn: How To Normalize Row Values Horizontally?"