为什么在R中反序列化xgboost模型时出现此错误

问题描述 投票:1回答:1

我正在尝试使用xgboost模型将xgboost模型保存并部署到sql服务器中>

unserialize(as.raw(paste(serialize(model_xgb, NULL), collapse = "")))此处找到方法:https://longhowlam.wordpress.com/2016/12/23/did-you-say-sql-server-yes-i-did/

在转向SQL之前,我首先完全在R中尝试该过程,只是为了确保它能正常工作,并且我得到了以下错误和警告消息:

Error in unserialize(as.raw(xgb_str)) : read error
In addition: Warning messages:
1: In unserialize(as.raw(xgb_str)) : NAs introduced by coercion
2: In unserialize(as.raw(xgb_str)) :
  out-of-range values treated as 0 in coercion to raw

这里是一个代表:

require(data.table)
require(mltools)
require(xgboost)
require(dplyr)


mat_cars <- mtcars %>% 
  select(., mpg, disp, hp, wt, cyl) %>% 
  mutate_at(., vars(cyl), as.factor) %>% 
  as.data.table() %>% 
  one_hot() %>% 
  data.matrix()

model_xgb <- xgboost(data = mat_cars[, -1], 
                     label = mat_cars[, 1],
                     nrounds = 10,
                     verbose = 0)

xgb_str <- paste(serialize(model_xgb, NULL), collapse = "")
model_xgb2 <- unserialize(as.raw(xgb_str))

另外,这是我的会话信息:

R version 3.5.2 (2018-12-20)
Platform: x86_64-w64-mingw32/x64 (64-bit)
Running under: Windows Server 2012 R2 x64 (build 9600)

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] bindrcpp_0.2.2       dplyr_0.7.8          xgboost_0.71.2       mltools_0.3.5        data.table_1.12.0    RevoUtilsMath_11.0.0
 [7] RevoUtils_11.0.2     RevoMods_11.0.1      MicrosoftML_9.4.7    mrsdeploy_1.1.3      RevoScaleR_9.4.7     lattice_0.20-38     
[13] rpart_4.1-13        

loaded via a namespace (and not attached):
 [1] Rcpp_1.0.0             rstudioapi_0.9.0       CompatibilityAPI_1.1.0 bindr_0.1.1            magrittr_1.5           tidyselect_0.2.5      
 [7] R6_2.3.0               rlang_0.3.1            foreach_1.4.4          tools_3.5.2            grid_3.5.2             iterators_1.0.11      
[13] assertthat_0.2.0       tibble_2.0.1           crayon_1.3.4           Matrix_1.2-15          purrr_0.3.0            codetools_0.2-15      
[19] curl_3.3               glue_1.3.0             stringi_1.2.4          pillar_1.3.1           compiler_3.5.2         jsonlite_1.6          
[25] pkgconfig_2.0.2 

[请注意,当我在具有R 3.6.1和xgboost 0.9的本地计算机上尝试时,也会遇到相同的错误。我也尝试用xgb.save.raw替换序列化,并得到完全相同的错误。

任何帮助将不胜感激!

我正在尝试使用在这里找到的unserialize(as.raw(paste(serialize(model_xgb,NULL),塌陷=“”))方法来保存xgboost模型并将其部署到sql服务器:https:// longhowlam。 wordpress.com / ...

r xgboost
1个回答
0
投票

知道是否已经存在(错误)解决方案或解决方法的人?

© www.soinside.com 2019 - 2024. All rights reserved.