Skip to content

Commit

Permalink
PUBDEV-5294 - XGBoost model in Flow doesn't seem to converge (#2055)
Browse files Browse the repository at this point in the history
* PUBDEV-5294 - XGBoost model in Flow doesn't seem to converge

* Fix issue with DecimalFormat (not thread safe!)

* Fix formatting
  • Loading branch information
Pavel Pscheidl authored Feb 16, 2018
1 parent 5049afc commit 6819806
Showing 1 changed file with 22 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,9 @@
import water.fvec.Frame;
import water.util.Log;
import hex.ModelMetrics;

import java.text.DecimalFormat;
import java.text.NumberFormat;
import java.util.HashMap;
import java.util.Map;

Expand Down Expand Up @@ -285,9 +288,28 @@ public static HashMap<String, Object> createParams(XGBoostParameters p, XGBoostO
Log.info(" " + s.getKey() + " = " + s.getValue());
}
Log.info("");

localizeDecimalParams(params);
return params;
}

/**
* Iterates over a set of parameters and applies locale-specific formatting
* to decimal ones (Floats and Doubles).
*
* @param params Parameters to localize
*/
private static void localizeDecimalParams(final HashMap<String, Object> params) {
final NumberFormat localizedNumberFormatter = DecimalFormat.getNumberInstance();
for (String key : params.keySet()) {
final Object value = params.get(key);
if (value instanceof Float || value instanceof Double) {
final String localizedValue = localizedNumberFormatter.format(value);
params.put(key, localizedValue);
}
}
}

@Override
protected double[] score0(double[] data, double[] preds) {
return score0(data, preds, 0.0);
Expand Down

0 comments on commit 6819806

Please sign in to comment.