# Fitting Gaussian mixture model to binary time data

I have data about the dates/times a user logs in and out of a system. I am trying to model the likelihood a user will be logged into the system at any particular time of day. I want to fit a Gaussian mixture model to the data to do this. I will be using Python and scikit-learn.

I am not sure how to input that data into the model. I could break the continuous data up into discrete data (a dictionary containing a 1 or 0 for each minute indicating whether they were logged on or not for each day) and sum up each day. However I feel like I should be able to use my continuous data.

I hope that makes sense! If not please ask me to clarify. I really appreciate any responses.

Edit: Oh sorry, I think I misread: You want to model the likelihood that a particular user is logged in at a particular time, i.e. given a certain user and time of the day you want to receive a likelihood that this user will be logged on at that time of the day?

Is it the case that you want to treat each user individually or do you want to get a general feeling about the time when users are logged on?

Or is the nature of the question more that you want to figure out whether or not a certain user is a 'morning-user' or an 'evening-user'?

I thougth you just want a likelihood for the log on time...

For now it seems as if you are just interested in the time of day, i.e. you want to ignore the fact that there is a summer / winter period and there may be differences depending on the day in the week (more logins on the weekend?). Hence, you could just turn timestamps into 'how many seconds after midnight', i.e.

'2000-01-01 01:00:00' --> 3600

'2016-05-03 02:10:23' --> 3600 + 3600 + 600 + 23 = 7823

...

Then you treat these numbers as continuous values. Then you could theoretically fit a GMM. However, it has hyperparameters which you need to optimize. Since you are lucky and the data is just one-dimensional, you can fit different GMMs (i.e. GMMs with different amounts of clusters) and see how good they resemble the data 'by eye'. Once you are satisfied, you got the likelihood.

However, depending on the question this can be useful and 'unuseful': GMMs will cluster the different logons into groups along the day and it will likely figure out something like 'there is a group in the morning and another one in the evening' or so. I.e. the latent variable, GMMs will uncover is the number of the cluster. However, if you are just interested some kind of likelihood then a one dimensional density estimation will suffice...

Cheers

• I will look into one-dimensional density estimation. Do you think this would be more appropriate for my problem? I am also not able to choose any parameters by eye as I have too much data for that to be feasible. – Alex Modell Jul 18 '17 at 10:14
• Yes, I am looking at given a time of day, the probability a user will be logged on. I wish to look at each user individually and the idea is for my to find out the nature of their use (as you say, whether they are a morning-user or an evening-user) so I can flag when they log in at a time which is out of character for them (e.g. when there is <2% chance they would be logged-on at that time normally) – Alex Modell Jul 18 '17 at 10:18
• Aah... so it actually is only important when they log in... so, for example, the time how long they are being logged in is not (yet) important to you... correct? It's only important when the log in, not when they are online... – Fabian Werner Jul 18 '17 at 11:14
• Maybe you should make different columns "firstLogin" , "secondLogin", ... group by day and insert the respective seconds after midnight. What you should do next is to add a feature "amountLogins" because I think this is important as well. However, even if the different login points are normally distributed, the amount will be gamma distributed! – Fabian Werner Jul 18 '17 at 11:25
• you should do an iterated version: first of all compute the clustering on the first login exclusively. Then, if you see a new login you check to which cluster this user belongs to and where the mean of the first login of that user is. The distance will tell you how "normal" it is that the users in this cluster log on at that time of the day. You can assign a probability using quantiles of the normal distribution. Then, when the user logs on for the second time you do the same thing with GMMs trained on the first two logins, etc... what do you think? – Fabian Werner Jul 18 '17 at 12:16