简体   繁体   中英

Time Prediction based on existing date:time records

I have a system that logs date:time and it returns results such as:

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 be able to do is have a list of date:time prediction for the next few days - so a person could see when the next event might occur.

Example of prediction results:

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

Thoughts on how to go about doing time prediction of this kind with php?

The basic answer is "no". Programming tools are not designed to do prediction. Statistical tools are designed for that purpose. You should be thinking more about R, SPSS, SAS, or some other similar tool. Some databases have rudimentary data analysis tools built-in, which is another (often inferior) option.

The standard statistical technique for time-series prediction is called ARIMA analysis (auto-regressive integrated moving average). It is unlikely that you are going to be implementing that in php/SQL. The standard statistical technique for estimating time between events is Poisson regression. It is also highly unlikely that you are going to be implementing that in php/SQL.

I observe that your data points are once per day in the evening. I might guess that this is the end of some process that runs during the day. The end time is based on the start time and the duration of the process.

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

If you know something about your process, then an average by day of the week can work well. You can also get more sophisticated, and do Monte Carlo estimates, by measuring the average and standard deviation, and then pulling a random value from a statistical distribution. However, the average value would work just as well in your case.

I would suggest that you study a bit about statistics/data mining/predictive analytics before attempting to do any "predictions". At the very least, if you really have a problem in this domain, you should be looking for the right tools to use.

As Gordon Linoff posted, the simple answer is "no", but you can write some code that will give a rough guess on what the next time will be.

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

Here's a possible way that this could be done, using PHP + MySQL:

  • You can have a table with two fields: a DATE field and a TIME field (essentially storing the date + time portion separately). Say that the table is named "timeData" and the fields are:

  • eventDate: date

  • eventTime: time

Your primary key would be the combination of eventDate and eventTime, so that they're never repeated as a pair.

Then, you can do a query like:

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

The aforementioned query will always return the first 10 most frequent event times, ordered by frequency. You can then order these again from smallest to largest.

This way, you can return quite accurate time prediction results, which will become even more accurate as you gather data each day

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM