Predicting Time Based on Existing Date: Time Records

I have a system that records date: time and returns results, for example:

05.28.2013 11:58pm 05.27.2013 10:20pm 05.26.2013 09:47pm 05.25.2013 07:30pm 05.24.2013 06:24pm 05.23.2013 05:36pm 

What I would like to do is have a list of dates: predicting the time over the next few days so that a person can see when the next event will happen.

An example of forecasting results:

 06.01.2013 04:06pm 05.31.2013 03:29pm 05.30.2013 01:14pm 

Thoughts on how to do this kind of time prediction using php?

+4
source share
3 answers

The main answer is no. Programming tools are not intended for forecasting. For this purpose, statistical tools have been developed. You should think more about R, SPSS, SAS, or another similar tool. Some databases have rudimentary data analysis tools built in, which is another (often inferior) option.

The standard statistical time series forecasting technique is called ARIMA analysis (autoregressive integrated moving average). It is unlikely that you are going to implement this in php / SQL. The standard statistical method for estimating the time between events is Poisson regression. It is also unlikely that you are going to implement this in php / SQL.

I observe that your data is indicated once a day in the evening. I can guess that this is the end of some process that works throughout the day. The end time is based on the start time and duration of the process.

What can you do? Often a reasonable prediction is "what happened yesterday." You would be surprised at how difficult it is to surpass this prediction for weather forecasting and stock market valuations. Another very reasonable method is the average of historical values.

If you know something about your process, then the average of the days of the week may work well. You can also get a more sophisticated approach and perform Monte Carlo estimates by measuring the mean and standard deviation, and then drawing a random value from the statistical distribution. However, the average will work just as well in your case.

I would advise you to learn a little about statistics / data mining / predictive analytics before trying to make β€œpredictions”. At least if you really have problems in this domain, you should look for the right tools.

+3
source

As Gordon Linoff wrote, the simple answer is no, but you can write code that gives an approximate guess of what will happen next time.

I wrote a very simple example of how to do this on my website http://livinglion.com/2013/05/next-occurrence-in-datetime-sequence/

+1
source

Here is a possible way this could be done using PHP + MySQL:

  • You may have a table with two fields: a DATE field and a TIME field (basically saving the date + time separately). Let's say that the table is called "timeData", and the fields are:

  • eventDate: date

  • eventTime: time

The primary key will be a combination of eventDate and eventTime so that they never repeat as a pair.

Then you can make a request like:

 SELECT eventTime, count(*) as counter FROM timeData GROUP BY eventTime ORDER BY counter DESC LIMIT 0, 10 

The above query will always return the first 10 most frequent events, ordered by frequency. Then you can order them again from the smallest to the largest.

Thus, you can return fairly accurate time prediction results, which will become even more accurate when you collect data every day.

0
source

Source: https://habr.com/ru/post/1483449/


All Articles