9951 explained code solutions for 126 technologies


python-scikit-learnYeo Johnson transformation example


from sklearn import preprocessing

pt = preprocessing.PowerTransformer(method='yeo-johnson')
data = [[1, 2], [3, 2], [4, 5]]
pt.fit(data)

transformed = pt.transform(data)ctrl + c
from sklearn import

import module from scikit-learn

.PowerTransformer(

create power transformation model

method='yeo-johnson'

use Yeo Johnson transformation method

.fit(

train transformation model

.transform(

transform original data and return transformed data


Usage example

from sklearn import preprocessing
pt = preprocessing.PowerTransformer(method='yeo-johnson')
data = [[1, 2], [3, 2], [4, 5]]
pt.fit(data)
print(pt.lambdas_)
print(pt.transform(data))
output
[ 1.38668178 -3.10053309]
[[-1.31616039 -0.70710678]
 [ 0.20998268 -0.70710678]
 [ 1.1061777   1.41421356]]