spectre icon indicating copy to clipboard operation
spectre copied to clipboard

how should OneHotEncoding be used?

Open flamz3d opened this issue 4 years ago • 1 comments

hello, I'm trying to create a dataset and one feature I'd like to encode is WEEKDAY as a one-hot encoded vector

I tried: engine.add(factors.filter.OneHotEncoder(factors.WEEKDAY), "weekday") and engine.add(factors.WEEKDAY.one_hot(), "weekday") seems to be called and encoded properly, however I get an error saying factors cannot return multiple values.

What's the proper way to use the OneHotEncoder filter?

flamz3d avatar Jul 22 '20 12:07 flamz3d

OneHotEncoder factor returns multiple values by class, for example, if you encoding [1,2,2,3], it will return 3 values: [1, 0, 0, 0], [0, 1, 1, 0], [0, 0, 0, 1]

So just use slice []:

onehots = factors.WEEKDAY.one_hot()
for i in range(5):
    engine.add(onehots[i], "weekday{}".format(i+1))

btw: other factors such as RollingLinearRegression also return multiple values (slope and intercept)

Heerozh avatar Jul 22 '20 13:07 Heerozh