H2O h2o.importFile Error: 'Cannot determine file type. for nfs://.../model.zip', caused by water.parser.ParseDataset$H2OParse

H2O h2o.importFile Error: 'Cannot determine file type. for nfs://.../model.zip', caused by water.parser.ParseDataset$H2OParse

我正在尝试将 h2o 模型作为 .zip 文件导出器导入为 POJOR。我得到以下错误:

model_file <- "/Users/bernardo/Desktop/DRF_1_AutoML_20190816_133251.zip"
m <- h2o.importFile(model_file)
Error: DistributedException from localhost/127.0.0.1:54321: 'Cannot determine file type. for nfs://Users/bernardo/Desktop/DRF_1_AutoML_20190816_133251.zip', caused by water.parser.ParseDataset$H2OParseException: Cannot determine file type. for nfs://Users/bernardo/Desktop/DRF_1_AutoML_20190816_133251.zip

我已经 运行 file.exists(model_file) 和那个 returns TRUE,所以文件存在。对 normalizePath(model_file) 做了同样的事情,得到了同样的结果。当我尝试将它导入我的 R 会话时,似乎 h2o 找到了该文件但由于某种原因无法导入它。

这是我的 R 会话信息:

R version 3.6.0 (2019-04-26)
Platform: x86_64-apple-darwin15.6.0 (64-bit)
Running under: macOS Mojave 10.14.6

Matrix products: default
BLAS:   /System/Library/Frameworks/Accelerate.framework/Versions/A/Frameworks/vecLib.framework/Versions/A/libBLAS.dylib
LAPACK: /Library/Frameworks/R.framework/Versions/3.6/Resources/lib/libRlapack.dylib

locale:
[1] en_US.UTF-8/en_US.UTF-8/en_US.UTF-8/C/en_US.UTF-8/en_US.UTF-8

attached base packages:
[1] stats     graphics  grDevices utils     datasets  methods   base     

other attached packages:
 [1] h2o_3.26.0.2      lares_4.7         data.table_1.12.2 lubridate_1.7.4   forcats_0.4.0    
 [6] stringr_1.4.0     dplyr_0.8.3       purrr_0.3.2       readr_1.3.1       tidyr_0.8.3      
[11] tibble_2.1.3      ggplot2_3.2.1     tidyverse_1.2.1  

希望你们能帮我将我的 POJO 模型导入 R。谢谢!

h2o 模型不是 zip 文件。试试这个

# path to your file
model_file <- "/Users/bernardo/Desktop/DRF_1_AutoML_20190816_133251.zip"

# prediction based on your mojo/pojo file. 
preds = h2o.mojo_predict_df(df, model_file, genmodel_jar_path = NULL, classpath = NULL, java_options = NULL, verbose = F)

如果它们是压缩的,则解压缩并再次 运行。更多信息在这里 http://docs.h2o.ai/h2o/latest-stable/h2o-docs/save-and-load-model.html

https://rdrr.io/cran/h2o/man/h2o.mojo_predict_df.html

好的,我实际上找到了我需要的解决方案。诀窍是将数据帧 (df) 转换为 json 格式,然后使用 h2o 生成的 .zip 文件来预测使用 h2o.predict_json 而不是h2o.mojo_predict_df。我认为这很简单,也不那么复杂。至少它在我需要的时候起作用了。

library(jsonlite)
library(h2o)
json <- toJSON(df)
output <- h2o.predict_json(zip_directory, json) 

注意:无需解压 zip 文件。

如果您碰巧使用了 lares 包,只需使用 h2o_predict_MOJO 函数即可。

希望它能帮助任何其他试图获得相同结果的人。