- #1
BRN
- 108
- 10
Hi everyone!
I need to inverse an label transform with sklearn. I found this example on web:
With 'inverse_transform' How can I obtain an array with shape (10, 7)?
Thaks!
I need to inverse an label transform with sklearn. I found this example on web:
example:
from sklearn.preprocessing import LabelEncoder
np.random.seed(1)
y = np.random.randint(0, 2, (10, 7))
y = y[np.where(y.sum(axis=1) != 0)[0]]
output::
array([[1, 1, 0, 0, 1, 1, 1],
[1, 1, 0, 0, 1, 0, 1],
[1, 0, 0, 1, 0, 0, 0],
[1, 0, 0, 1, 0, 0, 0],
[1, 0, 0, 0, 1, 1, 1],
[1, 1, 0, 0, 0, 1, 1],
[1, 1, 1, 1, 0, 1, 1],
[0, 0, 1, 0, 0, 1, 1],
[1, 0, 1, 0, 0, 1, 1],
[0, 1, 1, 1, 1, 0, 0]])
example:
le = LabelEncoder()
y_new = le.fit_transform([''.join(str(l)) for l in y])
output::
array([7, 6, 3, 3, 2, 5, 8, 0, 4, 1])
example:
y_old = le.inverse_transform(y_new)
output::
array(['[1 1 0 0 1 1 1]', '[1 1 0 0 1 0 1]', '[1 0 0 1 0 0 0]',
'[1 0 0 1 0 0 0]', '[1 0 0 0 1 1 1]', '[1 1 0 0 0 1 1]',
'[1 1 1 1 0 1 1]', '[0 0 1 0 0 1 1]', '[1 0 1 0 0 1 1]',
'[0 1 1 1 1 0 0]'], dtype='<U15')
With 'inverse_transform' How can I obtain an array with shape (10, 7)?
Thaks!