1
$\begingroup$

I have this dataset where one of the columns (features) is an array of delays codes. Sometimes the array has got 1 single code and sometimes up to 5 codes. The codes can appear just once in the array or multiple times.

Is there any way to solve this problem?

I want to add that I am actually planing to use xgboost, but I ask about decision tree since xgboost is based on decisions trees and I believe the answer can be extrapolated

$\endgroup$
4
  • 2
    $\begingroup$ Every machine learning algorithm can only handle numbers provided in structured form. Under the hood some of the functions and packages for ML are able to transform the data that comes in other formats so that they fit the requirements, this would however be specific for some particular implementation, so off-topic in here. $\endgroup$
    – Tim
    Commented Aug 9, 2018 at 11:43
  • $\begingroup$ @Tim thanks for the feedback. Should I close this question for off-topic? $\endgroup$ Commented Aug 9, 2018 at 11:46
  • 1
    $\begingroup$ It's only off topic if you're primarily asking about how to use particular software packages. If you're asking about whether/how decision trees in general could handle this type of data, then I think it's an interesting and on-topic question. $\endgroup$
    – user20160
    Commented Aug 9, 2018 at 12:31
  • $\begingroup$ I think the way the question is phrased now is interesting. Perhaps with a little elaboration on how one might go about what @Tim describes, it would be a sufficient answer. $\endgroup$ Commented Aug 9, 2018 at 12:35

1 Answer 1

2
$\begingroup$

The larger part of machine learning in an applied setting is , which describes the task of transforming something that exists in the real world (airline passengers, books, images of objects) into a "format" that a machine learning algorithm can understand. I use "format" in an extremely broad sense, not merely the idea of a "file format" like .png or .tsv.

Feature engineering rarely has an unambiguously "correct" answer. Usually, there are several alternatives which could be successful or better under particular conditions which are peculiar to whatever phenomenon you're studying. Stated another way, the person best suited to answer questions about how to represent your problem to a machine learning algorithm is the person studying the problem, i.e. you.

It sounds like your data is tabular (because you talk about "columns"), and that one "column" can contain one or more categorical variables.

This isn't a problem on its own; it's only a problem when you seek to present this data to machine learning algorithm which anticipates that each column will contain a float.

The standard way to treat categorical data is to encode each category as a binary feature, taking 1 when the category is present and 0 otherwise.

You say that some codes can appear more than once. This is where the ambiguity enters the picture. Is it sufficient to define your binary feature to indicate that the category was present 1 or more times (encoded as 1) or should you count the number of occurrences of a code (encoded as 0 or 1 or 2, etc.)? I don't know. It depends on your problem and the choice of algorithm.

You've written that you are specifically interested in using a tree-based model. Happily, if there is no benefit to encoding the data as counts, then it won't hurt the model to encode the data as counts. To understand what I mean, consider how a binary decision tree works: constructing splits based on some threshold. If the binary encoding works for you data, it will split at some number between 0 and 1, and never any other split. But if the count encoding is important, then the tree might also choose to split at another point that is not between 0 and 1 because that split improves the model. (All of the foregoing applies to the training data; out-of-sample performance could be improved or harmed by either strategy.)

$\endgroup$
1
  • $\begingroup$ Thanks for your feedback. I am actually planning to use Xgboost. Not really decision tree. And I was trying to do something similar to what you mention about indicate how many times the delay_code is present: 0, 1, 2... times. Since for that variable I have around 300 different codes, to avoid creating 300 new features indicating how many times the code is present in the record I was planning to group the delay_codes into 30 bins, depending on their average delay. I wasn't sure if this was the correct approach, but I think in your answer you consider this as a possible solution. $\endgroup$ Commented Aug 12, 2018 at 17:17

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.