I need to design an algorithm such that it handles the request for shift swapping.

The algorithm will recommend a list of people who are more likely to swap that shift with the person by analyzing previous data.

Can anyone list the techniques that will help me to do this or a good starting point?

I was thinking about training a Naive Bayes Classifier and using Mahout for generating recommendations.


2 Answers 2


You might not even need a classifier.

I would devise a scoring function, based on analysis of the previous data you have. Each user gets a score based on features like

  • how many times in the past has this user swapped a shift with somebody else?
  • how many times has the user swapped with the current user?
  • how many times has the user swapped this particular shift?

For each criterion you add a number of points to the score; the second one might be weighted higher that the first one. Then the person with the highest score is most likely to switch shifts with your current user.

The main question is the design of the scoring function, but I don't think you'd need to go into all the overkill of setting up a classifier; just think which criteria would make someone more likely to swap, and encode them directly. This has the advantage that it's transparent, ie you can always see why someone got recommended, and you can tweak your scoring method if the results are not quite what you'd want. This is often hard to do with ML classifiers.

  • $\begingroup$ Hi Oliver, I understand your comment regarding overkill. Actually I started learning AI/ML recently, I thought the best way to grasp is to learn by building something and asking questions in the process, so I thought of above generic problem involving shift swapping, this will include many constraint like a cashier would only swap with other cashier and so on. So I was thinking to apply ML/AI to learn it. $\endgroup$
    – Paras
    Commented May 15, 2018 at 4:39

The first thing to think about is how you might identify a likely swapper without a computer, and what characteristics might identify that swapper, e.g. what role they have, how many times they swapped in the last year, 6 months, 6 weeks etc, how many times they've taken each shift, how long they've been around, do they have a family, etc. In this initial step you don't need to figure out HOW those characteristics identify the swapper, just that they might help to identify them.

Once those "features" have been identified, you are ready to build a model of how you might identify a likely swapper. You would take a few examples of instances where two individuals swapped shifts, and map out the characteristics of each individual. This will identify a number of instances of your positive class. Flesh our your dataset with all other combinations of individuals and shifts which are, of course, instances where no switch occurred. These are your negative class.

Before doing any modeling, check to see if any of your features are highly correlated with your target variable. If there are a couple of features that are highly correlated, you may not even need to use machine learning. Remember, machine learning is just using an algorithm to learn a pattern. If you can learn the pattern without an algorithm, you're done.

If you're still looking at several features that may be involved in a complex model to identify who might swap shifts, then you can start trying various model algorithms. To start with you could try logistic regression, random forest, naïve bayes, and SVM. Split your data and try and overfit on your training set. If you manage to overfit, you've got a chance. Start scaling back the features and try and find something that generalizes.


You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .