facebookexperimental / Robyn

Robyn is an experimental, AI/ML-powered and open sourced Marketing Mix Modeling (MMM) package from Meta Marketing Science. Our mission is to democratise modeling knowledge, inspire the industry through innovation, reduce human bias in the modeling process & build a strong open source marketing science community.
https://facebookexperimental.github.io/Robyn/
MIT License
1.13k stars 336 forks source link

An error that occurs when setting hyperparameters "'x' must be numeric." #834

Open akhrt01 opened 12 months ago

akhrt01 commented 12 months ago

Let me ask you about an error that occurs when setting hyperparameters in Robyn, "'x' must be numeric.". (I reinstalled Robyn today, so I think the version is 3.10.4. This is an error that did not occur when I used version 3.7.1.)

After entering the hyperparameters as below,

//////// hyperparameters <- list( media_A_alphas = c(0.5, 1), media_A_gammas = c(0.3, 1), media_A_thetas = c(0, 0.05), media_B_alphas = c(0.5, 1), media_B_gammas = c(0.3, 1), media_B_thetas = c(0, 0.2), train_size = c(0.5, 0.8) ) ////////

run "InputCollect <- robyn_inputs(InputCollect = InputCollect, hyperparameters = hyperparameters)". Then the following error occurs.

//////// Error in mutate(): ℹ In argument: ds = cut(.data$ds, intervalType). Caused by error in cut.default(): ! 'x' must be numeric.

Backtrace: ▆

  1. ├─Robyn::robyn_inputs(InputCollect = InputCollect, hyperparameters = hyperparameters)
  2. │ └─Robyn:::robyn_engineering(InputCollect, ...)
  3. │ └─Robyn:::prophet_decomp(...)
  4. │ └─Robyn:::set_holidays(dt_transform, dt_holidays, intervalType)
  5. │ └─... %>% ...
  6. ├─dplyr::summarise(...)
  7. ├─dplyr::group_by(., .data$ds, .data$country, .data$year)
  8. ├─dplyr::select(., .data$ds, .data$holiday, .data$country, .data$year)
  9. ├─dplyr::mutate(., ds = cut(.data$ds, intervalType))
    1. ├─dplyr:::mutate.data.frame(., ds = cut(.data$ds, intervalType))
    2. │ └─dplyr:::mutate_cols(.data, dplyr_quosures(...), by)
    3. │ ├─base::withCallingHandlers(...)
    4. │ └─dplyr:::mutate_col(dots[[i]], data, mask, new_columns)
    5. │ └─mask$eval_all_mutate(quo)
    6. │ └─dplyr (local) eval()
    7. ├─base::cut(.data$ds, intervalType)
    8. ├─base::cut.default(.data$ds, intervalType)
    9. │ └─base::stop("'x' must be numeric")
    10. └─base::.handleSimpleError(...)
    11. └─dplyr (local) h(simpleError(msg, call))
    12. └─rlang::abort(message, class = error_class, parent = parent, call = error_call) ////////

And run "print(InputCollect)", Robyn says"Hyper-parameters: Not set yet". All data is either integer or numeric. And I am converting a date column to date data as below. //////// data$DATE <- as.IDate(data$DATE) ////////

What is the problem with this error and how can I resolve it?

gufengzhou commented 12 months ago

Your hyperparameter names don't look right. They should be media_A_alpha, _gamma, _theta etc. please read the demo.R guides. Also please make sure you're using the latest version on GitHub

akhrt01 commented 11 months ago

Thank you for your reply. Sorry, I made a mistake when posting the code. Actually, I am writing alpha, gamma, and theta as shown above, which has been modified.

It seems that the date data conversion was not working properly. It worked by installing the package("data.table"), declaring the library(data.table), and converting the date data with code like below.

data$DATE <- as.IDate(data$DATE)

I appreciate your kindness.

gufengzhou commented 11 months ago

We've actually deprecated data.table from Robyn completely. You're installing from CRAN right? You should get rid of this problem if you install from GitHub.

akhrt01 commented 11 months ago

I wanted to get the same results as when I built the model last year, so I used the code "Robyn 3.7.1" that I referenced from the github below around August last year.

https://github.com/facebookexperimental/Robyn/tree/main

I installed it using the code below from RStudio last week. /// install.packages("Robyn") ///

The fact that it is completely deprecated means that unexpected problems may occur when using "data.table".

I'm currently able to output the analysis results without any problems, but would it be better to include them from the source code and re-obtain them from the link below and analyze them?

https://github.com/facebookexperimental/Robyn/blob/main/demo/demo.R

gufengzhou commented 11 months ago

I strongly recommend to use the latest version for future modelling. Backwards compatibility is not always guaranteed.