一段充满bug的R程序,慎入 ...

twitter的AnomalyDetection  官网效果图如下:

尝试写了下面这个R程序:

get_specify_df <- function(start_ts,stop_ts,category='totaluploadspeed'){
  library(httr)
  library(rlist)
  library(jsonlite)
  
  base <- "http://8.8.8.8/path"
  url <- paste(base,start_ts,'&end_time=',stop_ts,sep="")
  response <-GET(url)
  result <- fromJSON(content(response, as="text",encoding='utf-8'))
  if(1 == result$status)
  {
    # Fix here in the future...
    # specify_df <- list.stack(list.select(result$result,result$result$datetime,result$result$category))
    specify_df <- list.stack(list.select(result$result,result$result$datetime,result$result$'totaluploadspeed'))
    return(specify_df)
  }
  return(NULL)
}

specify_df <- get_specify_df('153386640','1533870000','totaluploadspeed')

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

想利用Twitter开源的这个异常检测模块,但是遇到的问题很多,R语言本身可参考资料不多,并且目前貌似已经没人维护了...

所以暂时不想把过多的时间放在这上面,还是改用Python吧...

原文地址:https://www.cnblogs.com/standby/p/9480213.html