I am in 10th grade and I am looking to use a machine learning model on patient data to find a correlation between the time of week and patient adherence. I have separated the week into 21 time slots, three for each time of day (1 is Monday morning, 2 is monday afternoon, etc.). Adherence values will be binary (0 means they did not take the medicine, 1 means they did). I will simulate training, validation and test data for my model. From my understanding, I can use a logistic regression model to output the probability of the patient missing their medication on a certain time slot given past data for that time slot. This is because logistic regression outputs binary values when given a threshold and is good for problems dealing with probability and binary classes, which is my scenario. In my case, the two classes I am dealing with are yes they will take their medicine, and no they will not. But the major problem with this is that this data will be non-linear, at least to my understanding. To make this more clear, let me give a real life example. If a patient has yoga class on Sunday mornings, (time slot 19) and tends to forget to take their medication at this time, then most of the numbers under time slot 19 would be 0s, while all the other time slots would have many more 1s. The goal is to create a machine learning model which can realize given past data that the patient is very likely going to miss their medication on the next time slot 19. I believe that logistic regression must be used on data that still has an inherently linear data distribution, however I am not sure. I also understand that neural networks are ideal for non-linear distributions, but neural networks require a lot of data to function properly, and ideally the goal of my model is to be able to function decently with simply a few weeks of data. Of course any model becomes more accurate with more data, but it seems to me that generally neural networks need thousands of data sets to truly become decently accurate. Again, I could very well be wrong.

My question is really what model type would work here. I do know that I will need some form of supervised classification. But can I use logistic regression to make predictions when given time of week about adherence?

Really any general feedback on my project is greatly appreciated! Please keep in mind I am only 15, and so certain statements I made were possibly wrong and I will not be able to fully understand very complex replies.

I also have to complete this within the next two weeks, so please do not hesitate to respond as soon as you can! Thank you so much!

  • $\begingroup$ Is the study done for a single patient? $\endgroup$
    – Arun Jose
    Commented Dec 19, 2018 at 5:18
  • $\begingroup$ I will be simulating multiple patients worth of data. However I am not looking to make any comparisons between patients. Each set will contribute to either the training, validation or testing of my machine learning model. $\endgroup$ Commented Dec 20, 2018 at 3:05
  • $\begingroup$ Then I don't see why you even need a model here. You can simply tabulate probabilities of each time segment of each day for a given patient. This will be equivalent to the answer provided by using 21 dummy variables and leave out patient info. $\endgroup$
    – Arun Jose
    Commented Dec 20, 2018 at 7:45

1 Answer 1


If I understand you correctly, you have a single input, day_time, which is nonlinear, as stated in example.

Logistic regression is linear in its inputs, however, you are free to make nonlinear transformations of your original inputs and use those as inputs. In your case you could dummy code day_time into 21 Boolean variables. In fact I would use one dummy code for day-of week, one for time of day, and then also create the interactions ( = day_x_time_y). You would then also create interaction with the patient ids, to cover individual effects as you described (person X only missing daytime slot 19). You would then regularise the model using L1 or L2 regularisation. This model would then identify day patterns, or time patterns, or patient X time patterns. Regularisation ensures that the model aims to have as general a model as possible ( if most people miss on Monday, then the model will pick up a general Monday effect,rather than learning a Monday effect separately for each patient). You can do what I describe by using the https://patsy.readthedocs.io/en/latest/quickstart.html and scikit learn packages. You would provide a formula such as Medicine taken ~ hour * day* person, And patsy would create a matrix of all the base variables and every possible interaction.you would then pass this matrix to scikit learn to perform the regularised logistic regression

As an alternative model you could use a tree model such as xgboost, but I would still break day_time into two separate variables, day and time

  • $\begingroup$ Thank you for the reply! However, I am not planning on comparing data between patients, and do not plan on picking up on trends such as seeing if most people miss on Monday. I'm looking to find trends simply within one patient's data. If this is the case, would I still regularise the model? $\endgroup$ Commented Dec 20, 2018 at 3:13
  • $\begingroup$ Why don't you want to use trends across people to better identify trends in each person? $\endgroup$
    – seanv507
    Commented Dec 20, 2018 at 8:13
  • $\begingroup$ Even if as I think you are suggesting, you build a separate model for each person, regularisation will help identify a Monday effect ( common to each period) which requires less data than estimating separately for each period. $\endgroup$
    – seanv507
    Commented Dec 20, 2018 at 8:16
  • $\begingroup$ thank you so much for your input. Given what you suggested, I was thinking I would use multiple logistic regression to predict adherence. I would have a separate day of week variable (1-7), time of day variable (1-3) and a day_time variable (1-121). However, I wanted to ask if dropping the first two and using only the day_time variable would result in an inferior model, compared to including all 3 in the model. $\endgroup$ Commented Dec 28, 2018 at 6:01
  • $\begingroup$ Separately, I was also thinking of a way to give more weight to recent patient behavior when predicting adherence. One way that came to mind was to add a recency column that would have the same value for the recent 4 weeks of data, and a different value for anything older. Do you think that is a viable approach? Thanks! $\endgroup$ Commented Dec 28, 2018 at 6:08

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.