twitter / AnomalyDetection

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

Urgent Help!!! error "data must be a single data frame in R" #104

Open Elsunais opened 5 years ago

Elsunais commented 5 years ago

I want to run an anomaly on time series. my codes are below:

temp<- c(.0980, .0897, .0982, .0123, .0244, .0897) anom<- ts(temp, frequency=1, start=c(2006, 1)) anom Time Series: Start = 2006 End = 2011 Frequency = 1 [1] 0.0980 0.0897 0.0982 0.0123 0.0244 0.0897 AnomalyDetectionTs(anom, max_anoms = 0.2, direction = "both", alpha = 0.05,

  • only_last = NULL, threshold = "p95", e_value = FALSE,
  • longterm = FALSE, piecewise_median_period_weeks = 2, plot = TRUE,
  • y_log = TRUE, xlabel = "Year", ylabel = "Temperature", title = "AnomalyTemperature",
  • verbose = FALSE)

but i kept having an error stating: "Error in AnomalyDetectionTs(anom, max_anoms = 0.2, direction = "both", : data must be a single data frame." Please i need help! Thank you

WajdiBenSaad commented 4 years ago

Hello,

I have faced this error, and the solution is to input your data as a DataFrame object. here an example:

temp<- c(.0980, .0897, .0982, .0123, .0244, .0897) anom<- ts(temp, frequency=1, start=c(2006, 1))

library(xts) datx <- as.xts(anom) df <- data.frame(date=index(datx), coredata(datx)) res = AnomalyDetectionTs(df) res$plot

One final thing, you need more data to be able to use this function ( your example only has 6 data points)

Good luck !