尝试使用R进行异常检测时遇到错误

问题描述

我正在尝试使用R Anomalize软件包检查我们收入中的异常情况,

我正在按照下面的快速入门文档中的说明进行操作, https://cran.r-project.org/web/packages/anomalize/vignettes/anomalize_quick_start_guide.html

就我而言,我试图将数据帧转换为如下所示的时间对象,

library(anomalize)
library(tibble)
library(tibbletime)
library(tidyverse)

revenue <- read.csv(file = '../data/revenue.csv') %>%
  mutate(date = as.Date(date)) %>%
  as_tbl_time(index = date) %>%
  group_by(country_code,date) %>%
  summarise(count = sum(`total_revenue`,na.rm = TRUE)) 

这是时间对象的外观

> revenue
# A time tibble: 807 x 3
# Index:  date
# Groups: country_code [39]
   country_code date       count
   <chr>        <date>     <dbl>
 1 AE           2020-09-01 4688.
 2 AE           2020-09-02 3054.
 3 AE           2020-09-03 3987.
 4 AE           2020-09-04 3337.
 5 AE           2020-09-05 2947.
 6 AE           2020-09-06 3597.
 7 AE           2020-09-07 3737.
 8 AE           2020-09-08 4187.
 9 AE           2020-09-09 3038.
10 AE           2020-09-10 3803.
# … with 797 more rows

但是,当尝试使用以下代码进行异常检测时,

revenue_anomalized <- revenue %>%
  time_decompose(count,merge = TRUE) %>%
  anomalize(remainder) %>%
  time_recompose()

我遇到以下错误

错误mutate()输入nested.col出现问题。
x mutate()输入date有问题。
x日期类索引仅允许年,季度,月,周和日时段
ℹ输入datecollapse_index(...)
ℹ输入nested.colpurrr::map(.x = data,.f = .f,target = count,...)
运行rlang::last_error()以查看错误发生的位置。
另外:警告消息:
1:mutate()输入nested.col有问题。
ℹ无法计算1个观测值的周期性
ℹ输入nested.colpurrr::map(.x = data,...)
2:在xts :: periodicity(idx)中:
无法计算1个观测值的周期性

任何帮助将不胜感激。预先感谢。

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)