0
$\begingroup$

I have a dataset shown below. Here, status is if visit has been done or not and schedule is if next_action_scheduled.

df = 

visit_date |status |scheduled_visit

2018-09-13|1|0000-00-00

2018-11-13|1|0000-00-00

2019-01-13|1|0000-00-00

2019-03-13|0|0000-00-00

2019-05-13|0|0000-00-00

So consider this case like user is visiting in every 2 month.

I would like to find this pattern for all users based on the historical visits with the customer. I would like to find the next predicted visit for that customer and if we missed that visit, then I ask "Do you want to schedule a visit" Or "You missed a visit with this customer."

I'm new in Ml. I tried to use RNN for time series forecasting but I'm getting a really high error rate. Prediciton is nowhere close. What model/algorithm I should use and learn about to make a model for this? I want to create a solution like if I feed in the user_id it will check all these values and send notification within app.

Thank you

$\endgroup$
0
$\begingroup$

Assume x person in df table has visit_data and scheduled visit for Y person, initally calculate the difference and create that as your target variable. there after you can create a model and predict the no.of days, once you predict the no.of days add same to your visit date to get the schedule date. below is the process in code

#calculating the differnce in visit and schedule visit
df['#.of days']= df['scheduled_visit']-df['visit_date']

#now my table as below
visit_date|#serial.no|#.of days

#create Regression or ARMIA model on serial.no and #.of days

#start predicting the values for next 30 events, you will get to know the no.of days values

#finally add those values to your visit_date you will get the schedule visit date

Start with small model like ARIMA and check with results instead of deeplearning models(RNN),choose your model based the data size.

$\endgroup$
  • $\begingroup$ thanks murlidhar I will start with ARIMA first and as Mark also suggested for regression. Thanks for prompt reply :) $\endgroup$ – Akshit jain Jun 21 at 11:28
  • $\begingroup$ Hi Muralidhar, Do you know any example which I can follow? I'm new at this. $\endgroup$ – Akshit jain Jun 25 at 5:35
  • $\begingroup$ don't have any example. assuming one medical representative visit a doctor on certain period that could be every 14 or 30 or 45 days. now we are trying predict the certain visit date, that should be very efffective. Mean time still check with examples. $\endgroup$ – Muralidhar A Jun 25 at 6:39
  • $\begingroup$ Yes I need to find a pattern in visits, so that I can recommend if he misses one! so i need to change data as days since last visit right? If you get to know of any example please refer me to it. thanks $\endgroup$ – Akshit jain Jun 25 at 9:41
  • $\begingroup$ Actually most of the examples I found are working on a numerical data as in with date you also have another parameter which is increasing or decreasing with the dates like sales, temperature etc. In my case I only have dates of visits for each customer and also if he completed the visit or not as a status. So I have to convert this data into a time series data first. How do I do that? $\endgroup$ – Akshit jain Jun 25 at 11:13
2
$\begingroup$

If you plot days since the first visit vs the visit number, this ends up being a simple regression problem.

import pandas as pd

data = pd.read_csv('data.txt', '|')
data['visit_date'] = pd.to_datetime(data['visit_date'])
data['days_since_first_visit'] = (data['visit_date'] - data['visit_date'][0]).map(lambda delta: delta.days)
data = data.reset_index()

data.plot('index', 'days_since_first_visit')

enter image description here

I would recommend using a library like scikit-learn or statsmodels to do the regression.

$\endgroup$
  • $\begingroup$ thanks for your answer. what do you mean by this: data['days_since_first_visit'] = (data['visit_date'] - data['visit_date'][0]).map(lambda delta: delta.days). $\endgroup$ – Akshit jain Jun 21 at 9:55
  • $\begingroup$ This creates a new column containing the delta, in days, between each visit date and first visit date $\endgroup$ – Mark Dunne Jun 21 at 11:02

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.