Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/r/75.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
使用R中的插入符号保存并加载catboost模型_R_R Caret_Catboost - Fatal编程技术网

使用R中的插入符号保存并加载catboost模型

使用R中的插入符号保存并加载catboost模型,r,r-caret,catboost,R,R Caret,Catboost,我能用插入符号(Rstudio)训练Catboost模型,效果非常好 my_catboost <- caret::train(x, y, method=catboost.caret, trControl=fitControl, tuneGrid = param, metric = "ROC") my_catboost您误解了我的评论。以下是使用内置数据集Sonar的答案

我能用插入符号(Rstudio)训练Catboost模型,效果非常好

my_catboost <- caret::train(x, y, 

              method=catboost.caret, 
              trControl=fitControl, 
              tuneGrid = param,
              metric = "ROC")

my_catboost您误解了我的评论。以下是使用内置数据集Sonar的答案:

library(caret)
library(catboost)
library(mlbench)
data(Sonar)
创建列车和测试数据集:

set.seed(1)

tr <- createDataPartition(Sonar$Class, p = 0.7, list = FALSE)

trainer <- Sonar[tr,]
tester <- Sonar[-tr,]
加载保存的模型:

model2 <- catboost::catboost.load_model("model")
preds2 <- catboost.predict(model2,
                           catboost.load_pool(tester),
                           prediction_type = "Probability")
编辑:当:

saveRDS(model, "caret.model.rds")
model3 <- readRDS("caret.model.rds")
preds3 <- predict(model3, tester, type = "prob")

在插入符号中调整模型后,只需使用
catboost::catboost保存最终模型:
my_catboost$finalModel
。保存模型
并使用
catboost::catboost.load_模型
。如果您使用
caret::train
中的
preProcess
参数执行数据转换,事情会稍微复杂一些。如果您对此感兴趣,我可以添加一个答案,如果您可以使用内置数据集提供一个可复制的示例。此外,这可能也应该作为一个。谢谢@missuse发布。catboost::catboost.save_模型上的Rstudio崩溃。我在这里打开了一个github问题:@missuse让我知道我在github上发布的测试是否有意义。否则,我们将尝试使用一些内置数据的代码。您误解了我的评论,请检查我添加的答案。这应该有用。谢谢!它起作用了。但好奇的是,为什么它会与其他拯救方法相撞。正如我在对您的问题的评论中提到的,在github上的一个问题中值得一提的是,保存插入符号模型时,这一点不起作用。
catboost::catboost.save_model(model$finalModel, "model")
model2 <- catboost::catboost.load_model("model")
preds2 <- catboost.predict(model2,
                           catboost.load_pool(tester),
                           prediction_type = "Probability")
all.equal(preds1[,2], preds2)
saveRDS(model, "caret.model.rds")
model3 <- readRDS("caret.model.rds")
preds3 <- predict(model3, tester, type = "prob")
R version 3.5.0 (2018-04-23)
Platform: x86_64-w64-mingw32/x64 (64-bit)
Running under: Windows >= 8 x64 (build 9200)

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] mlbench_2.1-1        catboost_0.10.3      caret_6.0-80         ggplot2_2.2.1        lattice_0.20-35      RevoUtils_11.0.0    
[7] RevoUtilsMath_11.0.0

loaded via a namespace (and not attached):
 [1] httr_1.3.1         magic_1.5-8        ddalpha_1.3.3      tidyr_0.8.1        sfsmisc_1.1-2      jsonlite_1.5      
 [7] viridisLite_0.3.0  splines_3.5.0      foreach_1.5.0      prodlim_2018.04.18 assertthat_0.2.0   stats4_3.5.0      
[13] DRR_0.0.3          yaml_2.1.19        robustbase_0.93-0  ipred_0.9-6        pillar_1.2.3       glue_1.2.0        
[19] digest_0.6.15      colorspace_1.3-2   recipes_0.1.2      htmltools_0.3.6    Matrix_1.2-14      plyr_1.8.4        
[25] psych_1.8.4        timeDate_3043.102  pkgconfig_2.0.1    CVST_0.2-2         broom_0.4.4        purrr_0.2.4       
[31] scales_0.5.0       gower_0.1.2        lava_1.6.1         tibble_1.4.2       withr_2.1.2        nnet_7.3-12       
[37] lazyeval_0.2.1     mnormt_1.5-5       survival_2.41-3    magrittr_1.5       nlme_3.1-137       MASS_7.3-49       
[43] dimRed_0.1.0       foreign_0.8-70     class_7.3-14       tools_3.5.0        data.table_1.11.4  stringr_1.3.1     
[49] plotly_4.7.1       kernlab_0.9-26     munsell_0.4.3      bindrcpp_0.2.2     compiler_3.5.0     RcppRoll_0.2.2    
[55] rlang_0.2.0        grid_3.5.0         iterators_1.0.10   htmlwidgets_1.2    geometry_0.3-6     gtable_0.2.0      
[61] ModelMetrics_1.1.0 codetools_0.2-15   abind_1.4-5        reshape2_1.4.3     R6_2.2.2           lubridate_1.7.4   
[67] dplyr_0.7.5        bindr_0.1.1        stringi_1.1.7      parallel_3.5.0     Rcpp_0.12.17       rpart_4.1-13      
[73] DEoptimR_1.0-8     tidyselect_0.2.4