我正在尝试使用在运行时使用java从H2O创建和下载的XGBoost MOJO,但我在编译时遇到错误。我尝试了多个不同版本的依赖项,但无法通过它。
依赖性:
<dependency>
<groupId>ai.h2o</groupId>
<artifactId>h2o-genmodel</artifactId>
<version>3.22.1.6</version>
</dependency>
<!-- https://mvnrepository.com/artifact/ai.h2o/h2o-genmodel-ext-xgboost -->
<dependency>
<groupId>ai.h2o</groupId>
<artifactId>h2o-genmodel-ext-xgboost</artifactId>
<version>3.24.0.1</version>
<type>pom</type>
</dependency>
main.Java
import hex.genmodel.easy.EasyPredictModelWrapper;
import hex.genmodel.easy.RowData;
import hex.genmodel.easy.prediction.BinomialModelPrediction;
public class Main {
public static void main(String[] args) throws Exception {
EasyPredictModelWrapper model = new EasyPredictModelWrapper(
MojoModel.load("/Users/p0g0085/Downloads/grid_5dd10c7e_297d_42eb_b422_56c687ba85df_model_18.zip"));
RowData row = new RowData();
row.put("brand", "Great Value");
row.put("product_type", "Cheeses");
row.put("duration", "21.0");
row.put("quantity", "1.0");
row.put("ghs_frequency", "11.3714");
BinomialModelPrediction p = model.predictBinomial(row);
System.out.println("Has penetrated the prostatic capsule (1=yes; 0=no): " + p.label);
System.out.print("Class probabilities: ");
for (int i = 0; i < p.classProbabilities.length; i++) {
if (i > 0) {
System.out.print(",");
}
System.out.print(p.classProbabilities[i]);
}
System.out.println("");
}
}
错误:
Exception in thread "main" java.lang.IllegalStateException: Algorithm `XGBoost` is not supported by this version of h2o-genmodel. If you are using an algorithm implemented in an extension, be sure to include a jar dependency of the extension (eg.: ai.h2o:h2o-genmodel-ext-xgboost)
at hex.genmodel.ModelMojoFactory.getMojoReader(ModelMojoFactory.java:102)
at hex.genmodel.ModelMojoReader.readFrom(ModelMojoReader.java:31)
at hex.genmodel.MojoModel.load(MojoModel.java:37)
at Main.main(Main.java:9)
我花了一段时间才弄明白。以下依赖对我有用。
<dependency>
<groupId>ai.h2o</groupId>
<artifactId>h2o-genmodel-ext-xgboost</artifactId>
<version>3.22.0.3</version>
</dependency>