The easiest way is to just map them yourself with some Python code after
LabelEncoder - this type of mapping is generally application specific.
Something like:
a[a == 0] = 100
a[a == 1] = 150
a[a == 2] = 155
will do the trick. For many labels, you could loop through a dictionary you
make and set these values:
mapping = {0:100, 1:150, 2:155}
for k, v in mapping:
a[a == k] = v
Kyle
On Thu, Jul 3, 2014 at 3:42 AM, Sheila the angel <[email protected]>
wrote:
> Is there any way to specify the label encoding in
> preprocessing.LabelEncoder() ?
>
> My targets are in string and I want to convert them into numeric values.
> preprocessing.LabelEncoder() encodes always as 0,1,2 while I would like
> specify the numeric code.
>
>
> target_str = ['setosa', 'versicolor', 'virginica', 'setosa', 'setosa',
> 'versicolor']
>
>
> le = preprocessing.LabelEncoder()
>
> target_int =le.fit(target_str).transform(target_str)
>
>
> target_int
>
> Out[10]: array([0, 1, 2, 0, 0, 1])
>
>
> I would like to specify targets as
>
>
> target_code = {'setosa':100, 'versicolor': 150, 'virginica':155}
>
>
> and want to convert target_str to target_int as
>
>
> target_int
>
> Out[11]: array([100, 150, 155, 100, 100, 150])
>
>
>
> Thanks
>
> --
> Sheila
>
>
> ------------------------------------------------------------------------------
> Open source business process management suite built on Java and Eclipse
> Turn processes into business applications with Bonita BPM Community Edition
> Quickly connect people, data, and systems into organized workflows
> Winner of BOSSIE, CODIE, OW2 and Gartner awards
> http://p.sf.net/sfu/Bonitasoft
> _______________________________________________
> Scikit-learn-general mailing list
> [email protected]
> https://lists.sourceforge.net/lists/listinfo/scikit-learn-general
>
>
------------------------------------------------------------------------------
Open source business process management suite built on Java and Eclipse
Turn processes into business applications with Bonita BPM Community Edition
Quickly connect people, data, and systems into organized workflows
Winner of BOSSIE, CODIE, OW2 and Gartner awards
http://p.sf.net/sfu/Bonitasoft
_______________________________________________
Scikit-learn-general mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/scikit-learn-general