twitter / AnomalyDetection

Anomaly Detection with R
GNU General Public License v3.0
3.56k stars 779 forks source link

AnomalyDetectionTs I got a blank plot window #94

Open aliwumi opened 6 years ago

aliwumi commented 6 years ago

I'm a newbie in R, i got a problem when I am trying to detect anomalies on my test dataset use AnomalyDetection‘s function AnomalyDetectionTs.

My R code and the the plot window is blank: problem

My test data: time,rate 2017-08-01 00:00:00,0.7742 2017-08-02 00:00:00,0.7548 2017-08-03 00:00:00,0.7548 2017-08-04 00:00:00,0.7087 2017-08-05 00:00:00,0.7425 2017-08-06 00:00:00,0.7321 2017-08-07 00:00:00,0.7757 2017-08-08 00:00:00,0.7478 2017-08-09 00:00:00,0.745 2017-08-10 00:00:00,0.7264 2017-08-11 00:00:00,0.7139 2017-08-12 00:00:00,0.7257 2017-08-13 00:00:00,0.7307 2017-08-14 00:00:00,0.7443 2017-08-15 00:00:00,0.6525 2017-08-16 00:00:00,0.6732 2017-08-17 00:00:00,0.7324 2017-08-18 00:00:00,0.7288 2017-08-19 00:00:00,0.7485 2017-08-20 00:00:00,0.6779 2017-08-21 00:00:00,0.7564 2017-08-22 00:00:00,0.7322 2017-08-23 00:00:00,0.7337 2017-08-24 00:00:00,0.6972 2017-08-25 00:00:00,0.7336 2017-08-26 00:00:00,0.737 2017-08-27 00:00:00,0.716 2017-08-28 00:00:00,0.7535 2017-08-29 00:00:00,0.7557 2017-08-30 00:00:00,0.7318 2017-08-31 00:00:00,0.7754 2017-09-01 00:00:00,0.7403 2017-09-02 00:00:00,0.7304 2017-09-03 00:00:00,0.7211 2017-09-04 00:00:00,0.748 2017-09-05 00:00:00,0.7308 2017-09-06 00:00:00,0.7473 2017-09-07 00:00:00,0.7372 2017-09-08 00:00:00,0.7663 2017-09-09 00:00:00,0.7455 2017-09-10 00:00:00,0.75 2017-09-11 00:00:00,0.7514 2017-09-12 00:00:00,0.7194 2017-09-13 00:00:00,0.7211 2017-09-14 00:00:00,0.7388 2017-09-15 00:00:00,0.7595 2017-09-16 00:00:00,0.7438 2017-09-17 00:00:00,0.7495 2017-09-18 00:00:00,0.7681 2017-09-19 00:00:00,0.7409 2017-09-20 00:00:00,0.7249 2017-09-21 00:00:00,0.7355 2017-09-22 00:00:00,0.7611 2017-09-23 00:00:00,0.7672 2017-09-24 00:00:00,0.7474 2017-09-25 00:00:00,0.7472 2017-09-26 00:00:00,0.7324 2017-09-27 00:00:00,0.7957 2017-09-28 00:00:00,0.7586 2017-09-29 00:00:00,0.8076 2017-09-30 00:00:00,0.7578 2017-10-01 00:00:00,0.7403 2017-10-02 00:00:00,0.7722 2017-10-03 00:00:00,0.7634 2017-10-04 00:00:00,0.7516 2017-10-05 00:00:00,0.776 2017-10-06 00:00:00,0.7908 2017-10-07 00:00:00,0.7786 2017-10-08 00:00:00,0.7484 2017-10-09 00:00:00,0.7665 2017-10-10 00:00:00,0.7503 2017-10-11 00:00:00,0.7739 2017-10-12 00:00:00,0.7928 2017-10-13 00:00:00,0.7717 2017-10-14 00:00:00,0.8009 2017-10-15 00:00:00,0.7931 2017-10-16 00:00:00,0.7905 2017-10-17 00:00:00,0.7981 2017-10-18 00:00:00,0.7963 2017-10-19 00:00:00,0.7726 2017-10-20 00:00:00,0.8056 2017-10-21 00:00:00,0.8236 2017-10-22 00:00:00,0.7712 2017-10-23 00:00:00,0.7942 2017-10-24 00:00:00,0.7782 2017-10-25 00:00:00,0.8123 2017-10-26 00:00:00,0.7928 2017-10-27 00:00:00,0.7891 2017-10-28 00:00:00,0.8051 2017-10-29 00:00:00,0.7841 2017-10-30 00:00:00,0.7815 2017-10-31 00:00:00,0.8014 2017-11-01 00:00:00,0.8114 2017-11-02 00:00:00,0.7825 2017-11-03 00:00:00,0.7902 2017-11-04 00:00:00,0.8024 2017-11-05 00:00:00,0.8012 2017-11-06 00:00:00,0.8135 2017-11-07 00:00:00,0.781 2017-11-08 00:00:00,0.8088 2017-11-09 00:00:00,0.7858 2017-11-10 00:00:00,0.7437 2017-11-11 00:00:00,0.7529 2017-11-12 00:00:00,0.7734 2017-11-13 00:00:00,0.808 2017-11-14 00:00:00,0.7459 2017-11-15 00:00:00,0.692 2017-11-16 00:00:00,0.7114 2017-11-17 00:00:00,0.6866 2017-11-18 00:00:00,0.7112 2017-11-19 00:00:00,0.7282 2017-11-20 00:00:00,0.7214 2017-11-21 00:00:00,0.7705 2017-11-22 00:00:00,0.7705 2017-11-23 00:00:00,0.7844 2017-11-24 00:00:00,0.7603 2017-11-25 00:00:00,0.774 2017-11-26 00:00:00,0.7562 2017-11-27 00:00:00,0.7923 2017-11-28 00:00:00,0.7687 2017-11-29 00:00:00,0.7698 2017-11-30 00:00:00,0.7812 2017-12-01 00:00:00,0.765 2017-12-02 00:00:00,0.7837 2017-12-03 00:00:00,0.7863 2017-12-04 00:00:00,0.787 2017-12-05 00:00:00,0.7888 2017-12-06 00:00:00,0.7811 2017-12-07 00:00:00,0.7525 2017-12-08 00:00:00,0.817 2017-12-09 00:00:00,0.8083 2017-12-10 00:00:00,0.8361 2017-12-11 00:00:00,0.8086 2017-12-12 00:00:00,0.8022 2017-12-13 00:00:00,0.8041 2017-12-14 00:00:00,0.8016 2017-12-15 00:00:00,0.8131 2017-12-16 00:00:00,0.8331 2017-12-17 00:00:00,0.8265 2017-12-18 00:00:00,0.8253 2017-12-19 00:00:00,0.8175

danielmedbar commented 6 years ago

Hi there! I get the same. It seems this happens when you have plot=T and 0 anomalies detected. For some reason instead of showing the plot with 0 outliers it produces a blank plot.

Does anyone here know how to sort this out?

IronistM commented 6 years ago

+1. This happens when no output is supplied to the plot. Probably something like this would solve in in the _ts function.

 if(plot & length(anoms) > 0){
    return (list(anoms = anoms, plot = xgraph))
  } else {
    return (list(anoms = anoms, plot = plot.new()))
  }
danielmedbar commented 6 years ago

i think the problem is there and in line 148: if (anom_pct == 0) { if (verbose) message("No anomalies detected.") return(list(anoms = data.frame(), plot = plot.new())) } it should have to be changed to: if (anom_pct == 0) { if (verbose) message("No anomalies detected.") return(list(anoms = data.frame())) }

HanWang-HiWorld commented 6 years ago

AnomalyDetectionTs is very sensitive to max_anoms and longterm setting. This is how I fixed the issue with more than one month time series: anomalydetection <- AnomalyDetectionTs(data, max_anoms=0.02, direction = "pos", plot = TRUE, e_value = T, longterm = T)