R package Quickstart example not working.
Problem: R package example not working catboost version: 0.24.4 Operating System: Linux and Windows CPU: i5
When trying the following quickstart code for the R Package
library(catboost)
features <- data.frame(feature1 = c(1, 2, 3), feature2 = c('A', 'B', 'C'))
labels <- c(0, 0, 1)
train_pool <- catboost.load_pool(data = features, label = labels)
I got the following error:
Error in catboost.from_data_frame(data, label, pairs, weight, group_id, :
Unsupported column type: character
The same code worked great with version 0.24.1 and R 3.6.
The problem seems to be related to issue #1328. According to #1246, it seems that catboost now requires the categorical variables to be converted to factors. Is something new? If that is the case, I think the quickstart code should be corrected.
Thanks for the package!! It is really great!!
sessionInfo()
R version 4.0.2 (2020-06-22)
Platform: x86_64-pc-linux-gnu (64-bit)
Running under: Ubuntu 18.04.5 LTS
Matrix products: default
BLAS: /usr/lib/x86_64-linux-gnu/blas/libblas.so.3.7.1
LAPACK: /usr/lib/x86_64-linux-gnu/lapack/liblapack.so.3.7.1
locale:
[1] LC_CTYPE=en_US.UTF-8 LC_NUMERIC=C LC_TIME=en_US.UTF-8 LC_COLLATE=en_US.UTF-8
[5] LC_MONETARY=en_US.UTF-8 LC_MESSAGES=en_US.UTF-8 LC_PAPER=en_US.UTF-8 LC_NAME=C
[9] LC_ADDRESS=C LC_TELEPHONE=C LC_MEASUREMENT=en_US.UTF-8 LC_IDENTIFICATION=C
attached base packages:
[1] stats graphics grDevices utils datasets methods base
other attached packages:
[1] catboost_0.24.1
loaded via a namespace (and not attached):
[1] compiler_4.0.2 htmltools_0.5.0 tools_4.0.2 yaml_2.2.1 tinytex_0.28 rmarkdown_2.6 knitr_1.30
[8] jsonlite_1.7.2 digest_0.6.25 xfun_0.20 rlang_0.4.10 evaluate_0.14
Hello! In my case this example is working just fine. Can you try to fully reinstall catboost package? Maybe there were some problems due to mixed-version files install or some other kind of R-environment corruption. Thank you!
@harpomaxx Did you solve your issue? I'm having the same. Fresh install on fresh RStudio. I tried installing 0.24.1 and not 0.24.4 to see if it would resolve it.
devtools::install_url('https://github.com/catboost/catboost/releases/download/v0.24.1/catboost-R-Windows-0.24.1.tgz', INSTALL_opts = c("--no-multiarch"))
Install logs:
* installing *source* package 'catboost' ...
** using staged installation
** R
** inst
** byte-compile and prepare package for lazy loading
** help
*** installing help indices
converting help for package 'catboost'
finding HTML links ... done
catboost.caret html
catboost.cv html
catboost.drop_unused_features html
catboost.get_feature_importance html
catboost.get_model_params html
catboost.get_object_importance html
catboost.load_model html
catboost.load_pool html
catboost.predict html
catboost.save_model html
catboost.save_pool html
catboost.shrink html
catboost.staged_predict html
catboost.sum_models html
catboost.train html
dim.catboost.Pool html
dimnames.catboost.Pool html
head.catboost.Pool html
print.catboost.Pool html
tail.catboost.Pool html
** building package indices
** testing if installed package can be loaded from temporary location
** testing if installed package can be loaded from final location
** testing if installed package keeps a record of temporary installation path
* DONE (catboost)
Making 'packages.html' ... done
> sessionInfo()
>R version 4.0.3 (2020-10-10)
>Platform: x86_64-w64-mingw32/x64 (64-bit)
>Running under: Windows Server x64 (build 17763)
>
>Matrix products: default
>
>locale:
>[1] LC_COLLATE=English_Canada.1252 LC_CTYPE=English_Canada.1252 >LC_MONETARY=English_Canada.1252
>[4] LC_NUMERIC=C LC_TIME=English_Canada.1252
>
>attached base packages:
>[1] stats graphics grDevices utils datasets methods base
>
>other attached packages:
>[1] catboost_0.24.1
> library(catboost)
> features <- data.frame(feature1 = c(1, 2, 3), feature2 = c('A', 'B', 'C'))
> labels <- c(0, 0, 1)
> train_pool <- catboost.load_pool(data = features, label = labels)
Error in catboost.from_data_frame(data, label, pairs, weight, group_id, :
Unsupported column type: character
Ah, reading further on catboost, here, it specifies that:
Categorical features must be converted to factors (use as.factor
(emphasis mine)
When converted into factors, it does work.
Odd that the most basic example provided by catboost doc would fail...
@actuariallonewolf I could not solve the problem. According to @kizill I could be a problem between versions or something like that. I will check again with a docker image with a fresh R installation (https://github.com/harpomaxx/r-docker/tree/master/nvidia-base-r)
In any case, the same as you, I found it odd that the most basic example did not work.
Converting to factors, does not help in my case. I get different error message
Error in .Call("CatBoostHashStrings_R", as.character(preprocessed[[column_index]])) : "CatBoostHashStrings_R" not resolved from current namespace (catboost)
install.packages('devtools') devtools::install_url('https://github.com/catboost/catboost/releases/download/v0.24.4/catboost-R-Windows-0.24.4.tgz', INSTALL_opts = c("--no-multiarch"))
#%% Test ----- library(catboost) features <- data.frame(feature1 = c(1, 2, 3), feature2 = as.factor( c('A', 'B', 'C')) ) labels <- c(0, 0, 1) train_pool <- catboost.load_pool(data = features, label = labels)
Error in .Call("CatBoostHashStrings_R", as.character(preprocessed[[column_index]])) : "CatBoostHashStrings_R" not resolved from current namespace (catboost)
sessionInfo() R version 4.0.3 (2020-10-10) Platform: x86_64-w64-mingw32/x64 (64-bit) Running under: Windows 10 x64 (build 19042)
Matrix products: default
locale: [1] LC_COLLATE=English_United States.1252 LC_CTYPE=English_United States.1252 LC_MONETARY=English_United States.1252 [4] LC_NUMERIC=C LC_TIME=English_United States.1252
attached base packages: [1] stats graphics grDevices utils datasets methods base
other attached packages: [1] catboost_0.24.4
loaded via a namespace (and not attached):
[1] rstudioapi_0.13 magrittr_2.0.1 usethis_2.0.0 devtools_2.3.2 pkgload_1.1.0 R6_2.5.0 rlang_0.4.9 fansi_0.4.1
[9] tools_4.0.3 pkgbuild_1.2.0 xfun_0.19 sessioninfo_1.1.1 tinytex_0.28 cli_2.2.0 withr_2.3.0 remotes_2.2.0
[17] ellipsis_0.3.1 assertthat_0.2.1 digest_0.6.27 rprojroot_2.0.2 lifecycle_0.2.0 crayon_1.3.4 processx_3.4.5 purrr_0.3.4
[25] callr_3.5.1 fs_1.5.0 ps_1.5.0 testthat_3.0.1 memoise_1.1.0 glue_1.4.2 compiler_4.0.3 desc_1.2.0
[33] prettyunits_1.1.1 jsonlite_1.7.2
@harpomaxx There was a critical issue with exported dll symbols for builds on Windows introduced in 0.24.4, we'll pubish hotfix in minor release 0.24.5 today or tomorrow.
I suggest you should update CatBoost for stable version (0.26) and use factor() for categorical features like that:
features <- data.frame(feature1 = c(1, 2, 3), feature2 = factor(c('A', 'B', 'C')))
It works both on Windows and Linux and R version 3.6.3 or higher. So we have updated quick start page accordingly: https://catboost.ai/docs/concepts/r-quickstart.html Anyway, if you reproduce it again, feel free to reopen!
In R4, the quick start example fails using
features <- data.frame(feature1=c(1, 2, 3), feature2=c('A', 'B', 'C'))
with:
Error in catboost.train(train_pool, NULL, params = list(loss_function = "Logloss", :
catboost/private/libs/feature_estimator/text_feature_estimators.cpp:89: Dictionary size is 0, check out data or try to decrease occurrence_lower_bound parameter
The example works with:
features <- data.frame(feature1=c(1, 2, 3), feature2=factor('A', 'B', 'C'))