0
$\begingroup$

I am just getting into trying some machine learning. As a C# developer I have played around with ML.NET. I'd now like try and see if it can help with a real world problem.

We have a system that invites staff members to work shifts in multiple hospitals, if a staff member is interested they contact our admin team and are then assigned to the shift.

Many shifts are difficult to assign staff to due to the date/day, location, the hours and of course the pay available. We therefore often have to increase the rate paid per hour. When the rate is increased there is a much better chance the shift will be filled.

My shift class is displayed below.

    // SHIFT CLASS
    int shiftID 
    int locationID
    int shiftGradeID 

    DateTime shiftStartDate 
    DateTime shiftEndDate 

    decimal hourlyRate 
    decimal hours 

    int assignedLocumID 

Using the data above I'd appreciate any advice or insight to help work out;

Based on location, date (day, month), start time, end time, grade, hourly rate and hours, how can I work out the percentage chance of a shift being filled.

Ideally I'd like to try something out using ML.NET, however I'm not sure where to start. I have 5 years of data to train the model. Appreciate any help you can provide.

$\endgroup$
0
$\begingroup$

StatsSorceress has rightly indicated using logistic regression. This is almost a text book use case of the method. If you are also looking for sample code then u could look up this example (it uses ML.NET) https://medium.com/machinelearningadvantage/use-c-and-ml-net-machine-learning-to-predict-taxi-fares-in-new-york-519546f52591

A few differences for you would be that your "label" or the value that you are trying to predict might need to be calculated. For e.g. in the blog above the user has a ready made label , taxi fares , that she wanted to predict. In your case you are looking at a % value for whether the shift will be filled or not. Hence you will have to add an additional column called "%filled_or_something" which can be calculated by a simple SQL query grouping together your input features (day, month, hours, start time, end time, wages etc). So for e.g if you have 20 records for "Sunday / March / 6 (hours) / 23:00 / 06:00 / $13 (per hour)" and it was filled for all those 20 days then the column would read 100% BUT if it was filled only for 10 out of those 20 records it would read 50%.

Of course, this would also beg the question, that if all you need to do is the above , then given that all the features are finite why couldn't we simply just group all the unique combination and find the % and just use this value itself ? The answer , according to me, is that LR also indicates how important every feature is, so for e.g. if you were to introduce new days / new shift timings / more number of hours, the LR model should be able to predict even those since it understand the weights associated with every feature.

This should enable you to finally use a logistic regression model as explained in the blog above. Hope this helps in someway :)

$\endgroup$
0
$\begingroup$

If you're looking for code, I'm not familiar with C#. My answer will focus on theory.

tl;dr most machine learning-related packages have a built-in logistic regression function of some sort. That's what I'm recommending here.

More detail:

I would start with a basic model and work my way up. It sounds like this is something you can figure out using a regression model.

Based on your question: "Based on location, date (day, month), start time, end time, grade, hourly rate and hours, how can I work out the percentage chance of a shift being filled?", I understand you want:

  • output: probability of shift getting filled
  • input: location, date, start time, end time, grade, hourly rate, hours (these are $x$'s below)

If you're familiar with logistic regression:

$$log\left(\frac{p}{1-p}\right) = \beta_0 + \beta_1x_1 + \beta_2x_2 + ... + \beta_kx_k$$

the output of this model is the log odds of a single shift being filled (versus not filled). Note this can be rewritten as:

$$p = \frac{e^{\beta_0 + \beta_1x_1 + \beta_2x_2 + ... + \beta_kx_k}}{1-e^{\beta_0 + \beta_1x_1 + \beta_2x_2 + ... + \beta_kx_k}}$$

Where $p$ is the probability that the shift gets filled.

I would start by fitting one logistic regression model for each shift.

Be careful: multinomial regression would give you the probability of 1 shift out of k possible shifts being filled, but I don't think that's what you're looking for.

After seeing how well that worked (comparing the model predicted results to the actual percentages in the data), if necessary I would build a conditional model to take into account the probability of filling a shift, given other shifts have already been filled. Not sure how I'd do that yet, but hopefully this gives you a starting point!

EDIT based on the answer from Vikram Murthy:

I realize I forgot to mention: your response variable in this case would be 0 or 1 indicating whether a shift was filled or not. So for each shift, you would have a column indicating whether that shift was filled. That's the column being predicted. This is similar to using "dummy variables".

For example, if you have two shifts, your columns would be:

loc, day, month, starttime, endtime, grade, hourlyrate, hours, shift1_f, shift2_f

So your data might look something like this:

loc, day, month, starttime, endtime, grade, hourlyrate, hours, shift1_f, shift2_f
A, 1, 2, 12:00, 8:00, 1, 34.25, 8, 1, 0
A, 1, 2, 12:00, 8:00, 1, 34.25, 8, 0, 1
A, 1, 2, 12:00, 8:00, 1, 34.25, 8, 1, 1
A, 1, 2, 12:00, 8:00, 1, 34.25, 8, 0, 0

In this setup, this would indicate that shift 1 was filled in the first case, shift 2 was filled in the second case, both shifts in the third case, and no shifts in the last case.

Your two logistic regression models would be set up like this:

shift1_f = loc + day + month + starttime + endtime + grade + hourlyrate + hours

and

shift2_f = loc + day + month + starttime + endtime + grade + hourlyrate + hours

The proportions would be figured out automatically by the program; it's not necessary to figure them out yourself and enter them in any application of logistic regression that I've seen.

$\endgroup$

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.