问题
这里的情节不管用,我怎么能展示出来呢?
# minimal runnable code
# source: https://blog.twitter.com/engineering/en_us/a/2015/introducing-practical-and-robust-anomaly-detection-in-a-time-series
install.packages("devtools") devtools::install_github("twitter/AnomalyDetection")
library(AnomalyDetection)
data(raw_data)
res = AnomalyDetectionTs(raw_data, max_anoms=0.02, direction='both', plot=TRUE)
res$plot
我得到以下错误:
> res$plot
Error: Invalid input: time_trans works with objects of class POSIXct only
更多信息
如果可以的话,这就是我在RStudio中按下按钮RStudio后得到的完整输出:
# full output, including the error
> source("~/.active-rstudio-document", echo=TRUE)
> library(AnomalyDetection)
> data(raw_data)
> res = AnomalyDetectionTs(raw_data, max_anoms=0.02, direction='both', plot=TRUE)
> res$plot
Error: Invalid input: time_trans works with objects of class POSIXct only
>
此外,这里还有一个名为raw_data
的数据集示例
# minimal dataset (printed)
> raw_data
timestamp count
1 1980-09-25 14:01:00 182.4780
2 1980-09-25 14:02:00 176.2310
3 1980-09-25 14:03:00 183.9170
4 1980-09-25 14:04:00 177.7980
5 1980-09-25 14:05:00 165.4690
6 1980-09-25 14:06:00 181.8780
7 1980-09-25 14:07:00 184.5020
8 1980-09-25 14:08:00 183.3030
9 1980-09-25 14:09:00 177.5780
10 1980-09-25 14:10:00 171.6410
仍然是我的数据集的示例,名为raw_data
,使用dput
# minimal dataset (dput)
> dput(raw_data[1:10, ])
structure(list(timestamp = structure(list(sec = c(0, 0, 0, 0,
0, 0, 0, 0, 0, 0), min = 1:10, hour = c(14L, 14L, 14L, 14L, 14L,
14L, 14L, 14L, 14L, 14L), mday = c(25L, 25L, 25L, 25L, 25L, 25L,
25L, 25L, 25L, 25L), mon = c(8L, 8L, 8L, 8L, 8L, 8L, 8L, 8L,
8L, 8L), year = c(80L, 80L, 80L, 80L, 80L, 80L, 80L, 80L, 80L,
80L), wday = c(4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L), yday = c(268L,
268L, 268L, 268L, 268L, 268L, 268L, 268L, 268L, 268L), isdst = c(0L,
0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L)), class = c("POSIXlt", "POSIXt"
), tzone = "UTC"), count = c(182.478, 176.231, 183.917, 177.798,
165.469, 181.878, 184.502, 183.303, 177.578, 171.641)), row.names = c(NA,
10L), class = "data.frame")
发布于 2022-04-26 11:39:15
我不熟悉AnomnalyDetection包,但是数据集的示例显示时间戳列是POSIXlt
类,错误提示您需要将它作为POSIXct
使用。尝试使用as.POSIXct()
。
raw_data$timestamp <- as.POSIXct(raw_data$timestamp)
在运行AnomalyDetectionTs()
函数之前。
https://stackoverflow.com/questions/72004943
复制相似问题