简体   繁体   English

有没有办法在 sparkR 中加载 .RData 或 .model 文件(使用数据块)?

[英]Is there a way to load .RData or .model files in sparkR (using databricks)?

I'm using sparkR inside databricks environment and I'm trying to load an XGB model that has been created using RStudio.我在 databricks 环境中使用 sparkR,我正在尝试加载使用 RStudio 创建的 XGB 模型。

I saved the model both in .RData and .model (using xgb.save ) types (just to increase my chances of making this work) and then uploaded both files to a folder inside DBFS (databricks).我将模型保存为 .RData 和 .model(使用xgb.save )类型(只是为了增加我完成这项工作的机会),然后将这两个文件上传到 DBFS(databricks)内的文件夹。

Now, using databricks, I wanted to load the model so I can apply it to new data, but I always got the same error message.现在,使用数据块,我想加载模型,以便我可以将其应用于新数据,但我总是收到相同的错误消息。 Here's the code and the error:这是代码和错误:

%r
# Trying to load the .RData file
load(file='/FileStore/tables/folder/xgb_model.RData')

Error in readChar(con, 5L, useBytes = TRUE) : cannot open the connection Error in readChar(con, 5L, useBytes = TRUE) : cannot open the connection Error in readChar(con, 5L, useBytes = TRUE) : cannot open the connection readChar(con, 5L, useBytes = TRUE) 中的错误:无法打开连接 readChar(con, 5L, useBytes = TRUE) 中的错误:无法打开连接 readChar(con, 5L, useBytes = TRUE) 中的错误:无法打开联系

%r
# Trying to load the .model file
xgb.load("/FileStore/tables/folder/xgb_model.model")

Error in xgb.Booster.handle(modelfile = modelfile) : Error in xgb.Booster.handle(modelfile = modelfile) : [23:34:59] amalgamation/../dmlc-core/src/io/local_filesys.cc:209: Check failed: allow_null: LocalFileSystem::Open "/FileStore/tables/folder/xgb_model.model": No such file or directory xgb.Booster.handle(modelfile = modelfile) 中的错误:xgb.Booster.handle(modelfile = modelfile) 中的错误:[23:34:59] amalgamation/../dmlc-core/src/io/local_filesys.cc: 209:检查失败:allow_null:LocalFileSystem::Open“/FileStore/tables/folder/xgb_model.model”:没有那个文件或目录

Is that even possible?这甚至可能吗?

The FileStore is a special folder that is located on DBFS , so to access this data, R code needs to understand DBFS. FileStore是一个位于 DBFS 上特殊文件夹,因此要访问此数据,R 代码需要了解 DBFS。 But in your case, it can only work with the local files, that why it's failing.但是在您的情况下,它只能与本地文件一起使用,这就是它失败的原因。 To make it working with files in FileStore as local files, you need to prepend the /dbfs/ to the file names, like, /dbfs/FileStore/tables/folder/xgb_model.model (please note that it may not work on the community edition with 7.x runtime)要使其将FileStore中的文件作为本地文件使用,您需要在文件名前添加/dbfs/ ,例如/dbfs/FileStore/tables/folder/xgb_model.model (请注意它可能不适用于社区带有 7.x 运行时的版本)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM