【问题标题】:H2O h2o.importFile Error: 'Cannot determine file type. for nfs://.../model.zip', caused by water.parser.ParseDataset$H2OParseH2O h2o.importFile 错误:'无法确定文件类型。对于 nfs://.../model.zip',由 water.parser.ParseDataset$H2OParse 引起
【发布时间】:2019-08-29 05:03:21
【问题描述】:

我正在尝试将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) 并返回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。谢谢!

【问题讨论】:

    标签: java r h2o


    【解决方案1】:

    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

    【讨论】:

    • 感谢@not-dave 的快速响应,这就是我导入二进制模型文件的方式,但在我的情况下,我希望导入 MOJO 导出。如果我解压缩该 .zip,我将拥有三个文件夹(域、实验性、树)和一个文件(model.ini)。由于 h2o 二进制模型仅与相同版本兼容,因此我希望将 MOJO 导入 R,因此不会出现不同版本问题。再次感谢
    • 请参阅上面的更新答案。我相信您想使用该模型进行一些预测。你可以使用mojo_predict_df 函数来做到这一点。
    【解决方案2】:

    好的,我实际上找到了我需要的解决方案。诀窍是将您的数据框(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 函数即可。

    希望它可以帮助任何其他试图达到相同结果的人。

    【讨论】:

      猜你喜欢
      • 2019-05-31
      • 1970-01-01
      • 2019-02-18
      • 2013-01-25
      • 1970-01-01
      • 1970-01-01
      • 2013-07-26
      • 1970-01-01
      • 2020-10-05
      相关资源
      最近更新 更多