In Spyder, I print the first row of my matrix and I get:

*[3 'male' 22.0 1 7.25]*

And then I want to encode the second column in this matrix as a categorical 
variable. My code for that is:

*from sklearn.preprocessing import LabelEncoder, OneHotEncoder*
*labelencoder_X = LabelEncoder()*
*X[:, 1] = labelencoder_X.fit_transform(X[:, 1])*
*onehotencoder = OneHotEncoder(categorical_features = [1])*
*X = onehotencoder.fit_transform(X).toarray() *

This workds because when I print the first row again, I get:

*[ 0.    1.    3.   22.    1.    7.25]*

You can see that gender has taken over the first two columns. The first 
column has a 0, and second column has a 1, so this is how "males" are 
categorized. The first two column values would be 1, 0 if gender is female. 

The strange thing is when I run this exact same code in Jupyter notebook, I 
get a completely different output that doesn't make sense. I get:

*[ 0.      0.      1.      1.     22.      1.      7.25  ]*

Why is my output with the Jupyter notebook different? How can I make it the 
same as my output in Spyder?

-- 
You received this message because you are subscribed to the Google Groups 
"spyder" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
Visit this group at https://groups.google.com/group/spyderlib.
For more options, visit https://groups.google.com/d/optout.

Reply via email to