[jvm-packages] Expose json formatted booster dumps (#2233) (#2234)

* Change Booster dump from XGBoosterDumpModel to XGBoosterDumpModelEx

Allows exposing multiple formatting options of model dumping.
This commit is contained in:
ebernhardson
2017-04-29 20:23:09 -07:00
committed by Nan Zhu
parent c441d0916e
commit d3b866e3fd
5 changed files with 31 additions and 11 deletions

View File

@@ -333,6 +333,11 @@ public class Booster implements Serializable, KryoSerializable {
* @throws XGBoostError native error
*/
public String[] getModelDump(String featureMap, boolean withStats) throws XGBoostError {
return getModelDump(featureMap, withStats, "text");
}
public String[] getModelDump(String featureMap, boolean withStats, String format)
throws XGBoostError {
int statsFlag = 0;
if (featureMap == null) {
featureMap = "";
@@ -340,9 +345,12 @@ public class Booster implements Serializable, KryoSerializable {
if (withStats) {
statsFlag = 1;
}
if (format == null) {
format = "text";
}
String[][] modelInfos = new String[1][];
JNIErrorHandle.checkCall(
XGBoostJNI.XGBoosterDumpModel(handle, featureMap, statsFlag, modelInfos));
XGBoostJNI.XGBoosterDumpModelEx(handle, featureMap, statsFlag, format, modelInfos));
return modelInfos[0];
}
@@ -389,7 +397,8 @@ public class Booster implements Serializable, KryoSerializable {
statsFlag = 1;
}
String[][] modelInfos = new String[1][];
JNIErrorHandle.checkCall(XGBoostJNI.XGBoosterDumpModel(handle, "", statsFlag, modelInfos));
JNIErrorHandle.checkCall(XGBoostJNI.XGBoosterDumpModelEx(handle, "", statsFlag, "text",
modelInfos));
return modelInfos[0];
}

View File

@@ -84,8 +84,8 @@ class XGBoostJNI {
public final static native int XGBoosterGetModelRaw(long handle, byte[][] out_bytes);
public final static native int XGBoosterDumpModel(long handle, String fmap, int with_stats,
String[][] out_strings);
public final static native int XGBoosterDumpModelEx(long handle, String fmap, int with_stats,
String format, String[][] out_strings);
public final static native int XGBoosterGetAttr(long handle, String key, String[] out_string);
public final static native int XGBoosterSetAttr(long handle, String key, String value);