R中使用异常包进行时间序列异常检测;返回图和输出在最后一个指定时期“放大”

问题描述

我正在 R 中使用 anomalize 包,我想知道是否有可能以从指定时间点(即过去 24 小时内)绘制日期的方式过滤结果?

这是我正在使用的数据框(抱歉它看起来很长):-

fiveminclock<-structure(c(1590969600,1590969900,1590970200,1590970500,1590970800,1590971100,1590971400,1590971700,1590972000,1590972300,1590972600,1590972900,1590973200,1590973500,1590973800,1590974100,1590974400,1590974700,1590975000,1590975300,1590975600,1590975900,1590976200,1590976500,1590976800,1590977100,1590977400,1590977700,1590978000,1590978300,1590978600,1590978900,1590979200,1590979500,1590979800,1590980400,1590980700,1590981000,1590981300,1590981600,1590981900,1590982200,1590982500,1590982800,1590983100,1590983400,1590983700,1590984000,1590984300,1590984600,1590984900,1590985200,1590985500,1590985800,1590986100,1590986400,1590986700,1590987000,1590987300,1590987600,1590988200,1590988500,1590988800,1590989100,1590989400,1590989700,1590990000,1590990300,1590990600,1590990900,1590991200,1590991500,1590991800,1590992100,1590992400,1590992700,1590993000,1590993300,1590993600,1590993900,1590994200,1590994500,1590995100,1590995400,1590995700,1590996000,1590996300,1590996900,1590997200,1590997500,1590997800,1590998100,1590998400,1590998700,1590999000,1590999300,1590999600,1590999900,1591000200,1591000500,1591000800,1591001100,1591001400,1591001700,1591002000,1591002300,1591002600,1591002900,1591003200,1591003500,1591003800,1591004100,1591004400,1591004700,1591005000,1591005300,1591005600,1591005900,1591006200,1591006500,1591006800,1591007100,1591007400,1591007700,1591008000,1591008300,1591008600,1591008900,1591009200,1591009500,1591009800,1591010100,1591010400,1591010700,1591011000,1591011300,1591011600,1591011900,1591012200,1591012500,1591012800,1591013100,1591013400,1591013700,1591014000,1591014300,1591014600,1591014900,1591015200,1591015500,1591015800,1591016100,1591016400,1591016700,1591017000,1591017300,1591017600,1591017900,1591018200,1591018500,1591018800,1591019100,1591019400,1591019700,1591020000,1591020300,1591020600,1591020900,1591021200,1591021500,1591021800,1591022100,1591022400,1591022700,1591023000,1591023300,1591023600,1591023900,1591024200,1591024500,1591024800,1591025100,1591025400,1591025700,1591026000,1591026300,1591026600,1591026900,1591027200,1591027500,1591027800,1591028100,1591028400,1591028700,1591029000,1591029300,1591029600,1591029900,1591030200,1591030500,1591030800,1591031100,1591031400,1591031700,1591032000,1591032300,1591032600,1591032900,1591033200,1591033500,1591033800,1591034100,1591034400,1591034700,1591035000,1591035300,1591035600,1591035900,1591036200,1591036500,1591036800,1591037100,1591037400,1591037700,1591038000,1591038300,1591038600,1591038900,1591039200,1591039500,1591039800,1591040100,1591040400,1591040700,1591041000,1591041300,1591041600,1591041900,1591042200,1591042500,1591042800,1591043100,1591043400,1591043700,1591044000,1591044300,1591044600,1591044900,1591045200,1591045500,1591045800,1591046100,1591046400,1591046700,1591047000,1591047300,1591047600,1591047900,1591048200,1591048500,1591048800,1591049100,1591049400,1591049700,1591050000,1591050300,1591050600,1591050900,1591051200,1591051500,1591051800,1591052100,1591052400,1591052700,1591053000,1591053300,1591053600,1591053900,1591054200,1591054500,1591054800,1591055100,1591055400,1591055700,1591056000,1591056300,1591056600,1591056900,1591057200,1591057500,1591057800,1591058100,1591058400,1591058700,1591059000,1591059300,1591059600,1591059900,1591060200,1591060500,1591060800,1591061100,1591061400,1591061700,1591062000,1591062300,1591062600,1591062900,1591063200,1591063500,1591063800,1591064100,1591064400,1591064700,1591065000,1591065300,1591065600,1591065900,1591066200,1591066500,1591066800,1591067100,1591067400,1591067700,1591068000,1591068300,1591068600,1591068900,1591069200,1591069500,1591069800,1591070100,1591070400,1591070700,1591071000,1591071300,1591071900,1591072200,1591072500,1591072800,1591073100,1591073400,1591073700,1591074000,1591074300,1591074600,1591074900,1591075200,1591075500,1591075800,1591076100,1591076400,1591076700,1591077000,1591077300,1591077600,1591077900,1591078200,1591078500,1591078800,1591079100,1591079400,1591079700,1591080000,1591080300,1591080600,1591080900,1591081200,1591081500,1591081800,1591082100,1591082400,1591083000,1591083300,1591083600,1591083900,1591084200,1591084500,1591084800,1591085100,1591085400,1591085700,1591086000,1591086300,1591086600,1591086900,1591087500,1591087800,1591088100,1591088400,1591088700,1591089000,1591089300,1591089600,1591089900,1591090200,1591090500,1591090800,1591091100,1591091400,1591091700,1591092000,1591092300,1591092600,1591092900,1591093200,1591093500,1591093800,1591094100,1591094400,1591094700,1591095000,1591095300,1591095600,1591095900,1591096200,1591096500,1591096800,1591097100,1591097400,1591097700,1591098000,1591098300,1591098600,1591098900,1591099200,1591099500,1591099800,1591100100,1591100400,1591100700,1591101000,1591101300,1591101600,1591101900,1591102200,1591102500,1591102800,1591103100,1591103400,1591103700,1591104000,1591104300,1591104600,1591104900,1591105200,1591105500,1591105800,1591106100,1591106400,1591106700,1591107000,1591107300,1591107600,1591107900,1591108200,1591108500,1591108800,1591109100,1591109400,1591109700,1591110000,1591110300,1591110600,1591110900,1591111200,1591111500,1591111800,1591112100,1591112400,1591112700,1591113000,1591113300,1591113600,1591113900,1591114200,1591114500,1591114800,1591115100,1591115400,1591115700,1591116000,1591116300,1591116600,1591116900,1591117200,1591117500,1591117800,1591118100,1591118400,1591118700,1591119000,1591119300,1591119600,1591119900,1591120200,1591120500,1591120800,1591121100,1591121400,1591121700,1591122000,1591122300,1591122600,1591122900,1591123200,1591123500,1591123800,1591124100,1591124400,1591124700,1591125000,1591125300,1591125600,1591125900,1591126200,1591126500,1591126800,1591127100,1591127400,1591127700,1591128000,1591128300,1591128600,1591128900,1591129200,1591129500,1591129800,1591130100,1591130400,1591130700,1591131000,1591131300,1591131600,1591131900,1591132200,1591132500,1591132800,1591133100,1591133400,1591133700,1591134000,1591134300,1591134600,1591134900,1591135200,1591135500,1591135800,1591136100,1591136400,1591136700,1591137000,1591137300,1591137600,1591137900,1591138200,1591138500,1591138800,1591139100,1591139400,1591139700,1591140000,1591140300,1591140600,1591140900,1591141200,1591141500,1591141800,1591142100,1591142400,1591142700,1591143000,1591143300,1591143600,1591143900,1591144200,1591144500,1591144800,1591145100,1591145400,1591145700,1591146000,1591146300,1591146600,1591146900,1591147200,1591147500,1591147800,1591148100,1591148400,1591148700,1591149000,1591149300,1591149600,1591149900,1591150200,1591150500,1591150800,1591151100,1591151400,1591151700,1591152000,1591152300,1591152600,1591152900,1591153200,1591153500,1591153800,1591154100,1591154400,1591154700,1591155000,1591155300,1591155600,1591155900,1591156200,1591156500,1591156800,1591157100,1591157400,1591157700,1591158000,1591158300,1591158600,1591158900,1591159200,1591159500,1591159800,1591160100,1591160400,1591160700,1591161000,1591161300,1591161600,1591161900,1591162200,1591162500,1591162800,1591163100,1591163700,1591164000,1591164300,1591164600,1591164900,1591165200,1591165500,1591165800,1591166100,1591166400,1591166700,1591167000,1591167300,1591167600,1591167900,1591168200,1591168500,1591168800,1591169100,1591169400,1591169700,1591170000,1591170300,1591170600,1591170900,1591171200,1591171500,1591171800,1591172100,1591172400,1591172700,1591173000,1591173300,1591173600,1591173900,1591174200,1591174500,1591174800,1591175100,1591175400,1591175700,1591176000,1591176300,1591176600,1591176900,1591177200,1591177500,1591177800,1591178100,1591178400,1591178700,1591179000,1591179300,1591179600,1591179900,1591180200,1591180500,1591180800,1591181100,1591181400,1591181700,1591182000,1591182300,1591182600,1591182900,1591183200,1591183500,1591183800,1591184100,1591184400,1591184700,1591185000,1591185300,1591185600,1591185900,1591186200,1591186500,1591186800,1591187100,1591187400,1591187700,1591188000,1591188300,1591188600,1591188900,1591189200,1591189500,1591189800,1591190100,1591190400,1591190700,1591191000,1591191300,1591191600,1591191900,1591192200,1591192500,1591192800,1591193100,1591193400,1591193700,1591194000,1591194300,1591194600,1591194900,1591195200,1591195500,1591195800,1591196100,1591196400,1591196700,1591197000,1591197300,1591197600,1591197900,1591198200,1591198500,1591198800,1591199100,1591199400,1591199700,1591200000,1591200300,1591200600,1591200900,1591201200,1591201500,1591201800,1591202100,1591202400,1591202700,1591203000,1591203300,1591203600,1591203900,1591204200,1591204500,1591204800,1591205100,1591205400,1591205700,1591206000,1591206300,1591206600,1591206900,1591207200,1591207500,1591207800,1591208100,1591208400,1591208700,1591209000,1591209300,1591209600,1591209900,1591210200,1591210500,1591210800,1591211100,1591211400,1591211700,1591212000,1591212300,1591212600,1591212900,1591213200,1591213500,1591213800,1591214100,1591214400,1591214700,1591215000,1591215300,1591215600,1591215900,1591216200,1591216500,1591216800,1591217100,1591217400,1591217700,1591218000,1591218300,1591218600,1591218900,1591219200,1591219500,1591219800,1591220100,1591220400,1591220700,1591221000,1591221300,1591221600,1591221900,1591222200,1591222500,1591222800,1591223100,1591223400,1591223700,1591224000,1591224300,1591224600,1591224900,1591225200,1591225500,1591225800,1591226100,1591226400,1591226700,1591227000,1591227300,1591227600,1591227900,1591228200,1591228500,1591228800,1591229100,1591229400,1591229700,1591230000,1591230300,1591230600,1591230900,1591231200,1591231500,1591231800,1591232100,1591232400,1591232700,1591233000,1591233300,1591233600,1591233900,1591234200,1591234500,1591234800,1591235100,1591235400,1591235700,1591236000,1591236300,1591236600,1591236900,1591237200,1591237500,1591237800,1591238100,1591238400,1591238700,1591239000,1591239600,1591239900,1591240200,1591240500,1591240800,1591241100,1591241400,1591241700,1591242000,1591242600,1591242900,1591243200,1591243500,1591243800,1591244100,1591244400,1591244700,1591245000,1591245300,1591245600,1591245900,1591246200,1591246500,1591246800,1591247400,1591247700,1591248000,1591248300,1591248600,1591248900,1591249200,1591249500,1591249800,1591250100,1591250400,1591250700,1591251000,1591251300,1591251600,1591251900,1591252200,1591252500,1591252800,1591253100,1591253400,1591253700,1591254000,1591254300,1591254600,1591254900,1591255200,1591255500,1591255800,1591256100,1591256400,1591256700,1591257000,1591257300,1591257600,1591257900,1591258200,1591258500,1591258800,1591259100,1591259400,1591259700,1591260000,1591260300,1591260600,1591260900,1591261200,1591261500,1591261800,1591262100,1591262400,1591262700,1591263000,1591263300,1591263600,1591263900,1591264200,1591264500,1591264800,1591265100,1591265400,1591265700,1591266000,1591266300,1591266900,1591267200,1591267500,1591267800,1591268100,1591268400,1591268700,1591269000,1591269300,1591269600,1591269900,1591270200,1591270500,1591270800,1591271100,1591271400,1591271700,1591272000,1591272300,1591272600,1591272900,1591273200,1591273500,1591273800,1591274100,1591274400,1591274700,1591275000,1591275300,1591275600,1591275900,1591276200,1591276500,1591276800,1591277400,1591277700,1591278000,1591278300,1591278600,1591278900,1591279200,1591279500,1591279800,1591280100,1591280400,1591280700,1591281000,1591281300,1591281600,1591281900,1591282200,1591282500,1591282800,1591283100,1591283400,1591283700,1591284000,1591284300,1591284600,1591284900,1591285200,1591285500,1591285800,1591286100,1591286400,1591286700,1591287000,1591287300,1591287600,1591287900,1591288200,1591288500,1591288800,1591289100,1591289400,1591289700,1591290000,1591290300,1591290600,1591290900,1591291200,1591291500,1591291800,1591292100,1591292400,1591292700,1591293000,1591293300,1591293600,1591293900,1591294200,1591294500,1591294800,1591295100,1591295400,1591295700,1591296000,1591296300,1591296600,1591296900,1591297200,1591297500,1591297800,1591298100,1591298400,1591298700,1591299000,1591299300,1591299600,1591299900,1591300200,1591300500,1591300800,1591301100,1591301400,1591301700,1591302000,1591302300,1591302600,1591302900,1591303200,1591303500,1591303800,1591304100,1591304400,1591304700,1591305000,1591305300,1591305600,1591305900,1591306200,1591306500,1591306800,1591307100,1591307400,1591307700,1591308000,1591308300,1591308600,1591308900,1591309200,1591309500,1591309800,1591310100,1591310400,1591310700,1591311000,1591311300,1591311600,1591311900,1591312200,1591312500,1591312800,1591313100,1591313400,1591313700,1591314000,1591314300,1591314600,1591314900,1591315200,1591315500,1591315800,1591316100,1591316400,1591316700,1591317000,1591317300,1591317600,1591317900,1591318200,1591318500,1591318800,1591319100,1591319400,1591319700,1591320000,1591320300,1591320600,1591320900,1591321200,1591321500,1591321800,1591322100,1591322400,1591322700,1591323000,1591323300,1591323600,1591323900,1591324200,1591324500,1591324800,1591325100,1591325400,1591325700,1591326000,1591326300,1591326600,1591326900,1591327200,1591327500,1591327800,1591328100,1591328400,1591328700,1591329000,1591329300,1591329600,1591329900,1591330200,1591330500,1591330800,1591331100,1591331400,1591331700,1591332000,1591332300,1591332600,1591332900,1591333200,1591333500,1591333800,1591334100,1591334400,1591334700,1591335000,1591335300,1591335600,1591335900,1591336200,1591336500,1591336800,1591337100,1591337400,1591337700,1591338000,1591338600,1591338900,1591339200,1591339500,1591339800,1591340100,1591340400,1591340700,1591341000,1591341300,1591341600,1591341900,1591342200,1591342500,1591342800,1591343100,1591343400,1591343700,1591344000,1591344300,1591344600,1591344900,1591345200,1591345500,1591345800,1591346100,1591346400,1591346700,1591347000,1591347300,1591347600,1591347900,1591348200,1591348500,1591348800,1591349100,1591349400,1591349700,1591350000,1591350300,1591350600,1591350900,1591351200,1591351500,1591351800,1591352100,1591352400,1591352700,1591353000,1591353300,1591353600,1591353900,1591354200,1591354500,1591354800,1591355100,1591355400,1591355700,1591356000,1591356300,1591356600,1591356900,1591357200,1591357500,1591357800,1591358100,1591358400,1591358700,1591359000,1591359300,1591359600,1591359900,1591360200,1591360500,1591360800,1591361100,1591361700,1591362000,1591362300,1591362600,1591362900,1591363200,1591363500,1591363800,1591364100,1591364400,1591364700,1591365000,1591365300,1591365600,1591365900,1591366200,1591366500,1591366800,1591367100,1591367400,1591367700,1591368000,1591368300,1591368600,1591368900,1591369200,1591369500,1591369800,1591370100,1591370400,1591370700,1591371000,1591371300,1591371600,1591371900,1591372200,1591372500,1591372800,1591373100,1591373400,1591373700,1591374000,1591374300,1591374600,1591374900,1591375200,1591375500,1591375800,1591376100,1591376400,1591376700,1591377000,1591377300,1591377600,1591377900,1591378200,1591378500,1591378800,1591379100,1591379400,1591379700,1591380000,1591380300,1591380600,1591380900,1591381200,1591381500,1591381800,1591382100,1591382400,1591382700,1591383000,1591383300,1591383600,1591383900,1591384200,1591384500,1591384800,1591385100,1591385400,1591385700,1591386000,1591386300,1591386600,1591386900,1591387200,1591387500,1591387800,1591388100,1591388400,1591388700,1591389000,1591389300,1591389600,1591389900,1591390200,1591390500,1591390800,1591391100,1591391400,1591391700,1591392000,1591392300,1591392600,1591392900,1591393200,1591393500,1591393800,1591394100,1591394400,1591394700,1591395000,1591395300,1591395600,1591395900,1591396200,1591396500,1591396800,1591397100,1591397400,1591397700,1591398000,1591398300,1591398600,1591398900,1591399200,1591399500,1591399800,1591400100,1591400400,1591400700,1591401000,1591401300,1591401600),tzone = "UTC",class = c("POSIXct","POSIXt"))


Count<-c(5L,30L,8L,9L,1L,7L,20L,2L,17L,6L,19L,10L,13L,4L,5L,3L,26L,32L,22L,43L,12L,11L,14L,15L,18L,25L,16L,52L,40L,27L,33L,24L,23L,21L,36L,35L,39L,59L,28L,46L,29L,34L,3L)


df<-as.tibble(fiveminclock,Count)

这里是异常检测代码:-

library(anomalize) #tidy anomaly detectiom
library(tidyverse) #tidyverse packages like dplyr,ggplot,tidyr


df%>% 
  time_decompose(Count,method = "stl",frequency = "auto",trend = "auto") %>%
  anomalize(remainder,method = "gesd",alpha = 0.02,max_anoms = 0.01) %>%
  plot_anomaly_decomposition()


df %>% 
  time_decompose(Count,max_anoms = 0.01) %>%
  time_recompose() %>%
  plot_anomalies(time_recomposed = TRUE,ncol = 3,alpha_dots = 0.5)


 df%>% 
  time_decompose(Count,max_anoms = 0.01) %>%
  time_recompose() %>%
  filter(anomaly == 'Yes')



这将返回这些图以及此表输出:-

enter image description here

enter image description here

enter image description here

如您所见,时间变量是 YMD-HMS。我想知道是否有一种方法可以只显示数据中过去 24 小时的结果和图表。当然,我希望异常检测模型建立在所有可用数据上,但只需要显示数据中过去 24 小时的输出。这个包可以吗?

解决方法

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

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

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