public class ModelUtils
extends java.lang.Object
Used by interpreted models as well as by generated model code.
WARNING: The class should have no other H2O dependencies since it is provided for generated code as h2o-model.jar which contains only a few files.
| Modifier and Type | Field and Description |
|---|---|
static float[] |
DEFAULT_THRESHOLDS
List of default thresholds
|
| Constructor and Description |
|---|
ModelUtils() |
| Modifier and Type | Method and Description |
|---|---|
static float[] |
correctProbabilities(float[] scored,
float[] priorClassDist,
float[] modelClassDist)
Correct a given list of class probabilities produced as a prediction by a model back to prior class distribution
|
static int |
getPrediction(float[] preds,
double[] data)
Utility function to get a best prediction from an array of class
prediction distribution.
|
static int |
getPrediction(float[] preds,
int row) |
static int[] |
getPredictions(int numK,
float[] preds,
double[] data)
Create labels from per-class probabilities with pseudo-random tie-breaking, if needed.
|
static int[] |
sampleOOBRows(int nrows,
float rate,
java.util.Random sampler)
Sample out-of-bag rows with given rate with help of given sampler.
|
static int[] |
sampleOOBRows(int nrows,
float rate,
java.util.Random sampler,
int[] oob)
In-situ version of
sampleOOBRows(int, float, Random). |
public static int getPrediction(float[] preds,
double[] data)
preds - an array of prediction distribution. Length of arrays is equal to a number of classes+1.public static int[] getPredictions(int numK,
float[] preds,
double[] data)
numK - Number of top probabilities to make labels forpreds - Predictions (first element is ignored here: placeholder for a label)data - Data to break ties (typically, the test set data for this row)public static int getPrediction(float[] preds,
int row)
public static float[] correctProbabilities(float[] scored,
float[] priorClassDist,
float[] modelClassDist)
The implementation is based on Eq. (27) in the paper.
scored - list of class probabilities beginning at index 1priorClassDist - original class distributionmodelClassDist - class distribution used for model building (e.g., data was oversampled)public static int[] sampleOOBRows(int nrows,
float rate,
java.util.Random sampler)
nrows - number of rows to sample from.rate - sampling ratesampler - random "dice"public static int[] sampleOOBRows(int nrows,
float rate,
java.util.Random sampler,
int[] oob)
sampleOOBRows(int, float, Random).oob - an initial array to hold sampled rows. Can be internally reallocated.sampleOOBRows(int, float, Random)