首页 > 解决方案 > 检测我的数字异常增长/下降的算法

问题描述

我有一个数据集,其中包含在过去 30 天内访问我网站页面的访客编号,它看起来像这样:

Page 1: [1,2,66,2,2,7,8]
Page 2: [3,5,8,3,7,11,45]

页面的总量是巨大的。我想应用一种算法来检测在此期间突然增长、峰值或下降的页面。有没有一种算法可以让我做到这一点?

标签: algorithmstatistics

解决方案


int Q = 20;     //Q should be the difference 
                //between two pages that should be 
                //considered a spike

for (int i = 0; i < pages.length; i++){
    page p = pages[i];
    for (int j = 0; j < p.visitors.length - 1; j++){
        if(p.visitors[j] >= p.visitors[j+1] + Q){
            print("Page " + i + " has spike in day " + j);
        }
        else if(p.visitors[j] + Q <= p.visitors[j+1] + Q){
            print("Page " + i + " has spike in day " + (j+1));
        }
    }
}

推荐阅读