I'm also have a problem with OneHotEncoder.
Here is the code I ran:
# This is a test of the one hot encode module with a toy data set.
# I have a 4 x 2 data set. The first column is gender and the
#second column is pclass alread in integer form.
import numpy as np
arr=np.array([[0,2],[1,1],[0,0],[0,1]])
print arr
# so one hot encoder should return a matrix that is 4 x 5 since
# gender has two states and pclass has 3.
from sklearn.preprocessing import OneHotEncoder
enc=OneHotEncoder()
enc.fit(arr)
enc.n_values_
arr1=enc.transform(arr)
print arr1
And here is my output:
[[0 2]
[1 1]
[0 0]
[0 1]]
(0, 4) 1.0
(0, 0) 1.0
(1, 3) 1.0
(1, 1) 1.0
(2, 2) 1.0
(2, 0) 1.0
(3, 3) 1.0
(3, 0) 1.0
This is what I was looking for:
[[1,0,0,0,1]
[0,1,0,1,0]
[1,0,1,0,0]
[1,0,0,1,0]]
Anne Dwyer
On Sat, Mar 30, 2013 at 4:14 AM, <[email protected]> wrote:
> i thought OneHotEncoder solves that.
>
>
>
> Lars Buitinck <[email protected]> schrieb:
>
>> 2013/3/27 Anne Dwyer <[email protected]>:
>>
>>> Just to clarify, you are saying that there is no procedure in scikit that
>>> will transform categorical feature values into numerical values like I was
>>> trying to do here. Correct?
>>
>>
>> Not that I know of. DictVectorizer comes quite close, though.
>>
>>
> --
> Diese Nachricht wurde von meinem Android-Mobiltelefon mit K-9 Mail
> gesendet.
>
>
> ------------------------------------------------------------------------------
> Own the Future-Intel(R) Level Up Game Demo Contest 2013
> Rise to greatness in Intel's independent game demo contest. Compete
> for recognition, cash, and the chance to get your game on Steam.
> $5K grand prize plus 10 genre and skill prizes. Submit your demo
> by 6/6/13. http://altfarm.mediaplex.com/ad/ck/12124-176961-30367-2
> _______________________________________________
> Scikit-learn-general mailing list
> [email protected]
> https://lists.sourceforge.net/lists/listinfo/scikit-learn-general
>
>
------------------------------------------------------------------------------
Own the Future-Intel(R) Level Up Game Demo Contest 2013
Rise to greatness in Intel's independent game demo contest. Compete
for recognition, cash, and the chance to get your game on Steam.
$5K grand prize plus 10 genre and skill prizes. Submit your demo
by 6/6/13. http://altfarm.mediaplex.com/ad/ck/12124-176961-30367-2
_______________________________________________
Scikit-learn-general mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/scikit-learn-general