To my understanding pandas.factorize only works for the static case where no unseen variables can occur. <br><div class="gmail_quote"><div dir="ltr">Georg Heiler <<a href="mailto:georg.kf.heiler@gmail.com">georg.kf.heiler@gmail.com</a>> schrieb am Mo. 7. Aug. 2017 um 08:40:<br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">I will need to look into factorize. Here is the result from profiling the transform method on a single new observation <a href="https://codereview.stackexchange.com/q/171622/132999" target="_blank">https://codereview.stackexchange.com/q/171622/132999</a><br><br><br>Best Georg <br><div class="gmail_quote"><div dir="ltr">Sebastian Raschka <<a href="mailto:se.raschka@gmail.com" target="_blank">se.raschka@gmail.com</a>> schrieb am So. 6. Aug. 2017 um 20:39:<br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">> performance of prediction is pretty lame when there are around 100-150 columns used as the input.<br>
<br>
you are talking about computational performance when you are calling the "transform" method? Have you done some profiling to find out where your bottle neck (in the for loop) is? Just one a very quick look, I think this<br>
<br>
data.loc[~data[column].isin(fittedLabels), column] = str(replacementForUnseen)<br>
<br>
is already very slow because fittedLabels is an array where you have O(n) lookup instead of an average O(1) by using a hash table. Or is the isin function converting it to a hashtable/set/dict?<br>
<br>
In general, would it maybe help to use pandas' factorize? <a href="https://pandas.pydata.org/pandas-docs/stable/generated/pandas.factorize.html" rel="noreferrer" target="_blank">https://pandas.pydata.org/pandas-docs/stable/generated/pandas.factorize.html</a><br>
For predict time, say you have only 1 example for prediction that needs to be converted, you could append prototypes of all possible values that could occur, do the transformation, and then only pass the 1 transformed sample to the classifier. I guess that could be even slow though ...<br>
<br>
Best,<br>
Sebastian<br>
<br>
> On Aug 6, 2017, at 6:30 AM, Georg Heiler <<a href="mailto:georg.kf.heiler@gmail.com" target="_blank">georg.kf.heiler@gmail.com</a>> wrote:<br>
><br>
> @sebastian: thanks. Indeed, I am aware of this problem.<br>
><br>
> I developed something here: <a href="https://gist.github.com/geoHeil/5caff5236b4850d673b2c9b0799dc2ce" rel="noreferrer" target="_blank">https://gist.github.com/geoHeil/5caff5236b4850d673b2c9b0799dc2ce</a> but realized that the performance of prediction is pretty lame when there are around 100-150 columns used as the input.<br>
> Do you have some ideas how to speed this up?<br>
><br>
> Regards,<br>
> Georg<br>
><br>
> Joel Nothman <<a href="mailto:joel.nothman@gmail.com" target="_blank">joel.nothman@gmail.com</a>> schrieb am So., 6. Aug. 2017 um 00:49 Uhr:<br>
> We are working on CategoricalEncoder in <a href="https://github.com/scikit-learn/scikit-learn/pull/9151" rel="noreferrer" target="_blank">https://github.com/scikit-learn/scikit-learn/pull/9151</a> to help users more with this kind of thing. Feedback and testing is welcome.<br>
><br>
> On 6 August 2017 at 02:13, Sebastian Raschka <<a href="mailto:se.raschka@gmail.com" target="_blank">se.raschka@gmail.com</a>> wrote:<br>
> Hi, Georg,<br>
><br>
> I bring this up every time here on the mailing list :), and you probably aware of this issue, but it makes a difference whether your categorical data is nominal or ordinal. For instance if you have an ordinal variable like with values like {small, medium, large} you probably want to encode it as {1, 2, 3} or {1, 20, 100} or whatever is appropriate based on your domain knowledge regarding the variable. If you have sth like {blue, red, green} it may make more sense to do a one-hot encoding so that the classifier doesn't assumeĀ  a relationship between the variables like blue > red > green or sth like that.<br>
><br>
> Now, the DictVectorizer and OneHotEncoder are both doing one hot encoding. The LabelEncoder does convert a variable to integer values, but if you have sth like {small, medium, large}, it wouldn't know the order (if that's an ordinal variable) and it would just assign arbitrary integers in increasing order. Thus, if you are dealing ordinal variables, there's no way around doing this manually; for example you could create mapping dictionaries for that (most conveniently done in pandas).<br>
><br>
> Best,<br>
> Sebastian<br>
><br>
> > On Aug 5, 2017, at 5:10 AM, Georg Heiler <<a href="mailto:georg.kf.heiler@gmail.com" target="_blank">georg.kf.heiler@gmail.com</a>> wrote:<br>
> ><br>
> > Hi,<br>
> ><br>
> > the LabelEncooder is only meant for a single column i.e. target variable. Is the DictVectorizeer or a manual chaining of multiple LabelEncoders (one per categorical column) the desired way to get values which can be fed into a subsequent classifier?<br>
> ><br>
> > Is there some way I have overlooked which works better and possibly also can handle unseen values by applying most frequent imputation?<br>
> ><br>
> > regards,<br>
> > Georg<br>
> > _______________________________________________<br>
> > scikit-learn mailing list<br>
> > <a href="mailto:scikit-learn@python.org" target="_blank">scikit-learn@python.org</a><br>
> > <a href="https://mail.python.org/mailman/listinfo/scikit-learn" rel="noreferrer" target="_blank">https://mail.python.org/mailman/listinfo/scikit-learn</a><br>
><br>
> _______________________________________________<br>
> scikit-learn mailing list<br>
> <a href="mailto:scikit-learn@python.org" target="_blank">scikit-learn@python.org</a><br>
> <a href="https://mail.python.org/mailman/listinfo/scikit-learn" rel="noreferrer" target="_blank">https://mail.python.org/mailman/listinfo/scikit-learn</a><br>
><br>
> _______________________________________________<br>
> scikit-learn mailing list<br>
> <a href="mailto:scikit-learn@python.org" target="_blank">scikit-learn@python.org</a><br>
> <a href="https://mail.python.org/mailman/listinfo/scikit-learn" rel="noreferrer" target="_blank">https://mail.python.org/mailman/listinfo/scikit-learn</a><br>
> _______________________________________________<br>
> scikit-learn mailing list<br>
> <a href="mailto:scikit-learn@python.org" target="_blank">scikit-learn@python.org</a><br>
> <a href="https://mail.python.org/mailman/listinfo/scikit-learn" rel="noreferrer" target="_blank">https://mail.python.org/mailman/listinfo/scikit-learn</a><br>
<br>
_______________________________________________<br>
scikit-learn mailing list<br>
<a href="mailto:scikit-learn@python.org" target="_blank">scikit-learn@python.org</a><br>
<a href="https://mail.python.org/mailman/listinfo/scikit-learn" rel="noreferrer" target="_blank">https://mail.python.org/mailman/listinfo/scikit-learn</a><br>
</blockquote></div></blockquote></div>