3
$\begingroup$

I'm pretty new into Machine Learning and I was wondering if certain algorithms/models (ie. logistic regression) can handle lists as a value for their variables. Until now I've always used pretty standard datasets, where you have a couple of variables, associated values and then a classification for those set of values (view example 1). However, I now have a similar dataset but with lists for some of the variables (view example 2). Is this something logistic regression models can handle, or would I have to do some kind of feature extraction to transform this dataset into just a normal dataset like example 1?

Example 1 (normal):

+---+------+------+------+-----------------+
|   | var1 | var2 | var3 | classification  |
+---+------+------+------+-----------------+
| 1 |    5 |    2 |  526 |               0 |
| 2 |    6 |    1 |  686 |               0 |
| 3 |    1 |    9 |  121 |               1 |
| 4 |    3 |   11 |   99 |               0 |
+---+------+------+------+-----------------+

Example 2 (lists):

+-----+-------+--------+---------------------+-----------------+--------+
|     | width | height |       hlines        |      vlines     |  class | 
+-----+-------+--------+---------------------+-----------------+--------+
| 1   | 115   | 280    | [125, 263, 699]     | [125, 263, 699] |  1     |      
| 2   | 563   | 390    | [11, 211]           | [156, 253, 399] |  0     |   
| 3   | 523   | 489    | [125, 255, 698]     | [356]           |  1     |      
| 4   | 289   | 365    | [127, 698, 11, 136] | [458, 698]      |  0     |       
| ... | ...   | ...    | ...                 | ...             | ...    |      
+-----+-------+--------+---------------------+-----------------+--------+

To provide some additional context on my specific problem. I'm attempting to represent drawings. Drawings have a width and height (regular variables) but drawings also have a set of horizontal and vertical lines for example (represented as a list of their coordinates on their respective axis). This is what you see in example 2. The actual dataset I'm using is even bigger, also containing variables which hold lists containing the thicknesses for each line, lists containing the extension for each line, lists containing the colors of the spaces between the lines, etc. In the end I would like to my logistic regression to pick up on what result in nice drawings. For example, if there are too many lines too close the drawing is not nice. The model should pick up itself on these 'characteristics' of what makes a nice and a bad drawing.

I didn't include these as the way this data is setup is a bit confusing to explain and if I can solve my question for the above dataset I feel like I can use the principe of this solution for the remaining dataset as well. However, if you need additional (full) details, feel free to ask!

$\endgroup$
3
  • 2
    $\begingroup$ Welcome to Cross Validated! I think you'll need to explain what these lists represent & how you want logistic regression to handle them. $\endgroup$ Commented May 9, 2020 at 12:59
  • 2
    $\begingroup$ Added additional details :) $\endgroup$
    – Astarno
    Commented May 9, 2020 at 13:15
  • 3
    $\begingroup$ There is a tag feature-engineering you should look into. Logistic regression cannot use this lists as is, you need to decide on aspects which are important (you hinted at number, density) and calculate those. And consider add that tag! $\endgroup$ Commented May 9, 2020 at 15:40

1 Answer 1

0
$\begingroup$

Suppose the variable hlines instead consisted of entries like "cat" or "fox" or "anaconda". You might say each of these values is a "list" of characters. In regression such a variable would function in the same way as your hlines would. It's currently a nominal, or categorical, variable.

Now, as @kjetil b halvorsen indicated, if you suspected that the elements separated by commas were important to prediction -- e.g., if an entry containing "125" needed to be flagged as such, or one that fell within a specific range -- you could create a set of dummy variables (0 for no, 1 for yes) for any such elements that are of interest. You could then use those variables as predictors instead of the current hlines variable. It will require thought; there's likely no automatic way you'll get an algorithm to create valid meanings out of these lists. The hlines variable contains information, but it does not effectively express it in a way that most models, logistic or otherwise, can use.

$\endgroup$

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.