0
$\begingroup$

I wrote this code trying to encode male and female gender in two different columns but keep getting an error message

code:

from sklearn.preprocessing import OneHotEncoder
onehotencoder=OneHotEncoder(categorical_features=[1])
x= onehotencoder.fit_transform(x).toarray()
x

The error message:

ValueError: Shape mismatch: if categories is an array, 
it has to be of shape (n_features,).
$\endgroup$
2
  • 3
    $\begingroup$ Welcome to DS, Yinka. What are the inputs? what is the expected output? The error alone doesn't help much. If you can't give the actual data, can you make representative "toy" data that shows the key points? What is dim(x)? What is type? If its open, which data set is it pulled from? Why do you think that python doesn't like the shape? Is it formed as a tensor? $\endgroup$ Oct 26 at 13:16
  • $\begingroup$ Have a look here: ValueError: Shape mismatch: if categories is an array, it has to be of shape (n_features,) $\endgroup$ Oct 26 at 17:23

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy