AdrianAntico / AutoQuant

R package for automation of machine learning, forecasting, model evaluation, and model interpretation
GNU Affero General Public License v3.0
235 stars 43 forks source link

AutoTS Function ERROR #42

Closed arth1996 closed 4 years ago

arth1996 commented 4 years ago

Hey,

I am trying to run the following code:

output <- AutoTS(kpi, TargetName = 'Reject Qty', DateName = 'month_year', FCPeriods = 3, HoldOutPeriods = 4, EvaluationMetric = 'MAPE', InnerEval = 'AICc', TimeUnit = 'month', Lags = 1, SLags = 1, SkipModels = c("NNET","TBATS","ETS","TSLM","ARFIMA","DSHW"), StepWise = TRUE, TSClean = FALSE, ModelFreq = TRUE, PlotPredictionIntervals = TRUE, PrintUpdates = FALSE)

and getting this error:

Error in ncol(Final_metrics) : object 'Final_metrics' not found

Does anyone know what mistake am I making?

AdrianAntico commented 4 years ago

@arth1996 Can you supply some data so I can test your code? It can be fake data, just try to make it similar to the data you are using in the function...

DougVegas commented 4 years ago

@arth1996 , it's also possible that the TargetName you're supplying might be problematic because it has a space. Could you also try testing it by replacing the space with an underscore?

AdrianAntico commented 4 years ago

@DougVegas I just used the example in the help file (worked) then modified the target name to have a space in it, and it still worked. I'm wondering if the date column isn't recognized as a date column. I just had to deal with this on the CARMA functions for when date columns had a "/" in it and it was read in as a character column... Might need to add that correction to AutoTS. Seeing the users data (a snapshot of it) would help

arth1996 commented 4 years ago

TempDATA.xlsx

@AdrianAntico attached the fake data. Also, the class of Date column was Date and I had replaced "/" with "-" so, I am not sure if date is the issue.

AdrianAntico commented 4 years ago

@arth1996 Thanks for the heads up. I will look into it...

AdrianAntico commented 4 years ago

@arth1996 Here's what the data looks like when I save as .csv and pull it into R

         Date Reject Qty Kt Release V4 V5 V6 V7 V8 V9 V10 V11 V12
 1:  8/1/2017   1.000000   0.000000 NA NA NA NA NA NA  NA  NA  NA
 2:  9/1/2017   2.000000  40.000000 NA NA NA NA NA NA  NA  NA  NA
 3: 10/1/2017   3.000000  60.000000 NA NA NA NA NA NA  NA  NA  NA
 4: 11/1/2017  10.000000  48.666667 NA NA NA NA NA NA  NA  NA  NA
 5: 12/1/2017   0.000000  80.000000 NA NA NA NA NA NA  NA  NA  NA
 6:  1/1/2018   3.000000  24.000000 NA NA NA NA NA NA  NA  NA  NA
 7:  2/1/2018   3.000000  48.666667 NA NA NA NA NA NA  NA  NA  NA
 8:  3/1/2018   3.000000  51.333333 NA NA NA NA NA NA  NA  NA  NA
 9:  4/1/2018   1.000000   5.333333 NA NA NA NA NA NA  NA  NA  NA
10:  5/1/2018   2.000000  80.000000 NA NA NA NA NA NA  NA  NA  NA
11:  6/1/2018   3.000000   5.333333 NA NA NA NA NA NA  NA  NA  NA
12:  7/1/2018   1.000000   0.000000 NA NA NA NA NA NA  NA  NA  NA
13:  8/1/2018  25.000000   0.000000 NA NA NA NA NA NA  NA  NA  NA
14:  9/1/2018  13.000000  80.000000 NA NA NA NA NA NA  NA  NA  NA
15: 10/1/2018   5.000000  80.000000 NA NA NA NA NA NA  NA  NA  NA
16: 11/1/2018   1.000000  24.000000 NA NA NA NA NA NA  NA  NA  NA
17: 12/1/2018   0.000000  65.000000 NA NA NA NA NA NA  NA  NA  NA
18:  1/1/2019   1.000000  70.000000 NA NA NA NA NA NA  NA  NA  NA
19:  2/1/2019   2.000000  90.000000 NA NA NA NA NA NA  NA  NA  NA
20:  3/1/2019   4.000000   0.000000 NA NA NA NA NA NA  NA  NA  NA
21:  4/1/2019   4.000000  80.000000 NA NA NA NA NA NA  NA  NA  NA
22:  5/1/2019   2.913043  42.666667 NA NA NA NA NA NA  NA  NA  NA
23:  6/1/2019   1.000000  80.000000 NA NA NA NA NA NA  NA  NA  NA
24:  7/1/2019   3.000000   0.000000 NA NA NA NA NA NA  NA  NA  NA
25:                   NA         NA NA NA NA NA NA NA  NA  NA  NA
         Date Reject Qty Kt Release V4 V5 V6 V7 V8 V9 V10 V11 V12

> str(data)
Classes ‘data.table’ and 'data.frame':  25 obs. of  12 variables:
 $ Date      : chr  "8/1/2017" "9/1/2017" "10/1/2017" "11/1/2017" ...
 $ Reject Qty: num  1 2 3 10 0 3 3 3 1 2 ...
 $ Kt Release: num  0 40 60 48.7 80 ...
 $ V4        : logi  NA NA NA NA NA NA ...
 $ V5        : logi  NA NA NA NA NA NA ...
 $ V6        : logi  NA NA NA NA NA NA ...
 $ V7        : logi  NA NA NA NA NA NA ...
 $ V8        : logi  NA NA NA NA NA NA ...
 $ V9        : logi  NA NA NA NA NA NA ...
 $ V10       : logi  NA NA NA NA NA NA ...
 $ V11       : logi  NA NA NA NA NA NA ...
 $ V12       : logi  NA NA NA NA NA NA ...
 - attr(*, ".internal.selfref")=<externalptr> 
AdrianAntico commented 4 years ago

Fixed the issue. You will have to reinstall the package... The data you supplied wasn't liked much by most of the models. With the Arima model, if a model failed to build, it was stopping the function because a data object named Final_metrics wasn't created since no model was built. I added an existence check and it works fine now. However, I would set the SkipModels argument to NULL because I could only get the NNet and TBATS models to build...

# Downloaded xlsx and saved as .csv
# Load csv
data <- data.table::fread(file.choose())

# Keep first two columns
data <- data[, .SD, .SDcols = 1:2]

# Keep only rows 1 through 24
data <- data[1:24]

# Build models (notice the SkipModels argument)
xx <- RemixAutoML::AutoTS(
  data = data,
  TargetName = 'Reject Qty',
  DateName = 'Date',
  FCPeriods = 3,
  HoldOutPeriods = 4,
  EvaluationMetric = 'MAPE',
  InnerEval = 'AICc',
  TimeUnit = 'month',
  Lags = 1,
  SLags = 1,
  SkipModels = NULL, #c("NNET","TBATS","ETS","TSLM","ARFIMA","DSHW"),
  StepWise = TRUE,
  TSClean = FALSE,
  ModelFreq = TRUE,
  PlotPredictionIntervals = TRUE,
  PrintUpdates = TRUE)