Can logistic regression be used for variables containing lists?

Issue

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!

Thanks in advance!

Solution

No, it cannot directly handle that kind of input structure. The input must be a homogeneous 2D array. What you can do, is come up with new features that capture some of the relevant information contained in the lists. For instance, for the lists that contain the coordinates of the lines along an axis (other than the actual values themselves), one could be the spacing between lines, or the total amount of lines or also some statistics such as the mean location etc.

So the way to deal with this is through feature engineering. This is in fact, something that has to be dealt with in most cases. In many ML problems, you may not only have variables which describe a unique aspect or feature of each of the data samples, but also many of them might be aggregates from other features or sample groups, which might be the only way to go if you want to consider certain data sources.

Answered By – yatu

Answer Checked By – Dawn Plyler (AngularFixing Volunteer)

Leave a Reply

Your email address will not be published.