【问题标题】:Anomaly detection In RR中的异常检测
【发布时间】:2018-01-22 17:09:08
【问题描述】:

我习惯于使用 R 中的 qcc 包来检测数据中的异常值。我最近遇到了 AnomalyDetection 包。在这里找到:https://github.com/twitter/AnomalyDetection

我的数据集如下:

date_start<-as.Date(c('2017-10-17','2017-10-18',
                '2017-10-19','2017-10-20',
                '2017-10-21','2017-10-22',
                '2017-10-23','2017-10-24',
                '2017-10-25','2017-10-26',
                '2017-10-27','2017-10-28',
                '2017-10-29','2017-10-30',
                '2017-10-31','2017-11-01',
                '2017-11-02','2017-11-03',
                '2017-11-04','2017-11-05',
                '2017-11-06','2017-11-07',
                '2017-11-08','2017-11-09',
                '2017-11-10','2017-11-11',
                '2017-11-12'))

count <- c(NA, 3828,
                3532,3527,
                3916,4303,
                3867,3699,
                3439,3099,
                3148,3310,
                3904,3525,
                2962,3398,
                2935,3013,
                3005,3516,
                3010,2848,
                2689,2573,
                2569,2946,
                2713)

df<-data.frame(date_start,count)

head(df)

  date_start count
1 2017-10-17    NA
2 2017-10-18  3828
3 2017-10-19  3532
4 2017-10-20  3527
5 2017-10-21  3916
6 2017-10-22  4303

当我使用 AnomalyDetection 包测试此数据集时,响应为 NULL,并且没有显示任何绘图。知道为什么会这样吗?

library(AnomalyDetection)
res = AnomalyDetectionTs(df, max_anoms=0.02, direction='both', plot=TRUE)
res$plot

NULL

【问题讨论】:

    标签: r anomaly-detection


    【解决方案1】:

    这是由于没有检测到异常造成的。

    手动更改时:

    count[13] <- 5671 
    

    检测到了。

    此外,为了使情节正常工作,时间戳需要为 POSIXct

    df <- data.frame(date_start = as.POSIXct(date_start),
                     count)
    
    res <- AnomalyDetectionTs(df,
                              max_anoms = 0.02,
                              direction = 'both',
                              plot = TRUE)  
    
    #output
    
    $anoms
                timestamp anoms
    1 2017-10-29 02:00:00  5671
    
    $plot
    

    【讨论】:

      【解决方案2】:

      使用 POSIXct 时出现以下错误“错误:列 x 是日期/时间,必须存储为 POSIXct,而不是 POSIXlt”

      不过改成 POSIXlt 可以解决问题

      【讨论】:

        猜你喜欢
        • 2020-02-23
        • 2021-11-10
        • 2021-03-08
        • 1970-01-01
        • 1970-01-01
        • 2016-02-28
        • 2019-10-01
        • 2018-10-08
        • 1970-01-01
        相关资源
        最近更新 更多