title: Predict a user input using current datetime and past history
body: <h1>The project</h1>
  
  <p>I'm working on a small project where users can create events (such as <code>Eat</code>, <code>Sleep</code>, <code>Watch a movie</code>, etc.) and record log entries matching these events.</p>
  
  <p>My data model looks like this (the application itself is in Python 3 / Django, but I don't think it matters here):</p>
  
  <pre><code># a sample event
  event = {
      'id': 1,
      'name': 'Eat',
  }
  
  # a sample entry
  entry = {
      'event_id': event['id'],
      'user_id': 12,
  
      # record date of the entry
      'date': '2017-03-16T12:56:32.095465+00:00',
  
      # user-given tags for the entry
      'tags': ['home', 'delivery'],
  
      # A user notation for the entry, it can be positive or negative
      'score': 2,
  
      'comment': 'That was a tasty meal',
  
  }
  </code></pre>
  
  <p>Users can record an arbitrary number of entries for an arbitrary number of events, they can create new events when they need to. The data is stored in a relational database.</p>
  
  <p>Now, I'd like to make data entry easier for users, by suggesting them relevant events when they visit the "Add an entry" form. At the moment, they can select the event corresponding to their entry in a dropdown, but I want to suggest them a few relevant events on top of that.</p>
  
  <p>I was thinking that, given a user history (all the recorded entries), it should be possible to predict likely inputs, by identifying patterns in entries, e.g:</p>
  
  <ul>
  <li><code>Eat</code> usually happens every day, around noon and 7:00PM</li>
  <li><code>Sleep</code> usually occurs after 10:00 PM</li>
  <li><code>Watch a movie</code> usually occurs after on friday nights after 8:00 PM</li>
  </ul>
  
  <p>Ideally, I'd like a function, that, given a user ID and a datetime, and using the user history, will return a list of events that are more likely to occur:</p>
  
  <pre><code>def get_events(user_id, datetime, max=3):
      # implementation
  
      # returns a list of up to max events
      return events
  </code></pre>
  
  <p>So if I take the previous example (with more human dates), I would get the following results:</p>
  
  <pre><code>&gt;&gt;&gt; get_events(user_id, 'Friday at 9:00 PM')
  ['Watch a movie', 'Sleep', 'Eat']
  
  &gt;&gt;&gt; get_events(user_id, 'Friday at 9:00 PM', max=2)
  ['Watch a movie', 'Sleep']
  
  &gt;&gt;&gt; get_events(user_id, 'Monday at 9:00 PM')
  ['Sleep', 'Eat', 'Watch a movie']
  
  &gt;&gt;&gt; get_events(user_id, 'Monday at noon')
  ['eat']
  </code></pre>
  
  <p>Of course, in the real life, I'll pass real datetimes, and I'd like to get an event ID so I can get corresponding data from the database.</p>
  
  <h1>My question</h1>
  
  <p>(Sorry, if it took some time to explain the whole thing)</p>
  
  <p>My actual question is, what are the actual algorithms / tools / libraries required to achieve this? Is it even possible to do? </p>
  
  <p>My current guess is that I'll need to use some fancy machine learning stuff, using something like scikit-learn and classifiers, feeding it with the user history to train it, then ask the whole thing to do its magic.</p>
  
  <p>I'm not familiar at all with machine learning and I fear I don't have enough mathematical/scientific background to get started on my own. Can you provide me some reference material to help me understand how to solve this, the algorithms / vocabulary I have to dig in, or some pseudocode ?</p>