'Error: Expected 2D array, got scalar array instead for OrdinaEncoder in loop
i have such code:
def inv_transform(obj):
return ordinal_encoder.inverse_transform(obj)
for column in X_test[['col1', 'col2', 'col3']]:
X_test[column] = X_test[column].apply(inv_transform)
on execution of which i get an error:
ValueError: Expected 2D array, got scalar array instead: array=1.0. Reshape your data either using array.reshape(-1, 1) if your data has a single feature or array.reshape(1, -1) if it contains a single sample.
Also I have tried this
for column in X_test[['col1', 'col2', 'col3']]:
X_test[[column]] = X_test[[column]].apply(inv_transform)
with the same error.
Any idea what should I do ? Somehow got 2D array from 1D array (i.e. every column in list)? Imho the first snippet should work, but it doesn`t. I am trying to apply method of inverse_transform (from OrdinaEncoder) to only few columns of dataset, say 3 out of 10.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|