I have a dataset regarding a specific junction on a piece of road and the cars that will cross that junction. I am trying to predict the order that cars will pass the specific junction given a set of tabular features. My dataset looks similar to the following:

Target      car1_type  car2_type  car3_type      car1_positionId   car2_positionId   car3_positionId ... 
3,1,2       1          2          3              3                 6                 8 
2,1,3       8          4          9              1                 4                 2 

My features inlcude the type of car (car_type) as well as the position of each car (car_positionId). The position represents a region of road that the car is on. Each row above represents an observed case of 3 cars crossing a junction.

I am trying to predict the target column (the order that the cars will pass over the junction) based on the features given. There is additional complexity in that I also do not know how many cars there will be. There could be just one (trivial case) or there could be up to 20.

My question is what machine learning algorithm could I use to help me predict the order.

  • 1
    $\begingroup$ It's not clear to me what your features represent, actually it looks like they don't provide any information: as far as I understand the cars ids are not features, they're just "names" for the cars. Even the cars positions ids don't seem to represent any particular order, do they? In other words, which indications would a human use in order to guess the target order? $\endgroup$ – Erwan Nov 13 '19 at 11:29
  • $\begingroup$ I have updated the question. Car ids are in fact the type of car (which can be slow or fast etc). For the position, a human would know where the position was and could see which car is furthest away from the junction $\endgroup$ – Daniel Wyatt Nov 14 '19 at 11:28
  • $\begingroup$ @DanielWyatt Is 20 is an actual upper limit or just an example? $\endgroup$ – serali Nov 14 '19 at 11:48
  • $\begingroup$ An example. However the actual upper limit should be around that $\endgroup$ – Daniel Wyatt Nov 14 '19 at 11:51

I think you have 2 different ways to approach this problem. But the variable number of features and targets make it challenging. I am not aware of any well established ways to treat such issues but I find the problem interesting and would like to share my opinion.

The first way is to define this as a classification problem. The order of cars matters, in the sense that it is loss of a problem if you classify car in class 1 as a class 2, compared to identifying it as a class - say - 15 in a 20 car case. This is an "Ordinal Classification" problem and as far as I know, there is no established loss function for this. But someone implemented their own and shared it, but I never used it so I don't know how it works. Of course, this is not a must a you can use a regular classifier loss function.

Now you have to deal with variable number of cars. If you have a maximum possible number of cars present at each time, you can use that to define the number of features in your Neural Network. For the cases where there are less number of cars you can set the features associated with the non-existent cars to a number (for example -1), and put a constraint to the loss function such that cars with such features are ordered after the present cars only, and drop them at the end. This might sound complicated, it certainly is so to type it here; so I hope I was able to explain it.

The second possible way is to define a clustering problem. In order to deal with variable car numbers at each case you can define the total number of cars as an additional feature. In the example you give above they all will have a car number feature = 3. And then use any clustering algorithm you can think of, such as KNN with K=max number of cars. But this also has drawbacks: When 3 cars are present, cars can be clustered as 1,2,3; but they can just as easily be clustered into 4,6,9; or even 1,1,1. And I have no idea how you would handle such an issue. Problems with the classification algorithm defined above is less likely to cause such problems, but it is much more difficult to implement.

I know these options are far from optimal so I really hope someone else comes up with a better answer. Good luck.


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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