Java Code Examples for ml.dmlc.xgboost4j.java.XGBoost#loadModel()
The following examples show how to use
ml.dmlc.xgboost4j.java.XGBoost#loadModel() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: MLXGBoost.java From RecSys2018 with Apache License 2.0 | 6 votes |
public static Async<Booster> asyncModel(final String modelFile, final int nthread) { // load xgboost model final Async<Booster> modelAsync = new Async<Booster>(() -> { try { Booster bst = XGBoost.loadModel(modelFile); if (nthread > 0) { bst.setParam("nthread", nthread); } return bst; } catch (XGBoostError e) { e.printStackTrace(); return null; } }, Booster::dispose); return modelAsync; }
Example 2
Source File: MaxEdgeScoreDependencyParser.java From SmoothNLP with GNU General Public License v3.0 | 5 votes |
public static Booster loadXgbModel(String modelAddr) { try{ InputStream modelIS = SmoothNLP.IOAdaptor.open(modelAddr); Booster booster = XGBoost.loadModel(modelIS); return booster; }catch(Exception e){ // add proper warnings later System.out.println(e); return null; } }
Example 3
Source File: UtilFns.java From SmoothNLP with GNU General Public License v3.0 | 5 votes |
public static Booster loadXgbModel(String modelAddr) { try{ InputStream modelIS = SmoothNLP.IOAdaptor.open(modelAddr); Booster booster = XGBoost.loadModel(modelIS); return booster; }catch(Exception e){ // add proper warnings later System.out.println(e); return null; } }
Example 4
Source File: XGBoostModel.java From zoltar with Apache License 2.0 | 5 votes |
/** * Note: Please use Models from zoltar-models module. * * <p>Returns a XGBoost model given a URI to the serialized model file. */ public static XGBoostModel create(final Model.Id id, final URI modelUri) throws IOException { try { GompLoader.start(); final InputStream is = Files.newInputStream(FileSystemExtras.path(modelUri)); return new AutoValue_XGBoostModel(id, XGBoost.loadModel(is)); } catch (final XGBoostError xgBoostError) { throw new IOException(xgBoostError); } }
Example 5
Source File: MLXGBoost.java From RecSys2018 with Apache License 2.0 | 5 votes |
public static MLXGBoostFeature[] analyzeFeatures(final String modelFile, final String featureFile) throws Exception { Booster model = XGBoost.loadModel(modelFile); List<String> temp = new LinkedList<String>(); try (BufferedReader reader = new BufferedReader( new FileReader(featureFile))) { String line; while ((line = reader.readLine()) != null) { temp.add(line); } } // get feature importance scores String[] featureNames = new String[temp.size()]; temp.toArray(featureNames); int[] importances = MLXGBoost.getFeatureImportance(model, featureNames); // sort features by their importance MLXGBoostFeature[] sortedFeatures = new MLXGBoostFeature[featureNames.length]; for (int i = 0; i < featureNames.length; i++) { sortedFeatures[i] = new MLXGBoostFeature(featureNames[i], importances[i]); } Arrays.sort(sortedFeatures, new MLXGBoostFeature.ScoreComparator(true)); return sortedFeatures; }
Example 6
Source File: XGBoostUtils.java From incubator-hivemall with Apache License 2.0 | 5 votes |
@Nonnull public static Booster deserializeBooster(@Nonnull final Text model) throws HiveException { try { byte[] b = IOUtils.fromCompressedText(model.getBytes(), model.getLength()); return XGBoost.loadModel(new FastByteArrayInputStream(b)); } catch (Throwable e) { throw new HiveException("Failed to deserialize a booster", e); } }