Model Categories

class h2o.model.H2OAutoEncoderModel[source]

Bases: h2o.model.model_base.ModelBase

anomaly(test_data, per_feature=False)[source]

Obtain the reconstruction error for the input test_data.

Parameters:
  • test_data (H2OFrame) – The dataset upon which the reconstruction error is computed.
  • per_feature (bool) – Whether to return the square reconstruction error per feature. Otherwise, return the mean square error.
Returns:

the reconstruction error.

class h2o.model.H2OBinomialModel[source]

Bases: h2o.model.model_base.ModelBase

F0point5(thresholds=None, train=False, valid=False, xval=False)[source]

Get the F0.5 for a set of thresholds.

If all are False (default), then return the training metric value. If more than one options is set to True, then return a dictionary of metrics where the keys are “train”, “valid”, and “xval”.

Parameters:
  • thresholds – If None, then the thresholds in this set of metrics will be used.
  • train (bool) – If True, return the F0.5 value for the training data.
  • valid (bool) – If True, return the F0.5 value for the validation data.
  • xval (bool) – If True, return the F0.5 value for each of the cross-validated splits.
Returns:

The F0.5 values for the specified key(s).

F1(thresholds=None, train=False, valid=False, xval=False)[source]

Get the F1 value for a set of thresholds.

If all are False (default), then return the training metric value. If more than one options is set to True, then return a dictionary of metrics where the keys are “train”, “valid”, and “xval”.

Parameters:
  • thresholds – If None, then the thresholds in this set of metrics will be used.
  • train (bool) – If True, return the F1 value for the training data.
  • valid (bool) – If True, return the F1 value for the validation data.
  • xval (bool) – If True, return the F1 value for each of the cross-validated splits.
Returns:

The F1 values for the specified key(s).

Examples:
>>> import h2o as ml
>>> from h2o.estimators.gbm import H2OGradientBoostingEstimator
>>> ml.init()
>>> rows=[[1,2,3,4,0],[2,1,2,4,1],[2,1,4,2,1],[0,1,2,34,1],[2,3,4,1,0]]*50
>>> fr = ml.H2OFrame(rows)
>>> fr[4] = fr[4].asfactor()
>>> model = H2OGradientBoostingEstimator(ntrees=10, max_depth=10, nfolds=4)
>>> model.train(x=range(4), y=4, training_frame=fr)
>>> model.F1(train=True)
F2(thresholds=None, train=False, valid=False, xval=False)[source]

Get the F2 for a set of thresholds.

If all are False (default), then return the training metric value. If more than one options is set to True, then return a dictionary of metrics where the keys are “train”, “valid”, and “xval”.

Parameters:
  • thresholds – If None, then the thresholds in this set of metrics will be used.
  • train (bool) – If True, return the F2 value for the training data.
  • valid (bool) – If True, return the F2 value for the validation data.
  • xval (bool) – If True, return the F2 value for each of the cross-validated splits.
Returns:

The F2 values for the specified key(s).

accuracy(thresholds=None, train=False, valid=False, xval=False)[source]

Get the accuracy for a set of thresholds.

If all are False (default), then return the training metric value. If more than one options is set to True, then return a dictionary of metrics where the keys are “train”, “valid”, and “xval”.

Parameters:
  • thresholds – If None, then the thresholds in this set of metrics will be used.
  • train (bool) – If True, return the accuracy value for the training data.
  • valid (bool) – If True, return the accuracy value for the validation data.
  • xval (bool) – If True, return the accuracy value for each of the cross-validated splits.
Returns:

The accuracy values for the specified key(s).

confusion_matrix(metrics=None, thresholds=None, train=False, valid=False, xval=False)[source]

Get the confusion matrix for the specified metrics/thresholds.

If all are False (default), then return the training metric value. If more than one options is set to True, then return a dictionary of metrics where the keys are “train”, “valid”, and “xval”

Parameters:
  • metrics – One or more of "min_per_class_accuracy", "absolute_mcc", "tnr", "fnr", "fpr", "tpr", "precision", "accuracy", "f0point5", "f2", "f1".
  • thresholds – If None, then the thresholds in this set of metrics will be used.
  • train (bool) – If True, return the confusion matrix value for the training data.
  • valid (bool) – If True, return the confusion matrix value for the validation data.
  • xval (bool) – If True, return the confusion matrix value for each of the cross-validated splits.
Returns:

The confusion matrix values for the specified key(s).

error(thresholds=None, train=False, valid=False, xval=False)[source]

Get the error for a set of thresholds.

If all are False (default), then return the training metric value. If more than one options is set to True, then return a dictionary of metrics where the keys are “train”, “valid”, and “xval”.

Parameters:
  • thresholds – If None, then the thresholds in this set of metrics will be used.
  • train (bool) – If True, return the error value for the training data.
  • valid (bool) – If True, return the error value for the validation data.
  • xval (bool) – If True, return the error value for each of the cross-validated splits.
Returns:

The error values for the specified key(s).

fallout(thresholds=None, train=False, valid=False, xval=False)[source]

Get the fallout for a set of thresholds (aka False Positive Rate).

If all are False (default), then return the training metric value. If more than one options is set to True, then return a dictionary of metrics where the keys are “train”, “valid”, and “xval”.

Parameters:
  • thresholds – If None, then the thresholds in this set of metrics will be used.
  • train (bool) – If True, return the fallout value for the training data.
  • valid (bool) – If True, return the fallout value for the validation data.
  • xval (bool) – If True, return the fallout value for each of the cross-validated splits.
Returns:

The fallout values for the specified key(s).

find_idx_by_threshold(threshold, train=False, valid=False, xval=False)[source]

Retrieve the index in this metric’s threshold list at which the given threshold is located.

If all are False (default), then return the training metric value. If more than one options is set to True, then return a dictionary of metrics where the keys are “train”, “valid”, and “xval”.

Parameters:
  • threshold (float) – Threshold value to search for in the threshold list.
  • train (bool) – If True, return the find idx by threshold value for the training data.
  • valid (bool) – If True, return the find idx by threshold value for the validation data.
  • xval (bool) – If True, return the find idx by threshold value for each of the cross-validated splits.
Returns:

The find idx by threshold values for the specified key(s).

find_threshold_by_max_metric(metric, train=False, valid=False, xval=False)[source]

If all are False (default), then return the training metric value.

If more than one options is set to True, then return a dictionary of metrics where the keys are “train”, “valid”, and “xval”.

Parameters:
  • metric (str) – The metric to search for.
  • train (bool) – If True, return the find threshold by max metric value for the training data.
  • valid (bool) – If True, return the find threshold by max metric value for the validation data.
  • xval (bool) – If True, return the find threshold by max metric value for each of the cross-validated splits.
Returns:

The find threshold by max metric values for the specified key(s).

fnr(thresholds=None, train=False, valid=False, xval=False)[source]

Get the False Negative Rates for a set of thresholds.

If all are False (default), then return the training metric value. If more than one options is set to True, then return a dictionary of metrics where the keys are “train”, “valid”, and “xval”.

Parameters:
  • thresholds – If None, then the thresholds in this set of metrics will be used.
  • train (bool) – If True, return the FNR value for the training data.
  • valid (bool) – If True, return the FNR value for the validation data.
  • xval (bool) – If True, return the FNR value for each of the cross-validated splits.
Returns:

The FNR values for the specified key(s).

fpr(thresholds=None, train=False, valid=False, xval=False)[source]

Get the False Positive Rates for a set of thresholds.

If all are False (default), then return the training metric value. If more than one options is set to True, then return a dictionary of metrics where the keys are “train”, “valid”, and “xval”.

Parameters:
  • thresholds – If None, then the thresholds in this set of metrics will be used.
  • train (bool) – If True, return the FPR value for the training data.
  • valid (bool) – If True, return the FPR value for the validation data.
  • xval (bool) – If True, return the FPR value for each of the cross-validated splits.
Returns:

The FPR values for the specified key(s).

gains_lift(train=False, valid=False, xval=False)[source]

Get the Gains/Lift table for the specified metrics.

If all are False (default), then return the training metric Gains/Lift table. If more than one options is set to True, then return a dictionary of metrics where t he keys are “train”, “valid”, and “xval”.

Parameters:
  • train (bool) – If True, return the gains lift value for the training data.
  • valid (bool) – If True, return the gains lift value for the validation data.
  • xval (bool) – If True, return the gains lift value for each of the cross-validated splits.
Returns:

The gains lift values for the specified key(s).

max_per_class_error(thresholds=None, train=False, valid=False, xval=False)[source]

Get the max per class error for a set of thresholds.

If all are False (default), then return the training metric value. If more than one options is set to True, then return a dictionary of metrics where the keys are “train”, “valid”, and “xval”.

Parameters:
  • thresholds – If None, then the thresholds in this set of metrics will be used.
  • train (bool) – If True, return the max per class error value for the training data.
  • valid (bool) – If True, return the max per class error value for the validation data.
  • xval (bool) – If True, return the max per class error value for each of the cross-validated splits.
Returns:

The max per class error values for the specified key(s).

mcc(thresholds=None, train=False, valid=False, xval=False)[source]

Get the MCC for a set of thresholds.

If all are False (default), then return the training metric value. If more than one options is set to True, then return a dictionary of metrics where the keys are “train”, “valid”, and “xval”.

Parameters:
  • thresholds – If None, then the thresholds in this set of metrics will be used.
  • train (bool) – If True, return the MCC value for the training data.
  • valid (bool) – If True, return the MCC value for the validation data.
  • xval (bool) – If True, return the MCC value for each of the cross-validated splits.
Returns:

The MCC values for the specified key(s).

mean_per_class_error(thresholds=None, train=False, valid=False, xval=False)[source]

Get the mean per class error for a set of thresholds.

If all are False (default), then return the training metric value. If more than one options is set to True, then return a dictionary of metrics where the keys are “train”, “valid”, and “xval”.

Parameters:
  • thresholds – If None, then the thresholds in this set of metrics will be used.
  • train (bool) – If True, return the mean per class error value for the training data.
  • valid (bool) – If True, return the mean per class error value for the validation data.
  • xval (bool) – If True, return the mean per class error value for each of the cross-validated splits.
Returns:

The mean per class error values for the specified key(s).

metric(metric, thresholds=None, train=False, valid=False, xval=False)[source]

Get the metric value for a set of thresholds.

If all are False (default), then return the training metric value. If more than one options is set to True, then return a dictionary of metrics where the keys are “train”, “valid”, and “xval”.

Parameters:
  • metric (str) – name of the metric to retrieve.
  • thresholds – If None, then the thresholds in this set of metrics will be used.
  • train (bool) – If True, return the metric value for the training data.
  • valid (bool) – If True, return the metric value for the validation data.
  • xval (bool) – If True, return the metric value for each of the cross-validated splits.
Returns:

The metric values for the specified key(s).

missrate(thresholds=None, train=False, valid=False, xval=False)[source]

Get the miss rate for a set of thresholds (aka False Negative Rate).

If all are False (default), then return the training metric value. If more than one options is set to True, then return a dictionary of metrics where the keys are “train”, “valid”, and “xval”.

Parameters:
  • thresholds – If None, then the thresholds in this set of metrics will be used.
  • train (bool) – If True, return the miss rate value for the training data.
  • valid (bool) – If True, return the miss rate value for the validation data.
  • xval (bool) – If True, return the miss rate value for each of the cross-validated splits.
Returns:

The miss rate values for the specified key(s).

plot(timestep=u'AUTO', metric=u'AUTO', server=False, **kwargs)[source]

Plot training set (and validation set if available) scoring history for an H2OBinomialModel.

The timestep and metric arguments are restricted to what is available in its scoring history.

Parameters:
  • timestep (str) – A unit of measurement for the x-axis.
  • metric (str) – A unit of measurement for the y-axis.
  • server (bool) – if True, then generate the image inline (using matplotlib’s “Agg” backend)
precision(thresholds=None, train=False, valid=False, xval=False)[source]

Get the precision for a set of thresholds.

If all are False (default), then return the training metric value. If more than one options is set to True, then return a dictionary of metrics where the keys are “train”, “valid”, and “xval”.

Parameters:
  • thresholds – If None, then the thresholds in this set of metrics will be used.
  • train (bool) – If True, return the precision value for the training data.
  • valid (bool) – If True, return the precision value for the validation data.
  • xval (bool) – If True, return the precision value for each of the cross-validated splits.
Returns:

The precision values for the specified key(s).

recall(thresholds=None, train=False, valid=False, xval=False)[source]

Get the recall for a set of thresholds (aka True Positive Rate).

If all are False (default), then return the training metric value. If more than one options is set to True, then return a dictionary of metrics where the keys are “train”, “valid”, and “xval”.

Parameters:
  • thresholds – If None, then the thresholds in this set of metrics will be used.
  • train (bool) – If True, return the recall value for the training data.
  • valid (bool) – If True, return the recall value for the validation data.
  • xval (bool) – If True, return the recall value for each of the cross-validated splits.
Returns:

The recall values for the specified key(s).

roc(train=False, valid=False, xval=False)[source]

Return the coordinates of the ROC curve for a given set of data.

The coordinates are two-tuples containing the false positive rates as a list and true positive rates as a list. If all are False (default), then return is the training data. If more than one ROC curve is requested, the data is returned as a dictionary of two-tuples.

Parameters:
  • train (bool) – If True, return the ROC value for the training data.
  • valid (bool) – If True, return the ROC value for the validation data.
  • xval (bool) – If True, return the ROC value for each of the cross-validated splits.
Returns:

The ROC values for the specified key(s).

sensitivity(thresholds=None, train=False, valid=False, xval=False)[source]

Get the sensitivity for a set of thresholds (aka True Positive Rate or Recall).

If all are False (default), then return the training metric value. If more than one options is set to True, then return a dictionary of metrics where the keys are “train”, “valid”, and “xval”.

Parameters:
  • thresholds – If None, then the thresholds in this set of metrics will be used.
  • train (bool) – If True, return the sensitivity value for the training data.
  • valid (bool) – If True, return the sensitivity value for the validation data.
  • xval (bool) – If True, return the sensitivity value for each of the cross-validated splits.
Returns:

The sensitivity values for the specified key(s).

specificity(thresholds=None, train=False, valid=False, xval=False)[source]

Get the specificity for a set of thresholds (aka True Negative Rate).

If all are False (default), then return the training metric value. If more than one options is set to True, then return a dictionary of metrics where the keys are “train”, “valid”, and “xval”.

Parameters:
  • thresholds – If None, then the thresholds in this set of metrics will be used.
  • train (bool) – If True, return the specificity value for the training data.
  • valid (bool) – If True, return the specificity value for the validation data.
  • xval (bool) – If True, return the specificity value for each of the cross-validated splits.
Returns:

The specificity values for the specified key(s).

tnr(thresholds=None, train=False, valid=False, xval=False)[source]

Get the True Negative Rate for a set of thresholds.

If all are False (default), then return the training metric value. If more than one options is set to True, then return a dictionary of metrics where the keys are “train”, “valid”, and “xval”.

Parameters:
  • thresholds – If None, then the thresholds in this set of metrics will be used.
  • train (bool) – If True, return the TNR value for the training data.
  • valid (bool) – If True, return the TNR value for the validation data.
  • xval (bool) – If True, return the TNR value for each of the cross-validated splits.
Returns:

The TNR values for the specified key(s).

tpr(thresholds=None, train=False, valid=False, xval=False)[source]

Get the True Positive Rate for a set of thresholds.

If all are False (default), then return the training metric value. If more than one options is set to True, then return a dictionary of metrics where the keys are “train”, “valid”, and “xval”.

Parameters:
  • thresholds – If None, then the thresholds in this set of metrics will be used.
  • train (bool) – If True, return the TPR value for the training data.
  • valid (bool) – If True, return the TPR value for the validation data.
  • xval (bool) – If True, return the TPR value for each of the cross-validated splits.
Returns:

The TPR values for the specified key(s).

class h2o.model.H2OClusteringModel[source]

Bases: h2o.model.model_base.ModelBase

betweenss(train=False, valid=False, xval=False)[source]

Get the between cluster sum of squares.

If all are False (default), then return the training metric value. If more than one options is set to True, then return a dictionary of metrics where the keys are “train”, “valid”, and “xval”.

Parameters:
  • train (bool) – If True, return the between cluster sum of squares value for the training data.
  • valid (bool) – If True, return the between cluster sum of squares value for the validation data.
  • xval (bool) – If True, return the between cluster sum of squares value for each of the cross-validated splits.
Returns:

The between cluster sum of squares values for the specified key(s).

centers()[source]

The centers for the KMeans model.

centers_std()[source]

The standardized centers for the kmeans model.

centroid_stats(train=False, valid=False, xval=False)[source]

Get the centroid statistics for each cluster.

If all are False (default), then return the training metric value. If more than one options is set to True, then return a dictionary of metrics where the keys are “train”, “valid”, and “xval”.

Parameters:
  • train (bool) – If True, return the centroid statistic for the training data.
  • valid (bool) – If True, return the centroid statistic for the validation data.
  • xval (bool) – If True, return the centroid statistic for each of the cross-validated splits.
Returns:

The centroid statistics for the specified key(s).

num_iterations()[source]

Get the number of iterations it took to converge or reach max iterations.

size(train=False, valid=False, xval=False)[source]

Get the sizes of each cluster.

If all are False (default), then return the training metric value. If more than one options is set to True, then return a dictionary of metrics where the keys are “train”, “valid”, and “xval”.

Parameters:
  • train (bool) – If True, return the cluster sizes for the training data.
  • valid (bool) – If True, return the cluster sizes for the validation data.
  • xval (bool) – If True, return the cluster sizes for each of the cross-validated splits.
Returns:

The cluster sizes for the specified key(s).

tot_withinss(train=False, valid=False, xval=False)[source]

Get the total within cluster sum of squares.

If all are False (default), then return the training metric value. If more than one options is set to True, then return a dictionary of metrics where the keys are “train”, “valid”, and “xval”.

Parameters:
  • train (bool) – If True, return the total within cluster sum of squares value for the training data.
  • valid (bool) – If True, return the total within cluster sum of squares value for the validation data.
  • xval (bool) – If True, return the total within cluster sum of squares value for each of the cross-validated splits.
Returns:

The total within cluster sum of squares values for the specified key(s).

totss(train=False, valid=False, xval=False)[source]

Get the total sum of squares.

If all are False (default), then return the training metric value. If more than one options is set to True, then return a dictionary of metrics where the keys are “train”, “valid”, and “xval”.

Parameters:
  • train (bool) – If True, return the total sum of squares value for the training data.
  • valid (bool) – If True, return the total sum of squares value for the validation data.
  • xval (bool) – If True, return the total sum of squares value for each of the cross-validated splits.
Returns:

The total sum of squares values for the specified key(s).

withinss(train=False, valid=False, xval=False)[source]

Get the within cluster sum of squares for each cluster.

If all are False (default), then return the training metric value. If more than one options is set to True, then return a dictionary of metrics where the keys are “train”, “valid”, and “xval”.

Parameters:
  • train (bool) – If True, return the total sum of squares value for the training data.
  • valid (bool) – If True, return the total sum of squares value for the validation data.
  • xval (bool) – If True, return the total sum of squares value for each of the cross-validated splits.
Returns:

The total sum of squares values for the specified key(s).

class h2o.model.ConfusionMatrix(cm, domains=None, table_header=None)[source]

Bases: object

ROUND = 4
static read_cms(cms=None, domains=None)[source]

Read confusion matrices from the list of sources (?).

show()[source]

Print the confusion matrix into the console.

to_list()[source]

Convert this confusion matrix into a 2x2 plain list of values.

class h2o.model.H2ODimReductionModel[source]

Bases: h2o.model.model_base.ModelBase

Dimension reduction model, such as PCA or GLRM.

archetypes()[source]

The archetypes (Y) of the GLRM model.

final_step()[source]

Get the final step size for the model.

num_iterations()[source]

Get the number of iterations that it took to converge or reach max iterations.

objective()[source]

Get the final value of the objective function.

proj_archetypes(test_data, reverse_transform=False)[source]

Convert archetypes of the model into original feature space.

Parameters:
  • test_data (H2OFrame) – The dataset upon which the model was trained.
  • reverse_transform (bool) – Whether the transformation of the training data during model-building should be reversed on the projected archetypes.
Returns:

model archetypes projected back into the original training data’s feature space.

reconstruct(test_data, reverse_transform=False)[source]

Reconstruct the training data from the model and impute all missing values.

Parameters:
  • test_data (H2OFrame) – The dataset upon which the model was trained.
  • reverse_transform (bool) – Whether the transformation of the training data during model-building should be reversed on the reconstructed frame.
Returns:

the approximate reconstruction of the training data.

screeplot(type=u'barplot', **kwargs)[source]

Produce the scree plot.

Library matplotlib is required for this function.

Parameters:type (str) – either "barplot" or "lines".
class h2o.model.MetricsBase(metric_json, on=None, algo=u'')[source]

Bases: h2o.utils.backward_compatibility.BackwardsCompatibleBase

A parent class to house common metrics available for the various Metrics types.

The methods here are available across different model categories.

aic()[source]

The AIC for this set of metrics.

auc()[source]

The AUC for this set of metrics.

gini()[source]

Gini coefficient.

logloss()[source]

Log loss.

mae()[source]

The MAE for this set of metrics.

classmethod make(kvs)[source]

Factory method to instantiate a MetricsBase object from the list of key-value pairs.

mean_per_class_error()[source]

The mean per class error.

mean_residual_deviance()[source]

The mean residual deviance for this set of metrics.

mse()[source]

The MSE for this set of metrics.

nobs()[source]

The number of observations.

null_degrees_of_freedom()[source]

The null DoF if the model has residual deviance, otherwise None.

null_deviance()[source]

The null deviance if the model has residual deviance, otherwise None.

r2()[source]

The R squared coefficient.

residual_degrees_of_freedom()[source]

The residual DoF if the model has residual deviance, otherwise None.

residual_deviance()[source]

The residual deviance if the model has it, otherwise None.

rmse()[source]

The RMSE for this set of metrics.

rmsle()[source]

The RMSLE for this set of metrics.

show()[source]

Display a short summary of the metrics.

class h2o.model.ModelBase[source]

Bases: h2o.utils.backward_compatibility.BackwardsCompatibleBase

Base class for all models.

actual_params

Dictionary of actual parameters of the model.

aic(train=False, valid=False, xval=False)[source]

Get the AIC (Akaike Information Criterium).

If all are False (default), then return the training metric value. If more than one options is set to True, then return a dictionary of metrics where the keys are “train”, “valid”, and “xval”.

Parameters:
  • train (bool) – If train is True, then return the AIC value for the training data.
  • valid (bool) – If valid is True, then return the AIC value for the validation data.
  • xval (bool) – If xval is True, then return the AIC value for the validation data.
Returns:

The AIC.

auc(train=False, valid=False, xval=False)[source]

Get the AUC (Area Under Curve).

If all are False (default), then return the training metric value. If more than one options is set to True, then return a dictionary of metrics where the keys are “train”, “valid”, and “xval”.

Parameters:
  • train (bool) – If train is True, then return the AUC value for the training data.
  • valid (bool) – If valid is True, then return the AUC value for the validation data.
  • xval (bool) – If xval is True, then return the AUC value for the validation data.
Returns:

The AUC.

biases(vector_id=0)[source]

Return the frame for the respective bias vector.

Param:vector_id: an integer, ranging from 0 to number of layers, that specifies the bias vector to return.
Returns:an H2OFrame which represents the bias vector identified by vector_id
catoffsets()[source]

Categorical offsets for one-hot encoding.

coef()[source]

Return the coefficients which can be applied to the non-standardized data.

Note: standardize = True by default, if set to False then coef() return the coefficients which are fit directly.

coef_norm()[source]

Return coefficients fitted on the standardized data (requires standardize = True, which is on by default).

These coefficients can be used to evaluate variable importance.

cross_validation_fold_assignment()[source]

Obtain the cross-validation fold assignment for all rows in the training data.

Returns:H2OFrame
cross_validation_holdout_predictions()[source]

Obtain the (out-of-sample) holdout predictions of all cross-validation models on the training data.

This is equivalent to summing up all H2OFrames returned by cross_validation_predictions.

Returns:H2OFrame
cross_validation_metrics_summary()[source]

Retrieve Cross-Validation Metrics Summary.

Returns:The cross-validation metrics summary as an H2OTwoDimTable
cross_validation_models()[source]

Obtain a list of cross-validation models.

Returns:list of H2OModel objects.
cross_validation_predictions()[source]

Obtain the (out-of-sample) holdout predictions of all cross-validation models on their holdout data.

Note that the predictions are expanded to the full number of rows of the training data, with 0 fill-in.

Returns:list of H2OFrame objects.
deepfeatures(test_data, layer)[source]

Return hidden layer details.

Parameters:
  • test_data – Data to create a feature space on
  • layer – 0 index hidden layer
default_params

Dictionary of the default parameters of the model.

download_mojo(path=u'.', get_genmodel_jar=False, genmodel_name=u'')[source]

Download the model in MOJO format.

Parameters:
  • path – the path where MOJO file should be saved.
  • get_genmodel_jar – if True, then also download h2o-genmodel.jar and store it in folder path.

:param genmodel_name Custom name of genmodel jar :returns: name of the MOJO file written.

download_pojo(path=u'', get_genmodel_jar=False, genmodel_name=u'')[source]

Download the POJO for this model to the directory specified by path.

If path is an empty string, then dump the output to screen.

Parameters:
  • path – An absolute path to the directory where POJO should be saved.
  • get_genmodel_jar – if True, then also download h2o-genmodel.jar and store it in folder path.

:param genmodel_name Custom name of genmodel jar :returns: name of the POJO file written.

full_parameters

Dictionary of the full specification of all parameters.

get_xval_models(key=None)[source]

Return a Model object.

Parameters:key – If None, return all cross-validated models; otherwise return the model that key points to.
Returns:A model or list of models.
gini(train=False, valid=False, xval=False)[source]

Get the Gini coefficient.

If all are False (default), then return the training metric value. If more than one options is set to True, then return a dictionary of metrics where the keys are “train”, “valid”, and “xval”

Parameters:
  • train (bool) – If train is True, then return the Gini Coefficient value for the training data.
  • valid (bool) – If valid is True, then return the Gini Coefficient value for the validation data.
  • xval (bool) – If xval is True, then return the Gini Coefficient value for the cross validation data.
Returns:

The Gini Coefficient for this binomial model.

is_cross_validated()[source]

Return True if the model was cross-validated.

logloss(train=False, valid=False, xval=False)[source]

Get the Log Loss.

If all are False (default), then return the training metric value. If more than one options is set to True, then return a dictionary of metrics where the keys are “train”, “valid”, and “xval”.

Parameters:
  • train (bool) – If train is True, then return the log loss value for the training data.
  • valid (bool) – If valid is True, then return the log loss value for the validation data.
  • xval (bool) – If xval is True, then return the log loss value for the cross validation data.
Returns:

The log loss for this regression model.

mae(train=False, valid=False, xval=False)[source]

Get the Mean Absolute Error.

If all are False (default), then return the training metric value. If more than one options is set to True, then return a dictionary of metrics where the keys are “train”, “valid”, and “xval”.

Parameters:
  • train (bool) – If train is True, then return the MAE value for the training data.
  • valid (bool) – If valid is True, then return the MAE value for the validation data.
  • xval (bool) – If xval is True, then return the MAE value for the cross validation data.
Returns:

The MAE for this regression model.

mean_residual_deviance(train=False, valid=False, xval=False)[source]

Get the Mean Residual Deviances.

If all are False (default), then return the training metric value. If more than one options is set to True, then return a dictionary of metrics where the keys are “train”, “valid”, and “xval”.

Parameters:
  • train (bool) – If train is True, then return the Mean Residual Deviance value for the training data.
  • valid (bool) – If valid is True, then return the Mean Residual Deviance value for the validation data.
  • xval (bool) – If xval is True, then return the Mean Residual Deviance value for the cross validation data.
Returns:

The Mean Residual Deviance for this regression model.

metalearner()[source]

Print the metalearner for the model, if any. Currently only used by H2OStackedEnsembleEstimator.

model_id

Model identifier.

model_performance(test_data=None, train=False, valid=False, xval=False)[source]

Generate model metrics for this model on test_data.

Parameters:
  • test_data (H2OFrame) – Data set for which model metrics shall be computed against. All three of train, valid and xval arguments are ignored if test_data is not None.
  • train (bool) – Report the training metrics for the model.
  • valid (bool) – Report the validation metrics for the model.
  • xval (bool) – Report the cross-validation metrics for the model. If train and valid are True, then it defaults to True.
Returns:

An object of class H2OModelMetrics.

mse(train=False, valid=False, xval=False)[source]

Get the Mean Square Error.

If all are False (default), then return the training metric value. If more than one options is set to True, then return a dictionary of metrics where the keys are “train”, “valid”, and “xval”.

Parameters:
  • train (bool) – If train is True, then return the MSE value for the training data.
  • valid (bool) – If valid is True, then return the MSE value for the validation data.
  • xval (bool) – If xval is True, then return the MSE value for the cross validation data.
Returns:

The MSE for this regression model.

normmul()[source]

Normalization/Standardization multipliers for numeric predictors.

normsub()[source]

Normalization/Standardization offsets for numeric predictors.

null_degrees_of_freedom(train=False, valid=False, xval=False)[source]

Retreive the null degress of freedom if this model has the attribute, or None otherwise.

Parameters:
  • train (bool) – Get the null dof for the training set. If both train and valid are False, then train is selected by default.
  • valid (bool) – Get the null dof for the validation set. If both train and valid are True, then train is selected by default.
Returns:

Return the null dof, or None if it is not present.

null_deviance(train=False, valid=False, xval=False)[source]

Retreive the null deviance if this model has the attribute, or None otherwise.

Parameters:
  • train (bool) – Get the null deviance for the training set. If both train and valid are False, then train is selected by default.
  • valid (bool) – Get the null deviance for the validation set. If both train and valid are True, then train is selected by default.
Returns:

Return the null deviance, or None if it is not present.

params

Get the parameters and the actual/default values only.

Returns:A dictionary of parameters used to build this model.
partial_plot(data, cols, destination_key=None, nbins=20, plot=True, plot_stddev=True, figsize=(7, 10), server=False)[source]

Create partial dependence plot which gives a graphical depiction of the marginal effect of a variable on the response. The effect of a variable is measured in change in the mean response.

Parameters:
  • data (H2OFrame) – An H2OFrame object used for scoring and constructing the plot.
  • cols – Feature(s) for which partial dependence will be calculated.
  • destination_key – An key reference to the created partial dependence tables in H2O.
  • nbins – Number of bins used. For categorical columns make sure the number of bins exceed the level count.
  • plot – A boolean specifying whether to plot partial dependence table.
  • plot_stddev – A boolean specifying whether to add std err to partial dependence plot.
  • figsize – Dimension/size of the returning plots, adjust to fit your output cells.
  • server

    ?

Returns:

Plot and list of calculated mean response tables for each feature requested.

pprint_coef()[source]

Pretty print the coefficents table (includes normalized coefficients).

predict(test_data)[source]

Predict on a dataset.

Parameters:test_data (H2OFrame) – Data on which to make predictions.
Returns:A new H2OFrame of predictions.
predict_leaf_node_assignment(test_data)[source]

Predict on a dataset and return the leaf node assignment (only for tree-based models).

Parameters:test_data (H2OFrame) – Data on which to make predictions.
Returns:A new H2OFrame of predictions.
r2(train=False, valid=False, xval=False)[source]

Return the R squared for this regression model.

Will return R^2 for GLM Models and will return NaN otherwise.

The R^2 value is defined to be 1 - MSE/var, where var is computed as sigma*sigma.

If all are False (default), then return the training metric value. If more than one options is set to True, then return a dictionary of metrics where the keys are “train”, “valid”, and “xval”.

Parameters:
  • train (bool) – If train is True, then return the R^2 value for the training data.
  • valid (bool) – If valid is True, then return the R^2 value for the validation data.
  • xval (bool) – If xval is True, then return the R^2 value for the cross validation data.
Returns:

The R squared for this regression model.

residual_degrees_of_freedom(train=False, valid=False, xval=False)[source]

Retreive the residual degress of freedom if this model has the attribute, or None otherwise.

Parameters:
  • train (bool) – Get the residual dof for the training set. If both train and valid are False, then train is selected by default.
  • valid (bool) – Get the residual dof for the validation set. If both train and valid are True, then train is selected by default.
Returns:

Return the residual dof, or None if it is not present.

residual_deviance(train=False, valid=False, xval=None)[source]

Retreive the residual deviance if this model has the attribute, or None otherwise.

Parameters:
  • train (bool) – Get the residual deviance for the training set. If both train and valid are False, then train is selected by default.
  • valid (bool) – Get the residual deviance for the validation set. If both train and valid are True, then train is selected by default.
Returns:

Return the residual deviance, or None if it is not present.

respmul()[source]

Normalization/Standardization multipliers for numeric response.

respsub()[source]

Normalization/Standardization offsets for numeric response.

rmse(train=False, valid=False, xval=False)[source]

Get the Root Mean Square Error.

If all are False (default), then return the training metric value. If more than one options is set to True, then return a dictionary of metrics where the keys are “train”, “valid”, and “xval”.

Parameters:
  • train (bool) – If train is True, then return the RMSE value for the training data.
  • valid (bool) – If valid is True, then return the RMSE value for the validation data.
  • xval (bool) – If xval is True, then return the RMSE value for the cross validation data.
Returns:

The RMSE for this regression model.

rmsle(train=False, valid=False, xval=False)[source]

Get the Root Mean Squared Logarithmic Error.

If all are False (default), then return the training metric value. If more than one options is set to True, then return a dictionary of metrics where the keys are “train”, “valid”, and “xval”.

Parameters:
  • train (bool) – If train is True, then return the RMSLE value for the training data.
  • valid (bool) – If valid is True, then return the RMSLE value for the validation data.
  • xval (bool) – If xval is True, then return the RMSLE value for the cross validation data.
Returns:

The RMSLE for this regression model.

rotation()[source]

Obtain the rotations (eigenvectors) for a PCA model

Returns:H2OFrame
save_model_details(path=u'', force=False)[source]

Save Model Details of an H2O Model in JSON Format to disk.

Parameters:
  • model – The model object to save.
  • path – a path to save the model details at (hdfs, s3, local)
  • force – if True overwrite destination directory in case it exists, or throw exception if set to False.
Returns str:

the path of the saved model details

save_mojo(path=u'', force=False)[source]

Save an H2O Model as MOJO (Model Object, Optimized) to disk.

Parameters:
  • model – The model object to save.
  • path – a path to save the model at (hdfs, s3, local)
  • force – if True overwrite destination directory in case it exists, or throw exception if set to False.
Returns str:

the path of the saved model

score_history()[source]

DEPRECATED. Use scoring_history() instead.

scoring_history()[source]

Retrieve Model Score History.

Returns:The score history as an H2OTwoDimTable or a Pandas DataFrame.
show()[source]

Print innards of model, without regards to type.

std_coef_plot(num_of_features=None, server=False)[source]

Plot a GLM model”s standardized coefficient magnitudes.

Parameters:
  • num_of_features – the number of features shown in the plot.
  • server

    ?

Returns:

None.

summary()[source]

Print a detailed summary of the model.

type

The type of model built: "classifier" or "regressor" or "unsupervised"

varimp(use_pandas=False)[source]

Pretty print the variable importances, or return them in a list.

Parameters:use_pandas – If True, then the variable importances will be returned as a pandas data frame.
Returns:A list or Pandas DataFrame.
varimp_plot(num_of_features=None, server=False)[source]

Plot the variable importance for a trained model.

Parameters:
  • num_of_features – the number of features shown in the plot.
  • server

    ?

Returns:

None.

weights(matrix_id=0)[source]

Return the frame for the respective weight matrix.

Param:matrix_id: an integer, ranging from 0 to number of layers, that specifies the weight matrix to return.
Returns:an H2OFrame which represents the weight matrix identified by matrix_id
xval_keys()[source]

Return model keys for the cross-validated model.

xvals

Return a list of the cross-validated models.

Returns:A list of models.
class h2o.model.H2OModelFuture(job, x)[source]

Bases: object

A class representing a future H2O model (a model that may, or may not, be in the process of being built).

poll()[source]

ModelBase

class h2o.model.model_base.ModelBase[source]

Bases: h2o.utils.backward_compatibility.BackwardsCompatibleBase

Base class for all models.

actual_params

Dictionary of actual parameters of the model.

aic(train=False, valid=False, xval=False)[source]

Get the AIC (Akaike Information Criterium).

If all are False (default), then return the training metric value. If more than one options is set to True, then return a dictionary of metrics where the keys are “train”, “valid”, and “xval”.

Parameters:
  • train (bool) – If train is True, then return the AIC value for the training data.
  • valid (bool) – If valid is True, then return the AIC value for the validation data.
  • xval (bool) – If xval is True, then return the AIC value for the validation data.
Returns:

The AIC.

auc(train=False, valid=False, xval=False)[source]

Get the AUC (Area Under Curve).

If all are False (default), then return the training metric value. If more than one options is set to True, then return a dictionary of metrics where the keys are “train”, “valid”, and “xval”.

Parameters:
  • train (bool) – If train is True, then return the AUC value for the training data.
  • valid (bool) – If valid is True, then return the AUC value for the validation data.
  • xval (bool) – If xval is True, then return the AUC value for the validation data.
Returns:

The AUC.

biases(vector_id=0)[source]

Return the frame for the respective bias vector.

Param:vector_id: an integer, ranging from 0 to number of layers, that specifies the bias vector to return.
Returns:an H2OFrame which represents the bias vector identified by vector_id
catoffsets()[source]

Categorical offsets for one-hot encoding.

coef()[source]

Return the coefficients which can be applied to the non-standardized data.

Note: standardize = True by default, if set to False then coef() return the coefficients which are fit directly.

coef_norm()[source]

Return coefficients fitted on the standardized data (requires standardize = True, which is on by default).

These coefficients can be used to evaluate variable importance.

cross_validation_fold_assignment()[source]

Obtain the cross-validation fold assignment for all rows in the training data.

Returns:H2OFrame
cross_validation_holdout_predictions()[source]

Obtain the (out-of-sample) holdout predictions of all cross-validation models on the training data.

This is equivalent to summing up all H2OFrames returned by cross_validation_predictions.

Returns:H2OFrame
cross_validation_metrics_summary()[source]

Retrieve Cross-Validation Metrics Summary.

Returns:The cross-validation metrics summary as an H2OTwoDimTable
cross_validation_models()[source]

Obtain a list of cross-validation models.

Returns:list of H2OModel objects.
cross_validation_predictions()[source]

Obtain the (out-of-sample) holdout predictions of all cross-validation models on their holdout data.

Note that the predictions are expanded to the full number of rows of the training data, with 0 fill-in.

Returns:list of H2OFrame objects.
deepfeatures(test_data, layer)[source]

Return hidden layer details.

Parameters:
  • test_data – Data to create a feature space on
  • layer – 0 index hidden layer
default_params

Dictionary of the default parameters of the model.

download_mojo(path=u'.', get_genmodel_jar=False, genmodel_name=u'')[source]

Download the model in MOJO format.

Parameters:
  • path – the path where MOJO file should be saved.
  • get_genmodel_jar – if True, then also download h2o-genmodel.jar and store it in folder path.

:param genmodel_name Custom name of genmodel jar :returns: name of the MOJO file written.

download_pojo(path=u'', get_genmodel_jar=False, genmodel_name=u'')[source]

Download the POJO for this model to the directory specified by path.

If path is an empty string, then dump the output to screen.

Parameters:
  • path – An absolute path to the directory where POJO should be saved.
  • get_genmodel_jar – if True, then also download h2o-genmodel.jar and store it in folder path.

:param genmodel_name Custom name of genmodel jar :returns: name of the POJO file written.

full_parameters

Dictionary of the full specification of all parameters.

get_xval_models(key=None)[source]

Return a Model object.

Parameters:key – If None, return all cross-validated models; otherwise return the model that key points to.
Returns:A model or list of models.
gini(train=False, valid=False, xval=False)[source]

Get the Gini coefficient.

If all are False (default), then return the training metric value. If more than one options is set to True, then return a dictionary of metrics where the keys are “train”, “valid”, and “xval”

Parameters:
  • train (bool) – If train is True, then return the Gini Coefficient value for the training data.
  • valid (bool) – If valid is True, then return the Gini Coefficient value for the validation data.
  • xval (bool) – If xval is True, then return the Gini Coefficient value for the cross validation data.
Returns:

The Gini Coefficient for this binomial model.

is_cross_validated()[source]

Return True if the model was cross-validated.

logloss(train=False, valid=False, xval=False)[source]

Get the Log Loss.

If all are False (default), then return the training metric value. If more than one options is set to True, then return a dictionary of metrics where the keys are “train”, “valid”, and “xval”.

Parameters:
  • train (bool) – If train is True, then return the log loss value for the training data.
  • valid (bool) – If valid is True, then return the log loss value for the validation data.
  • xval (bool) – If xval is True, then return the log loss value for the cross validation data.
Returns:

The log loss for this regression model.

mae(train=False, valid=False, xval=False)[source]

Get the Mean Absolute Error.

If all are False (default), then return the training metric value. If more than one options is set to True, then return a dictionary of metrics where the keys are “train”, “valid”, and “xval”.

Parameters:
  • train (bool) – If train is True, then return the MAE value for the training data.
  • valid (bool) – If valid is True, then return the MAE value for the validation data.
  • xval (bool) – If xval is True, then return the MAE value for the cross validation data.
Returns:

The MAE for this regression model.

mean_residual_deviance(train=False, valid=False, xval=False)[source]

Get the Mean Residual Deviances.

If all are False (default), then return the training metric value. If more than one options is set to True, then return a dictionary of metrics where the keys are “train”, “valid”, and “xval”.

Parameters:
  • train (bool) – If train is True, then return the Mean Residual Deviance value for the training data.
  • valid (bool) – If valid is True, then return the Mean Residual Deviance value for the validation data.
  • xval (bool) – If xval is True, then return the Mean Residual Deviance value for the cross validation data.
Returns:

The Mean Residual Deviance for this regression model.

metalearner()[source]

Print the metalearner for the model, if any. Currently only used by H2OStackedEnsembleEstimator.

model_id

Model identifier.

model_performance(test_data=None, train=False, valid=False, xval=False)[source]

Generate model metrics for this model on test_data.

Parameters:
  • test_data (H2OFrame) – Data set for which model metrics shall be computed against. All three of train, valid and xval arguments are ignored if test_data is not None.
  • train (bool) – Report the training metrics for the model.
  • valid (bool) – Report the validation metrics for the model.
  • xval (bool) – Report the cross-validation metrics for the model. If train and valid are True, then it defaults to True.
Returns:

An object of class H2OModelMetrics.

mse(train=False, valid=False, xval=False)[source]

Get the Mean Square Error.

If all are False (default), then return the training metric value. If more than one options is set to True, then return a dictionary of metrics where the keys are “train”, “valid”, and “xval”.

Parameters:
  • train (bool) – If train is True, then return the MSE value for the training data.
  • valid (bool) – If valid is True, then return the MSE value for the validation data.
  • xval (bool) – If xval is True, then return the MSE value for the cross validation data.
Returns:

The MSE for this regression model.

normmul()[source]

Normalization/Standardization multipliers for numeric predictors.

normsub()[source]

Normalization/Standardization offsets for numeric predictors.

null_degrees_of_freedom(train=False, valid=False, xval=False)[source]

Retreive the null degress of freedom if this model has the attribute, or None otherwise.

Parameters:
  • train (bool) – Get the null dof for the training set. If both train and valid are False, then train is selected by default.
  • valid (bool) – Get the null dof for the validation set. If both train and valid are True, then train is selected by default.
Returns:

Return the null dof, or None if it is not present.

null_deviance(train=False, valid=False, xval=False)[source]

Retreive the null deviance if this model has the attribute, or None otherwise.

Parameters:
  • train (bool) – Get the null deviance for the training set. If both train and valid are False, then train is selected by default.
  • valid (bool) – Get the null deviance for the validation set. If both train and valid are True, then train is selected by default.
Returns:

Return the null deviance, or None if it is not present.

params

Get the parameters and the actual/default values only.

Returns:A dictionary of parameters used to build this model.
partial_plot(data, cols, destination_key=None, nbins=20, plot=True, plot_stddev=True, figsize=(7, 10), server=False)[source]

Create partial dependence plot which gives a graphical depiction of the marginal effect of a variable on the response. The effect of a variable is measured in change in the mean response.

Parameters:
  • data (H2OFrame) – An H2OFrame object used for scoring and constructing the plot.
  • cols – Feature(s) for which partial dependence will be calculated.
  • destination_key – An key reference to the created partial dependence tables in H2O.
  • nbins – Number of bins used. For categorical columns make sure the number of bins exceed the level count.
  • plot – A boolean specifying whether to plot partial dependence table.
  • plot_stddev – A boolean specifying whether to add std err to partial dependence plot.
  • figsize – Dimension/size of the returning plots, adjust to fit your output cells.
  • server

    ?

Returns:

Plot and list of calculated mean response tables for each feature requested.

pprint_coef()[source]

Pretty print the coefficents table (includes normalized coefficients).

predict(test_data)[source]

Predict on a dataset.

Parameters:test_data (H2OFrame) – Data on which to make predictions.
Returns:A new H2OFrame of predictions.
predict_leaf_node_assignment(test_data)[source]

Predict on a dataset and return the leaf node assignment (only for tree-based models).

Parameters:test_data (H2OFrame) – Data on which to make predictions.
Returns:A new H2OFrame of predictions.
r2(train=False, valid=False, xval=False)[source]

Return the R squared for this regression model.

Will return R^2 for GLM Models and will return NaN otherwise.

The R^2 value is defined to be 1 - MSE/var, where var is computed as sigma*sigma.

If all are False (default), then return the training metric value. If more than one options is set to True, then return a dictionary of metrics where the keys are “train”, “valid”, and “xval”.

Parameters:
  • train (bool) – If train is True, then return the R^2 value for the training data.
  • valid (bool) – If valid is True, then return the R^2 value for the validation data.
  • xval (bool) – If xval is True, then return the R^2 value for the cross validation data.
Returns:

The R squared for this regression model.

residual_degrees_of_freedom(train=False, valid=False, xval=False)[source]

Retreive the residual degress of freedom if this model has the attribute, or None otherwise.

Parameters:
  • train (bool) – Get the residual dof for the training set. If both train and valid are False, then train is selected by default.
  • valid (bool) – Get the residual dof for the validation set. If both train and valid are True, then train is selected by default.
Returns:

Return the residual dof, or None if it is not present.

residual_deviance(train=False, valid=False, xval=None)[source]

Retreive the residual deviance if this model has the attribute, or None otherwise.

Parameters:
  • train (bool) – Get the residual deviance for the training set. If both train and valid are False, then train is selected by default.
  • valid (bool) – Get the residual deviance for the validation set. If both train and valid are True, then train is selected by default.
Returns:

Return the residual deviance, or None if it is not present.

respmul()[source]

Normalization/Standardization multipliers for numeric response.

respsub()[source]

Normalization/Standardization offsets for numeric response.

rmse(train=False, valid=False, xval=False)[source]

Get the Root Mean Square Error.

If all are False (default), then return the training metric value. If more than one options is set to True, then return a dictionary of metrics where the keys are “train”, “valid”, and “xval”.

Parameters:
  • train (bool) – If train is True, then return the RMSE value for the training data.
  • valid (bool) – If valid is True, then return the RMSE value for the validation data.
  • xval (bool) – If xval is True, then return the RMSE value for the cross validation data.
Returns:

The RMSE for this regression model.

rmsle(train=False, valid=False, xval=False)[source]

Get the Root Mean Squared Logarithmic Error.

If all are False (default), then return the training metric value. If more than one options is set to True, then return a dictionary of metrics where the keys are “train”, “valid”, and “xval”.

Parameters:
  • train (bool) – If train is True, then return the RMSLE value for the training data.
  • valid (bool) – If valid is True, then return the RMSLE value for the validation data.
  • xval (bool) – If xval is True, then return the RMSLE value for the cross validation data.
Returns:

The RMSLE for this regression model.

rotation()[source]

Obtain the rotations (eigenvectors) for a PCA model

Returns:H2OFrame
save_model_details(path=u'', force=False)[source]

Save Model Details of an H2O Model in JSON Format to disk.

Parameters:
  • model – The model object to save.
  • path – a path to save the model details at (hdfs, s3, local)
  • force – if True overwrite destination directory in case it exists, or throw exception if set to False.
Returns str:

the path of the saved model details

save_mojo(path=u'', force=False)[source]

Save an H2O Model as MOJO (Model Object, Optimized) to disk.

Parameters:
  • model – The model object to save.
  • path – a path to save the model at (hdfs, s3, local)
  • force – if True overwrite destination directory in case it exists, or throw exception if set to False.
Returns str:

the path of the saved model

score_history()[source]

DEPRECATED. Use scoring_history() instead.

scoring_history()[source]

Retrieve Model Score History.

Returns:The score history as an H2OTwoDimTable or a Pandas DataFrame.
show()[source]

Print innards of model, without regards to type.

std_coef_plot(num_of_features=None, server=False)[source]

Plot a GLM model”s standardized coefficient magnitudes.

Parameters:
  • num_of_features – the number of features shown in the plot.
  • server

    ?

Returns:

None.

summary()[source]

Print a detailed summary of the model.

type

The type of model built: "classifier" or "regressor" or "unsupervised"

varimp(use_pandas=False)[source]

Pretty print the variable importances, or return them in a list.

Parameters:use_pandas – If True, then the variable importances will be returned as a pandas data frame.
Returns:A list or Pandas DataFrame.
varimp_plot(num_of_features=None, server=False)[source]

Plot the variable importance for a trained model.

Parameters:
  • num_of_features – the number of features shown in the plot.
  • server

    ?

Returns:

None.

weights(matrix_id=0)[source]

Return the frame for the respective weight matrix.

Param:matrix_id: an integer, ranging from 0 to number of layers, that specifies the weight matrix to return.
Returns:an H2OFrame which represents the weight matrix identified by matrix_id
xval_keys()[source]

Return model keys for the cross-validated model.

xvals

Return a list of the cross-validated models.

Returns:A list of models.

Binomial Classification

class h2o.model.binomial.H2OBinomialModel[source]

Bases: h2o.model.model_base.ModelBase

F0point5(thresholds=None, train=False, valid=False, xval=False)[source]

Get the F0.5 for a set of thresholds.

If all are False (default), then return the training metric value. If more than one options is set to True, then return a dictionary of metrics where the keys are “train”, “valid”, and “xval”.

Parameters:
  • thresholds – If None, then the thresholds in this set of metrics will be used.
  • train (bool) – If True, return the F0.5 value for the training data.
  • valid (bool) – If True, return the F0.5 value for the validation data.
  • xval (bool) – If True, return the F0.5 value for each of the cross-validated splits.
Returns:

The F0.5 values for the specified key(s).

F1(thresholds=None, train=False, valid=False, xval=False)[source]

Get the F1 value for a set of thresholds.

If all are False (default), then return the training metric value. If more than one options is set to True, then return a dictionary of metrics where the keys are “train”, “valid”, and “xval”.

Parameters:
  • thresholds – If None, then the thresholds in this set of metrics will be used.
  • train (bool) – If True, return the F1 value for the training data.
  • valid (bool) – If True, return the F1 value for the validation data.
  • xval (bool) – If True, return the F1 value for each of the cross-validated splits.
Returns:

The F1 values for the specified key(s).

Examples:
>>> import h2o as ml
>>> from h2o.estimators.gbm import H2OGradientBoostingEstimator
>>> ml.init()
>>> rows=[[1,2,3,4,0],[2,1,2,4,1],[2,1,4,2,1],[0,1,2,34,1],[2,3,4,1,0]]*50
>>> fr = ml.H2OFrame(rows)
>>> fr[4] = fr[4].asfactor()
>>> model = H2OGradientBoostingEstimator(ntrees=10, max_depth=10, nfolds=4)
>>> model.train(x=range(4), y=4, training_frame=fr)
>>> model.F1(train=True)
F2(thresholds=None, train=False, valid=False, xval=False)[source]

Get the F2 for a set of thresholds.

If all are False (default), then return the training metric value. If more than one options is set to True, then return a dictionary of metrics where the keys are “train”, “valid”, and “xval”.

Parameters:
  • thresholds – If None, then the thresholds in this set of metrics will be used.
  • train (bool) – If True, return the F2 value for the training data.
  • valid (bool) – If True, return the F2 value for the validation data.
  • xval (bool) – If True, return the F2 value for each of the cross-validated splits.
Returns:

The F2 values for the specified key(s).

accuracy(thresholds=None, train=False, valid=False, xval=False)[source]

Get the accuracy for a set of thresholds.

If all are False (default), then return the training metric value. If more than one options is set to True, then return a dictionary of metrics where the keys are “train”, “valid”, and “xval”.

Parameters:
  • thresholds – If None, then the thresholds in this set of metrics will be used.
  • train (bool) – If True, return the accuracy value for the training data.
  • valid (bool) – If True, return the accuracy value for the validation data.
  • xval (bool) – If True, return the accuracy value for each of the cross-validated splits.
Returns:

The accuracy values for the specified key(s).

confusion_matrix(metrics=None, thresholds=None, train=False, valid=False, xval=False)[source]

Get the confusion matrix for the specified metrics/thresholds.

If all are False (default), then return the training metric value. If more than one options is set to True, then return a dictionary of metrics where the keys are “train”, “valid”, and “xval”

Parameters:
  • metrics – One or more of "min_per_class_accuracy", "absolute_mcc", "tnr", "fnr", "fpr", "tpr", "precision", "accuracy", "f0point5", "f2", "f1".
  • thresholds – If None, then the thresholds in this set of metrics will be used.
  • train (bool) – If True, return the confusion matrix value for the training data.
  • valid (bool) – If True, return the confusion matrix value for the validation data.
  • xval (bool) – If True, return the confusion matrix value for each of the cross-validated splits.
Returns:

The confusion matrix values for the specified key(s).

error(thresholds=None, train=False, valid=False, xval=False)[source]

Get the error for a set of thresholds.

If all are False (default), then return the training metric value. If more than one options is set to True, then return a dictionary of metrics where the keys are “train”, “valid”, and “xval”.

Parameters:
  • thresholds – If None, then the thresholds in this set of metrics will be used.
  • train (bool) – If True, return the error value for the training data.
  • valid (bool) – If True, return the error value for the validation data.
  • xval (bool) – If True, return the error value for each of the cross-validated splits.
Returns:

The error values for the specified key(s).

fallout(thresholds=None, train=False, valid=False, xval=False)[source]

Get the fallout for a set of thresholds (aka False Positive Rate).

If all are False (default), then return the training metric value. If more than one options is set to True, then return a dictionary of metrics where the keys are “train”, “valid”, and “xval”.

Parameters:
  • thresholds – If None, then the thresholds in this set of metrics will be used.
  • train (bool) – If True, return the fallout value for the training data.
  • valid (bool) – If True, return the fallout value for the validation data.
  • xval (bool) – If True, return the fallout value for each of the cross-validated splits.
Returns:

The fallout values for the specified key(s).

find_idx_by_threshold(threshold, train=False, valid=False, xval=False)[source]

Retrieve the index in this metric’s threshold list at which the given threshold is located.

If all are False (default), then return the training metric value. If more than one options is set to True, then return a dictionary of metrics where the keys are “train”, “valid”, and “xval”.

Parameters:
  • threshold (float) – Threshold value to search for in the threshold list.
  • train (bool) – If True, return the find idx by threshold value for the training data.
  • valid (bool) – If True, return the find idx by threshold value for the validation data.
  • xval (bool) – If True, return the find idx by threshold value for each of the cross-validated splits.
Returns:

The find idx by threshold values for the specified key(s).

find_threshold_by_max_metric(metric, train=False, valid=False, xval=False)[source]

If all are False (default), then return the training metric value.

If more than one options is set to True, then return a dictionary of metrics where the keys are “train”, “valid”, and “xval”.

Parameters:
  • metric (str) – The metric to search for.
  • train (bool) – If True, return the find threshold by max metric value for the training data.
  • valid (bool) – If True, return the find threshold by max metric value for the validation data.
  • xval (bool) – If True, return the find threshold by max metric value for each of the cross-validated splits.
Returns:

The find threshold by max metric values for the specified key(s).

fnr(thresholds=None, train=False, valid=False, xval=False)[source]

Get the False Negative Rates for a set of thresholds.

If all are False (default), then return the training metric value. If more than one options is set to True, then return a dictionary of metrics where the keys are “train”, “valid”, and “xval”.

Parameters:
  • thresholds – If None, then the thresholds in this set of metrics will be used.
  • train (bool) – If True, return the FNR value for the training data.
  • valid (bool) – If True, return the FNR value for the validation data.
  • xval (bool) – If True, return the FNR value for each of the cross-validated splits.
Returns:

The FNR values for the specified key(s).

fpr(thresholds=None, train=False, valid=False, xval=False)[source]

Get the False Positive Rates for a set of thresholds.

If all are False (default), then return the training metric value. If more than one options is set to True, then return a dictionary of metrics where the keys are “train”, “valid”, and “xval”.

Parameters:
  • thresholds – If None, then the thresholds in this set of metrics will be used.
  • train (bool) – If True, return the FPR value for the training data.
  • valid (bool) – If True, return the FPR value for the validation data.
  • xval (bool) – If True, return the FPR value for each of the cross-validated splits.
Returns:

The FPR values for the specified key(s).

gains_lift(train=False, valid=False, xval=False)[source]

Get the Gains/Lift table for the specified metrics.

If all are False (default), then return the training metric Gains/Lift table. If more than one options is set to True, then return a dictionary of metrics where t he keys are “train”, “valid”, and “xval”.

Parameters:
  • train (bool) – If True, return the gains lift value for the training data.
  • valid (bool) – If True, return the gains lift value for the validation data.
  • xval (bool) – If True, return the gains lift value for each of the cross-validated splits.
Returns:

The gains lift values for the specified key(s).

max_per_class_error(thresholds=None, train=False, valid=False, xval=False)[source]

Get the max per class error for a set of thresholds.

If all are False (default), then return the training metric value. If more than one options is set to True, then return a dictionary of metrics where the keys are “train”, “valid”, and “xval”.

Parameters:
  • thresholds – If None, then the thresholds in this set of metrics will be used.
  • train (bool) – If True, return the max per class error value for the training data.
  • valid (bool) – If True, return the max per class error value for the validation data.
  • xval (bool) – If True, return the max per class error value for each of the cross-validated splits.
Returns:

The max per class error values for the specified key(s).

mcc(thresholds=None, train=False, valid=False, xval=False)[source]

Get the MCC for a set of thresholds.

If all are False (default), then return the training metric value. If more than one options is set to True, then return a dictionary of metrics where the keys are “train”, “valid”, and “xval”.

Parameters:
  • thresholds – If None, then the thresholds in this set of metrics will be used.
  • train (bool) – If True, return the MCC value for the training data.
  • valid (bool) – If True, return the MCC value for the validation data.
  • xval (bool) – If True, return the MCC value for each of the cross-validated splits.
Returns:

The MCC values for the specified key(s).

mean_per_class_error(thresholds=None, train=False, valid=False, xval=False)[source]

Get the mean per class error for a set of thresholds.

If all are False (default), then return the training metric value. If more than one options is set to True, then return a dictionary of metrics where the keys are “train”, “valid”, and “xval”.

Parameters:
  • thresholds – If None, then the thresholds in this set of metrics will be used.
  • train (bool) – If True, return the mean per class error value for the training data.
  • valid (bool) – If True, return the mean per class error value for the validation data.
  • xval (bool) – If True, return the mean per class error value for each of the cross-validated splits.
Returns:

The mean per class error values for the specified key(s).

metric(metric, thresholds=None, train=False, valid=False, xval=False)[source]

Get the metric value for a set of thresholds.

If all are False (default), then return the training metric value. If more than one options is set to True, then return a dictionary of metrics where the keys are “train”, “valid”, and “xval”.

Parameters:
  • metric (str) – name of the metric to retrieve.
  • thresholds – If None, then the thresholds in this set of metrics will be used.
  • train (bool) – If True, return the metric value for the training data.
  • valid (bool) – If True, return the metric value for the validation data.
  • xval (bool) – If True, return the metric value for each of the cross-validated splits.
Returns:

The metric values for the specified key(s).

missrate(thresholds=None, train=False, valid=False, xval=False)[source]

Get the miss rate for a set of thresholds (aka False Negative Rate).

If all are False (default), then return the training metric value. If more than one options is set to True, then return a dictionary of metrics where the keys are “train”, “valid”, and “xval”.

Parameters:
  • thresholds – If None, then the thresholds in this set of metrics will be used.
  • train (bool) – If True, return the miss rate value for the training data.
  • valid (bool) – If True, return the miss rate value for the validation data.
  • xval (bool) – If True, return the miss rate value for each of the cross-validated splits.
Returns:

The miss rate values for the specified key(s).

plot(timestep=u'AUTO', metric=u'AUTO', server=False, **kwargs)[source]

Plot training set (and validation set if available) scoring history for an H2OBinomialModel.

The timestep and metric arguments are restricted to what is available in its scoring history.

Parameters:
  • timestep (str) – A unit of measurement for the x-axis.
  • metric (str) – A unit of measurement for the y-axis.
  • server (bool) – if True, then generate the image inline (using matplotlib’s “Agg” backend)
precision(thresholds=None, train=False, valid=False, xval=False)[source]

Get the precision for a set of thresholds.

If all are False (default), then return the training metric value. If more than one options is set to True, then return a dictionary of metrics where the keys are “train”, “valid”, and “xval”.

Parameters:
  • thresholds – If None, then the thresholds in this set of metrics will be used.
  • train (bool) – If True, return the precision value for the training data.
  • valid (bool) – If True, return the precision value for the validation data.
  • xval (bool) – If True, return the precision value for each of the cross-validated splits.
Returns:

The precision values for the specified key(s).

recall(thresholds=None, train=False, valid=False, xval=False)[source]

Get the recall for a set of thresholds (aka True Positive Rate).

If all are False (default), then return the training metric value. If more than one options is set to True, then return a dictionary of metrics where the keys are “train”, “valid”, and “xval”.

Parameters:
  • thresholds – If None, then the thresholds in this set of metrics will be used.
  • train (bool) – If True, return the recall value for the training data.
  • valid (bool) – If True, return the recall value for the validation data.
  • xval (bool) – If True, return the recall value for each of the cross-validated splits.
Returns:

The recall values for the specified key(s).

roc(train=False, valid=False, xval=False)[source]

Return the coordinates of the ROC curve for a given set of data.

The coordinates are two-tuples containing the false positive rates as a list and true positive rates as a list. If all are False (default), then return is the training data. If more than one ROC curve is requested, the data is returned as a dictionary of two-tuples.

Parameters:
  • train (bool) – If True, return the ROC value for the training data.
  • valid (bool) – If True, return the ROC value for the validation data.
  • xval (bool) – If True, return the ROC value for each of the cross-validated splits.
Returns:

The ROC values for the specified key(s).

sensitivity(thresholds=None, train=False, valid=False, xval=False)[source]

Get the sensitivity for a set of thresholds (aka True Positive Rate or Recall).

If all are False (default), then return the training metric value. If more than one options is set to True, then return a dictionary of metrics where the keys are “train”, “valid”, and “xval”.

Parameters:
  • thresholds – If None, then the thresholds in this set of metrics will be used.
  • train (bool) – If True, return the sensitivity value for the training data.
  • valid (bool) – If True, return the sensitivity value for the validation data.
  • xval (bool) – If True, return the sensitivity value for each of the cross-validated splits.
Returns:

The sensitivity values for the specified key(s).

specificity(thresholds=None, train=False, valid=False, xval=False)[source]

Get the specificity for a set of thresholds (aka True Negative Rate).

If all are False (default), then return the training metric value. If more than one options is set to True, then return a dictionary of metrics where the keys are “train”, “valid”, and “xval”.

Parameters:
  • thresholds – If None, then the thresholds in this set of metrics will be used.
  • train (bool) – If True, return the specificity value for the training data.
  • valid (bool) – If True, return the specificity value for the validation data.
  • xval (bool) – If True, return the specificity value for each of the cross-validated splits.
Returns:

The specificity values for the specified key(s).

tnr(thresholds=None, train=False, valid=False, xval=False)[source]

Get the True Negative Rate for a set of thresholds.

If all are False (default), then return the training metric value. If more than one options is set to True, then return a dictionary of metrics where the keys are “train”, “valid”, and “xval”.

Parameters:
  • thresholds – If None, then the thresholds in this set of metrics will be used.
  • train (bool) – If True, return the TNR value for the training data.
  • valid (bool) – If True, return the TNR value for the validation data.
  • xval (bool) – If True, return the TNR value for each of the cross-validated splits.
Returns:

The TNR values for the specified key(s).

tpr(thresholds=None, train=False, valid=False, xval=False)[source]

Get the True Positive Rate for a set of thresholds.

If all are False (default), then return the training metric value. If more than one options is set to True, then return a dictionary of metrics where the keys are “train”, “valid”, and “xval”.

Parameters:
  • thresholds – If None, then the thresholds in this set of metrics will be used.
  • train (bool) – If True, return the TPR value for the training data.
  • valid (bool) – If True, return the TPR value for the validation data.
  • xval (bool) – If True, return the TPR value for each of the cross-validated splits.
Returns:

The TPR values for the specified key(s).

Multinomial Classification

class h2o.model.multinomial.H2OMultinomialModel[source]

Bases: h2o.model.model_base.ModelBase

confusion_matrix(data)[source]

Returns a confusion matrix based of H2O’s default prediction threshold for a dataset.

Parameters:data (H2OFrame) – the frame with the prediction results for which the confusion matrix should be extracted.
hit_ratio_table(train=False, valid=False, xval=False)[source]

Retrieve the Hit Ratios.

If all are False (default), then return the training metric value. If more than one options is set to True, then return a dictionary of metrics where the keys are “train”, “valid”, and “xval”.

Parameters:
  • train – If train is True, then return the hit ratio value for the training data.
  • valid – If valid is True, then return the hit ratio value for the validation data.
  • xval – If xval is True, then return the hit ratio value for the cross validation data.
Returns:

The hit ratio for this regression model.

mean_per_class_error(train=False, valid=False, xval=False)[source]

Retrieve the mean per class error across all classes

If all are False (default), then return the training metric value. If more than one options is set to True, then return a dictionary of metrics where the keys are “train”, “valid”, and “xval”.

Parameters:
  • train (bool) – If True, return the mean_per_class_error value for the training data.
  • valid (bool) – If True, return the mean_per_class_error value for the validation data.
  • xval (bool) – If True, return the mean_per_class_error value for each of the cross-validated splits.
Returns:

The mean_per_class_error values for the specified key(s).

plot(timestep=u'AUTO', metric=u'AUTO', **kwargs)[source]

Plots training set (and validation set if available) scoring history for an H2OMultinomialModel. The timestep and metric arguments are restricted to what is available in its scoring history.

Parameters:
  • timestep – A unit of measurement for the x-axis.
  • metric – A unit of measurement for the y-axis.
Returns:

A scoring history plot.

Regression

class h2o.model.regression.H2ORegressionModel[source]

Bases: h2o.model.model_base.ModelBase

plot(timestep=u'AUTO', metric=u'AUTO', **kwargs)[source]

Plots training set (and validation set if available) scoring history for an H2ORegressionModel. The timestep and metric arguments are restricted to what is available in its scoring history.

Parameters:
  • timestep – A unit of measurement for the x-axis.
  • metric – A unit of measurement for the y-axis.
Returns:

A scoring history plot.

h2o.model.regression.h2o_explained_variance_score(y_actual, y_predicted, weights=None)[source]

Explained variance regression score function.

Parameters:
  • y_actual – H2OFrame of actual response.
  • y_predicted – H2OFrame of predicted response.
  • weights – (Optional) sample weights
Returns:

the explained variance score.

h2o.model.regression.h2o_mean_absolute_error(y_actual, y_predicted, weights=None)[source]

Mean absolute error regression loss.

Parameters:
  • y_actual – H2OFrame of actual response.
  • y_predicted – H2OFrame of predicted response.
  • weights – (Optional) sample weights
Returns:

mean absolute error loss (best is 0.0).

h2o.model.regression.h2o_mean_squared_error(y_actual, y_predicted, weights=None)[source]

Mean squared error regression loss

Parameters:
  • y_actual – H2OFrame of actual response.
  • y_predicted – H2OFrame of predicted response.
  • weights – (Optional) sample weights
Returns:

mean squared error loss (best is 0.0).

h2o.model.regression.h2o_median_absolute_error(y_actual, y_predicted)[source]

Median absolute error regression loss

Parameters:
  • y_actual – H2OFrame of actual response.
  • y_predicted – H2OFrame of predicted response.
Returns:

median absolute error loss (best is 0.0)

h2o.model.regression.h2o_r2_score(y_actual, y_predicted, weights=1.0)[source]

R-squared (coefficient of determination) regression score function

Parameters:
  • y_actual – H2OFrame of actual response.
  • y_predicted – H2OFrame of predicted response.
  • weights – (Optional) sample weights
Returns:

R-squared (best is 1.0, lower is worse).

Clustering Methods

class h2o.model.clustering.H2OClusteringModel[source]

Bases: h2o.model.model_base.ModelBase

betweenss(train=False, valid=False, xval=False)[source]

Get the between cluster sum of squares.

If all are False (default), then return the training metric value. If more than one options is set to True, then return a dictionary of metrics where the keys are “train”, “valid”, and “xval”.

Parameters:
  • train (bool) – If True, return the between cluster sum of squares value for the training data.
  • valid (bool) – If True, return the between cluster sum of squares value for the validation data.
  • xval (bool) – If True, return the between cluster sum of squares value for each of the cross-validated splits.
Returns:

The between cluster sum of squares values for the specified key(s).

centers()[source]

The centers for the KMeans model.

centers_std()[source]

The standardized centers for the kmeans model.

centroid_stats(train=False, valid=False, xval=False)[source]

Get the centroid statistics for each cluster.

If all are False (default), then return the training metric value. If more than one options is set to True, then return a dictionary of metrics where the keys are “train”, “valid”, and “xval”.

Parameters:
  • train (bool) – If True, return the centroid statistic for the training data.
  • valid (bool) – If True, return the centroid statistic for the validation data.
  • xval (bool) – If True, return the centroid statistic for each of the cross-validated splits.
Returns:

The centroid statistics for the specified key(s).

num_iterations()[source]

Get the number of iterations it took to converge or reach max iterations.

size(train=False, valid=False, xval=False)[source]

Get the sizes of each cluster.

If all are False (default), then return the training metric value. If more than one options is set to True, then return a dictionary of metrics where the keys are “train”, “valid”, and “xval”.

Parameters:
  • train (bool) – If True, return the cluster sizes for the training data.
  • valid (bool) – If True, return the cluster sizes for the validation data.
  • xval (bool) – If True, return the cluster sizes for each of the cross-validated splits.
Returns:

The cluster sizes for the specified key(s).

tot_withinss(train=False, valid=False, xval=False)[source]

Get the total within cluster sum of squares.

If all are False (default), then return the training metric value. If more than one options is set to True, then return a dictionary of metrics where the keys are “train”, “valid”, and “xval”.

Parameters:
  • train (bool) – If True, return the total within cluster sum of squares value for the training data.
  • valid (bool) – If True, return the total within cluster sum of squares value for the validation data.
  • xval (bool) – If True, return the total within cluster sum of squares value for each of the cross-validated splits.
Returns:

The total within cluster sum of squares values for the specified key(s).

totss(train=False, valid=False, xval=False)[source]

Get the total sum of squares.

If all are False (default), then return the training metric value. If more than one options is set to True, then return a dictionary of metrics where the keys are “train”, “valid”, and “xval”.

Parameters:
  • train (bool) – If True, return the total sum of squares value for the training data.
  • valid (bool) – If True, return the total sum of squares value for the validation data.
  • xval (bool) – If True, return the total sum of squares value for each of the cross-validated splits.
Returns:

The total sum of squares values for the specified key(s).

withinss(train=False, valid=False, xval=False)[source]

Get the within cluster sum of squares for each cluster.

If all are False (default), then return the training metric value. If more than one options is set to True, then return a dictionary of metrics where the keys are “train”, “valid”, and “xval”.

Parameters:
  • train (bool) – If True, return the total sum of squares value for the training data.
  • valid (bool) – If True, return the total sum of squares value for the validation data.
  • xval (bool) – If True, return the total sum of squares value for each of the cross-validated splits.
Returns:

The total sum of squares values for the specified key(s).

AutoEncoders

class h2o.model.autoencoder.H2OAutoEncoderModel[source]

Bases: h2o.model.model_base.ModelBase

anomaly(test_data, per_feature=False)[source]

Obtain the reconstruction error for the input test_data.

Parameters:
  • test_data (H2OFrame) – The dataset upon which the reconstruction error is computed.
  • per_feature (bool) – Whether to return the square reconstruction error per feature. Otherwise, return the mean square error.
Returns:

the reconstruction error.