h2o4gpu.solvers package

h2o4gpu.solvers.elastic_net module

copyright:2017-2018 H2O.ai, Inc.
license:Apache License Version 2.0 (see LICENSE for details)
class h2o4gpu.solvers.elastic_net.ElasticNet(alpha=1.0, l1_ratio=0.5, fit_intercept=True, normalize=False, precompute=False, max_iter=5000, copy_X=True, tol=0.01, warm_start=False, positive=False, random_state=None, selection='cyclic', n_gpus=-1, lambda_stop_early=True, glm_stop_early=True, glm_stop_early_error_fraction=1.0, verbose=False, n_threads=None, gpu_id=0, lambda_min_ratio=1e-07, n_lambdas=100, n_folds=5, n_alphas=5, tol_seek_factor=0.1, family='elasticnet', store_full_path=0, lambda_max=None, alpha_max=1.0, alpha_min=0.0, alphas=None, lambdas=None, double_precision=None, order=None, backend='auto')[source]

Bases: object

H2O ElasticNet Solver

Selects between h2o4gpu.solvers.elastic_net.ElasticNet_h2o4gpu and h2o4gpu.linear_model.coordinate_descent.ElasticNet_sklearn

Parameters:
alpha : float, optional

Constant that multiplies the penalty terms. Defaults to 1.0. See the notes for the exact mathematical meaning of this parameter.``alpha = 0`` is equivalent to an ordinary least square, solved by the LinearRegressionSklearn object. For numerical reasons, using alpha = 0 with the LassoSklearn object is not advised. Given this, you should use the LinearRegressionSklearn object.

l1_ratio : float

The ElasticNetSklearn mixing parameter, with 0 <= l1_ratio <= 1. For l1_ratio = 0 the penalty is an L2 penalty. For l1_ratio = 1 it is an L1 penalty. For 0 < l1_ratio < 1, the penalty is a combination of L1 and L2.

fit_intercept : bool

Whether the intercept should be estimated or not. If False, the data is assumed to be already centered.

normalize : boolean, optional, default False

This parameter is ignored when fit_intercept is set to False. If True, the regressors X will be normalized before regression by subtracting the mean and dividing by the l2-norm. If you wish to standardize, please use h2o4gpu.preprocessing.StandardScaler before calling fit on an estimator with normalize=False.

precompute : True | False | array-like

Whether to use a precomputed Gram matrix to speed up calculations. The Gram matrix can also be passed as argument. For sparse input this option is always True to preserve sparsity.

max_iter : int, optional

The maximum number of iterations

copy_X : boolean, optional, default True

If True, X will be copied; else, it may be overwritten.

tol : float, optional

The tolerance for the optimization: if the updates are smaller than tol, the optimization code checks the dual gap for optimality and continues until it is smaller than tol.

warm_start : bool, optional

When set to True, reuse the solution of the previous call to fit as initialization, otherwise, just erase the previous solution.

positive : bool, optional

When set to True, forces the coefficients to be positive.

random_state : int, RandomState instance or None, optional, default None

The seed of the pseudo random number generator that selects a random feature to update. If int, random_state is the seed used by the random number generator; If RandomState instance, random_state is the random number generator; If None, the random number generator is the RandomState instance used by np.random. Used when selection == ‘random’.

selection : str, default ‘cyclic’

If set to ‘random’, a random coefficient is updated every iteration rather than looping over features sequentially by default. This (setting to ‘random’) often leads to significantly faster convergence especially when tol is higher than 1e-4.

n_gpus : int, (Default=-1)

Number of gpu’s to use in GLM solver.

lambda_stop_early : float, (Default=True)

Stop early when there is no more relative improvement on train or validation.

glm_stop_early : bool, (Default=True)

Stop early when there is no more relative improvement in the primary and dual residuals for ADMM.

glm_stop_early_error_fraction : float, (Default=1.0)

Relative tolerance for metric-based stopping criterion (stop if relative improvement is not at least this much).

verbose : int, (Default=0)

Print verbose information to the console if set to > 0.

n_threads : int, (Default=None)

Number of threads to use in the gpu. Each thread is an independent model builder.

gpu_id : int, optional, (default=0)

ID of the GPU on which the algorithm should run.

lambda_min_ratio: float, (Default=1E-7).

Minimum lambda ratio to maximum lambda, used in lambda search.

n_lambdas : int, (Default=100)

Number of lambdas to be used in a search.

n_folds : int, (Default=1)

Number of cross validation folds.

n_alphas : int, (Default=5)

Number of alphas to be used in a search.

tol_seek_factor : float, (Default=1E-1)

Factor of tolerance to seek once below null model accuracy. Default is 1E-1, so seeks tolerance of 1E-3 once below null model accuracy for tol=1E-2.

family : string, (Default=”elasticnet”)

“logistic” for classification with logistic regression. Defaults to “elasticnet” for regression. Must be “logistic” or “elasticnet”.

store_full_path: int, (Default=0)

Whether to store full solution for all alphas and lambdas. If 1, then during predict will compute best and full predictions.

lambda_max : int, (Default=None)

Maximum Lambda value to use. Default is None, and then internally compute standard maximum

alpha_max : float, (Default=1.0)

Maximum alpha.

alpha_min : float, (Default=0.0)

Minimum alpha.

alphas: list, tuple, array, or numpy 1D array of alphas (Default=None)

overrides n_alphas, alpha_min, and alpha_max.

lambdas: list, tuple, array, or numpy 1D array of lambdas (Default=None)

overrides n_lambdas, lambda_max, and lambda_min_ratio.

double_precision: int, (Default=None)

Internally set unless using _ptr methods. Value can either be 0 (float32) or 1(float64)

order : string, (Default=None)

Order of data. Default is None, and internally determined (unless using _ptr methods) whether row ‘r’ or column ‘c’ major order.

backend : string, (Default=”auto”)

Which backend to use. Options are ‘auto’, ‘sklearn’, ‘h2o4gpu’. Saves as attribute for actual backend used.

fit(X, y=None, check_input=True)[source]
get_params()[source]
predict(X)[source]
predict_proba(X)[source]
score(X, y, sample_weight=None)[source]
set_attributes()[source]

Set attributes and don’t fail if not yet present

set_params(**params)[source]
class h2o4gpu.solvers.elastic_net.ElasticNetH2O(n_threads=None, gpu_id=0, n_gpus=-1, fit_intercept=True, lambda_min_ratio=1e-07, n_lambdas=100, n_folds=5, n_alphas=5, tol=0.01, tol_seek_factor=0.1, lambda_stop_early=True, glm_stop_early=True, glm_stop_early_error_fraction=1.0, max_iter=5000, verbose=0, family='elasticnet', store_full_path=0, lambda_max=None, alpha_max=1.0, alpha_min=0.0, alphas=None, lambdas=None, double_precision=None, order=None)[source]

Bases: object

H2O Elastic Net Solver for GPUs

Parameters:
n_threads : int, (Default=None)

Number of threads to use in the gpu. Each thread is an independent model builder.

gpu_id : int, optional, (default=0)

ID of the GPU on which the algorithm should run.

n_gpus : int, (Default=-1)

Number of gpu’s to use in GLM solver.

order : string, (Default=’r’)

Row or Column major for C/C++ backend. Default is ‘r’. Must be ‘r’ (Row major) or ‘c’ (Column major).

fit_intercept : bool, (default=True)

Include constant term in the model.

lambda_min_ratio: float, (Default=1E-7).

Minimum lambda ratio to maximum lambda, used in lambda search.

n_lambdas : int, (Default=100)

Number of lambdas to be used in a search.

n_folds : int, (Default=1)

Number of cross validation folds.

n_alphas : int, (Default=5)

Number of alphas to be used in a search.

tol : float, (Default=1E-2)

Relative tolerance.

tol_seek_factor : float, (Default=1E-1)

Factor of tolerance to seek once below null model accuracy. Default is 1E-1, so seeks tolerance of 1E-3 once below null model accuracy for tol=1E-2.

lambda_stop_early : float, (Default=True)

Stop early when there is no more relative improvement on train or validation.

glm_stop_early : bool, (Default=True)

Stop early when there is no more relative improvement in the primary and dual residuals for ADMM.

glm_stop_early_error_fraction : float, (Default=1.0)

Relative tolerance for metric-based stopping criterion (stop if relative improvement is not at least this much).

max_iter : int, (Default=5000)

Maximum number of iterations.

verbose : int, (Default=0)

Print verbose information to the console if set to > 0.

family : string, (Default=”elasticnet”)

“logistic” for classification with logistic regression. Defaults to “elasticnet” for regression. Must be “logistic” or “elasticnet”.

store_full_path: int, (Default=0)

Whether to store full solution for all alphas and lambdas. If 1, then during predict will compute best and full predictions.

lambda_max : int, (Default=None)

Maximum Lambda value to use. Default is None, and then internally compute standard maximum

alpha_max : float, (Default=1.0)

Maximum alpha.

alpha_min : float, (Default=0.0)

Minimum alpha.

alphas: list, tuple, array, or numpy 1D array of alphas (Default=None)

overrides n_alphas, alpha_min, and alpha_max.

lambdas: list, tuple, array, or numpy 1D array of lambdas (Default=None)

overrides n_lambdas, lambda_max, and lambda_min_ratio.

double_precision: int, (Default=None)

Internally set unless using _ptr methods. Value can either be 0 (float32) or 1(float64)

order : string, (Default=None)

Order of data. Default is None, and internally determined (unless using _ptr methods) whether row ‘r’ or column ‘c’ major order.

X
X_best
X_full

Returns full solution if store_full_path=1 X[which lambda][which alpha]

alphas
alphas_best
alphas_full

Returns full alpha if store_full_path=1 alpha[which lambda][which alpha]

coef_
error
error_best
error_full
family
fit(train_x=None, train_y=None, valid_x=None, valid_y=None, sample_weight=None, free_input_data=1)[source]

Train a GLM

:param ndarray train_x : Training features array

:param ndarray train_y : Training response array

:param ndarray valid_x : Validation features

:param ndarray valid_y : Validation response

:param ndarray weight : Observation weights

:param int free_input_data : Indicate if input data should be freed
at the end of fit(). Default is 1.
fit_predict(train_x, train_y, valid_x=None, valid_y=None, sample_weight=None, free_input_data=1, order=None)[source]

Train a model using GLM and predict on validation set

:param ndarray train_x : Training features array

:param ndarray train_y : Training response array

:param ndarray valid_x : Validation features

:param ndarray valid_y : Validation response

:param ndarray weight : Observation weights

:param int free_input_data : Indicate if input data should be freed at
the end of fit(). Default is 1.
Parameters:order – Order of data. Default is None, and internally determined whether row ‘r’ or column ‘c’ major order.
fit_predict_ptr(m_train, n, m_valid, double_precision, order, a, b, c, d, e, free_input_data=0, source_dev=0)[source]

Train a GLM with pointers to data on the GPU and predict on validation set that also has a pointer on the GPU

:param m_train Number of rows in the training set

:param n Number of columns in the training set

:param m_valid Number of rows in the validation set

:param double_precision float32 (0) or double precision (1) of fit.
Default None.
Parameters:order – Order of data. Default is None, and internally determined whether row ‘r’ or column ‘c’ major order.

:param a Pointer to training features array

:param b Pointer to training response array

:param c Pointer to validation features

:param d Pointer to validation response

:param e Pointer to weight column

:param int free_input_data : Indicate if input data should be freed
at the end of fit(). Default is 1.

:param source_dev GPU ID of device

fit_ptr(m_train, n, m_valid, double_precision, order, a, b, c, d, e, free_input_data=0, source_dev=0)[source]
Train a GLM with pointers to data on the GPU
(if fit_intercept, then you should have added 1’s as last column to m_train)

:param m_train Number of rows in the training set

:param n Number of columns in the training set

:param m_valid Number of rows in the validation set

:param double_precision float32 (0) or double point precision (1) of fit
No Default.
Parameters:order – Order of data. Default is None, and assumed set by constructor or upload_data whether row ‘r’ or column ‘c’ major order.

:param a Pointer to training features array

:param b Pointer to training response array

:param c Pointer to validation features

:param d Pointer to validation response

:param e Pointer to weight column

:param int free_input_data : Indicate if input data should be freed at
the end of fit(). Default is 1.

:param source_dev GPU ID of device

fit_transform(train_x, train_y, valid_x=None, valid_y=None, sample_weight=None, free_input_data=1)[source]

Train a model using GLM and predict on validation set

:param ndarray train_x : Training features array

:param ndarray train_y : Training response array

:param ndarray valid_x : Validation features

:param ndarray valid_y : Validation response

:param ndarray weight : Observation weights

:param int free_input_data : Indicate if input data should be freed at
the end of fit(). Default is 1.
get_params(deep=True)[source]

Get parameters for this estimator.

:param bool deep : If True, will return the parameters for this
estimator and contained subobjects that are estimators.

:returns dict params : Parameter names mapped to their values.

gpu_id
class info[source]

Bases: object

intercept_
intercept_best
intercept_full

Returns full intercept if store_full_path=1 intercept[which lambda][which alpha]

lambdas
lambdas_best
lambdas_full

Returns full lambda path if store_full_path=1 lambda[which lambda][which alpha]

predict(valid_x=None, valid_y=None, sample_weight=None, free_input_data=1)[source]

Predict on a fitted GLM and get back class predictions for binomial models for classification and predicted values for regression.

:param ndarray valid_x : Validation features

:param ndarray valid_y : Validation response

:param ndarray weight : Observation weights

:param int free_input_data : Indicate if input data should be freed at
the end of fit(). Default is 1.
predict_proba(valid_x=None, valid_y=None, sample_weight=None, free_input_data=1)[source]

Predict on a fitted GLM and get back uncalibrated probabilities for classification models

:param ndarray valid_x : Validation features

:param ndarray valid_y : Validation response

:param ndarray weight : Observation weights

:param int free_input_data : Indicate if input data should be freed at
the end of fit(). Default is 1.
predict_ptr(valid_xptr=None, valid_yptr=None, free_input_data=0, order=None)[source]

Predict on a fitted GLM with with pointers to data on the GPU

:param ndarray valid_xptr : Pointer to validation features

:param ndarray valid_yptr : Pointer to validation response

:param int store_full_path : Store full regularization path
from glm model
:param int free_input_data : Indicate if input data should be freed
at the end of fit(). Default is 1.
:param int verbose : Print verbose information to the console
if set to > 0. Default is 0.
Parameters:order – Order of data. Default is None, and internally determined whether row ‘r’ or column ‘c’ major order.
set_params(**params)[source]

Set the parameters of this estimator.

shared_a
class solution[source]

Bases: object

standardize
summary()[source]

Obtain model summary, which is error per alpha across train, cv, and validation

Error is logloss for classification and RMSE (Root Mean Squared Error) for regression.

tols
tols_best
tols_full

Returns full tols if store_full_path=1 tols[which lambda][which alpha]

total_n_gpus
transform()[source]
validPreds
validPreds_best
validPreds_full

Returns full predictions if store_full_path=1 validPreds[which lambda][which alpha]

h2o4gpu.solvers.logistic module

copyright:2017-2018 H2O.ai, Inc.
license:Apache License Version 2.0 (see LICENSE for details)
class h2o4gpu.solvers.logistic.LogisticRegression(penalty='l2', dual=False, tol=0.01, C=1.0, fit_intercept=True, intercept_scaling=1.0, class_weight=None, random_state=None, solver='liblinear', max_iter=5000, multi_class='ovr', verbose=0, warm_start=False, n_jobs=1, n_gpus=-1, glm_stop_early=True, glm_stop_early_error_fraction=1.0, backend='auto')[source]

Bases: object

H2O Logistic Regression Solver

Parameters:
penalty : str, ‘l1’ or ‘l2’, default: ‘l2’

Used to specify the norm used in the penalization. The ‘newton-cg’, ‘sag’ and ‘lbfgs’ solvers support only l2 penalties.

New in version 0.19: l1 penalty with SAGA solver (allowing ‘multinomial’ + L1)

dual : bool, default: False

Dual or primal formulation. Dual formulation is only implemented for l2 penalty with liblinear solver. Prefer dual=False when n_samples > n_features.

tol : float, default: 1e-4

Tolerance for stopping criteria.

C : float, default: 1.0

Inverse of regularization strength; must be a positive float. Like in support vector machines, smaller values specify stronger regularization.

fit_intercept : bool, default: True

Specifies if a constant (a.k.a. bias or intercept) should be added to the decision function.

intercept_scaling : float, default 1.

Useful only when the solver ‘liblinear’ is used and self.fit_intercept is set to True. In this case, x becomes [x, self.intercept_scaling], i.e. a “synthetic” feature with constant value equal to intercept_scaling is appended to the instance vector. The intercept becomes intercept_scaling * synthetic_feature_weight.

Note! the synthetic feature weight is subject to l1/l2 regularization as all other features. To lessen the effect of regularization on synthetic feature weight (and therefore on the intercept) intercept_scaling has to be increased.

class_weight : dict or ‘balanced’, default: None

Weights associated with classes in the form {class_label: weight}. If not given, all classes are supposed to have weight one.

The “balanced” mode uses the values of y to automatically adjust weights inversely proportional to class frequencies in the input data as n_samples / (n_classes * np.bincount(y)).

Note that these weights will be multiplied with sample_weight (passed through the fit method) if sample_weight is specified.

New in version 0.17: class_weight=’balanced’

random_state : int, RandomState instance or None, optional, default: None

The seed of the pseudo random number generator to use when shuffling the data. If int, random_state is the seed used by the random number generator; If RandomState instance, random_state is the random number generator; If None, the random number generator is the RandomState instance used by np.random. Used when solver == ‘sag’ or ‘liblinear’.

solver : {‘newton-cg’, ‘lbfgs’, ‘liblinear’, ‘sag’, ‘saga’},

default: ‘liblinear’ Algorithm to use in the optimization problem.

  • For small datasets, ‘liblinear’ is a good choice, whereas ‘sag’ and
    ‘saga’ are faster for large ones.
  • For multiclass problems, only ‘newton-cg’, ‘sag’, ‘saga’ and ‘lbfgs’
    handle multinomial loss; ‘liblinear’ is limited to one-versus-rest schemes.
  • ‘newton-cg’, ‘lbfgs’ and ‘sag’ only handle L2 penalty, whereas
    ‘liblinear’ and ‘saga’ handle L1 penalty.

Note that ‘sag’ and ‘saga’ fast convergence is only guaranteed on features with approximately the same scale. You can preprocess the data with a scaler from h2o4gpu.preprocessing.

New in version 0.17: Stochastic Average Gradient descent solver.

New in version 0.19: SAGA solver.

max_iter : int, default: 100

Useful only for the newton-cg, sag and lbfgs solvers. Maximum number of iterations taken for the solvers to converge.

multi_class : str, {‘ovr’, ‘multinomial’}, default: ‘ovr’

Multiclass option can be either ‘ovr’ or ‘multinomial’. If the option chosen is ‘ovr’, then a binary problem is fit for each label. Else the loss minimised is the multinomial loss fit across the entire probability distribution. Does not work for liblinear solver.

New in version 0.18: Stochastic Average Gradient descent solver for ‘multinomial’ case.

verbose : int, (Default=0)

Print verbose information to the console if set to > 0.

warm_start : bool, default: False

When set to True, reuse the solution of the previous call to fit as initialization, otherwise, just erase the previous solution. Useless for liblinear solver.

New in version 0.17: warm_start to support lbfgs, newton-cg, sag, saga solvers.

n_jobs : int, default: 1

Number of CPU cores used when parallelizing over classes if multi_class=’ovr’”. This parameter is ignored when the ``solver``is set to ‘liblinear’ regardless of whether ‘multi_class’ is specified or not. If given a value of -1, all cores are used.

n_gpus : int

Number of gpu’s to use in RandomForestRegressor solver. Default is -1.

glm_stop_early : bool, (Default=True)

Stop early when there is no more relative improvement in the primary and dual residuals for ADMM.

glm_stop_early_error_fraction : float, (Default=1.0)

Relative tolerance for metric-based stopping criterion (stop if relative improvement is not at least this much).

backend : string, (Default=”auto”)

Which backend to use. Options are ‘auto’, ‘sklearn’, ‘h2o4gpu’. Saves as attribute for actual backend used.

decision_function(X)[source]
densify()[source]
fit(X, y=None, sample_weight=None)[source]
get_params()[source]
predict(X)[source]
predict_log_proba(X)[source]
predict_proba(X)[source]
score(X, y, sample_weight=None)[source]
set_attributes()[source]

set attributes for Logistic

set_params(**params)[source]
sparsify()[source]

h2o4gpu.solvers.lasso module

copyright:2017-2018 H2O.ai, Inc.
license:Apache License Version 2.0 (see LICENSE for details)
class h2o4gpu.solvers.lasso.Lasso(alpha=1.0, fit_intercept=True, normalize=False, precompute=False, copy_X=True, max_iter=5000, tol=0.01, warm_start=False, positive=False, random_state=None, selection='cyclic', n_gpus=-1, glm_stop_early=True, glm_stop_early_error_fraction=1.0, verbose=False, backend='auto')[source]

Bases: object

H2O Lasso Regression Solver

Parameters:
alpha : float, optional

Constant that multiplies the L1 term. Defaults to 1.0. alpha = 0 is equivalent to an ordinary least square, solved by the LinearRegression object. For numerical reasons, using alpha = 0 with the Lasso object is not advised. Given this, you should use the LinearRegression object.

fit_intercept : boolean

whether to calculate the intercept for this model. If set to false, no intercept will be used in calculations (e.g. data is expected to be already centered).

normalize : boolean, optional, default False

This parameter is ignored when fit_intercept is set to False. If True, the regressors X will be normalized before regression by subtracting the mean and dividing by the l2-norm. If you wish to standardize, please use sklearn.preprocessing.StandardScaler before calling fit on an estimator with normalize=False.

precompute : True | False | array-like, default=False

Whether to use a precomputed Gram matrix to speed up calculations. If set to 'auto' let us decide. The Gram matrix can also be passed as argument. For sparse input this option is always True to preserve sparsity.

copy_X : boolean, optional, default True

If True, X will be copied; else, it may be overwritten.

max_iter : int, optional

The maximum number of iterations

tol : float, optional

The tolerance for the optimization: if the updates are smaller than tol, the optimization code checks the dual gap for optimality and continues until it is smaller than tol.

warm_start : bool, optional

When set to True, reuse the solution of the previous call to fit as initialization, otherwise, just erase the previous solution.

positive : bool, optional

When set to True, forces the coefficients to be positive.

random_state : int, RandomState instance or None, optional, default None

The seed of the pseudo random number generator that selects a random feature to update. If int, random_state is the seed used by the random number generator; If RandomState instance, random_state is the random number generator; If None, the random number generator is the RandomState instance used by np.random. Used when selection == ‘random’.

selection : str, default ‘cyclic’

If set to ‘random’, a random coefficient is updated every iteration rather than looping over features sequentially by default. This (setting to ‘random’) often leads to significantly faster convergence especially when tol is higher than 1e-4.

n_gpus : int

Number of gpu’s to use in RandomForestRegressor solver. Default is -1.

glm_stop_early : bool, (Default=True)

Stop early when there is no more relative improvement in the primary and dual residuals for ADMM.

glm_stop_early_error_fraction : float, (Default=1.0)

Relative tolerance for metric-based stopping criterion (stop if relative improvement is not at least this much).

verbose : int, (Default=0)

Print verbose information to the console if set to > 0.

backend : string, (Default=”auto”)

Which backend to use. Options are ‘auto’, ‘sklearn’, ‘h2o4gpu’. Saves as attribute for actual backend used.

fit(X, y=None, check_input=True)[source]

H2O Lasso Regression Fitter

get_params()[source]
predict(X)[source]
score(X, y, sample_weight=None)[source]
set_attributes()[source]

set attributes for Lasso

set_params(**params)[source]

h2o4gpu.solvers.ridge module

copyright:2017-2018 H2O.ai, Inc.
license:Apache License Version 2.0 (see LICENSE for details)
class h2o4gpu.solvers.ridge.Ridge(alpha=1.0, fit_intercept=True, normalize=False, copy_X=True, max_iter=5000, tol=0.01, solver='auto', random_state=None, n_gpus=-1, glm_stop_early=True, glm_stop_early_error_fraction=1.0, verbose=False, backend='auto', **kwargs)[source]

Bases: object

H2O Ridge Regression Solver

Parameters:
alpha : {float, array-like}, shape (n_targets)

Regularization strength; must be a positive float. Regularization improves the conditioning of the problem and reduces the variance of the estimates. Larger values specify stronger regularization. Alpha corresponds to C^-1 in other linear models such as LogisticRegression or LinearSVC. If an array is passed, penalties are assumed to be specific to the targets. Hence they must correspond in number.

fit_intercept : boolean

Whether to calculate the intercept for this model. If set to false, no intercept will be used in calculations (e.g. data is expected to be already centered).

normalize : boolean, optional, default False

This parameter is ignored when fit_intercept is set to False. If True, the regressors X will be normalized before regression by subtracting the mean and dividing by the l2-norm. If you wish to standardize, please use sklearn.preprocessing.StandardScaler before calling fit on an estimator with normalize=False.

copy_X : boolean, optional, default True

If True, X will be copied; else, it may be overwritten.

max_iter : int, optional

Maximum number of iterations for conjugate gradient solver. For ‘sparse_cg’ and ‘lsqr’ solvers, the default value is determined by scipy.sparse.linalg. For ‘sag’ solver, the default value is 1000.

tol : float

Precision of the solution.

solver : {‘auto’, ‘svd’, ‘cholesky’, ‘lsqr’, ‘sparse_cg’, ‘sag’, ‘saga’}

Solver to use in the computational routines:

  • ‘auto’ chooses the solver automatically based on the type of data.
  • ‘svd’ uses a Singular Value Decomposition of X to compute the Ridge coefficients. More stable for singular matrices than ‘cholesky’.
  • ‘cholesky’ uses the standard scipy.linalg.solve function to obtain a closed-form solution.
  • ‘sparse_cg’ uses the conjugate gradient solver as found in scipy.sparse.linalg.cg. As an iterative algorithm, this solver is more appropriate than ‘cholesky’ for large-scale data (possibility to set tol and max_iter).
  • ‘lsqr’ uses the dedicated regularized least-squares routine scipy.sparse.linalg.lsqr. It is the fastest but may not be available in old scipy versions. It also uses an iterative procedure.
  • ‘sag’ uses a Stochastic Average Gradient descent, and ‘saga’ uses its improved, unbiased version named SAGA. Both methods also use an iterative procedure, and are often faster than other solvers when both n_samples and n_features are large. Note that ‘sag’ and ‘saga’ fast convergence is only guaranteed on features with approximately the same scale. You can preprocess the data with a scaler from sklearn.preprocessing.

All last five solvers support both dense and sparse data. However, only ‘sag’ and ‘saga’ supports sparse input when fit_intercept is True.

New in version 0.17: Stochastic Average Gradient descent solver.

New in version 0.19: SAGA solver.

random_state : int, RandomState instance or None, optional, default None

The seed of the pseudo random number generator to use when shuffling the data. If int, random_state is the seed used by the random number generator; If RandomState instance, random_state is the random number generator; If None, the random number generator is the RandomState instance used by np.random. Used when solver == ‘sag’.

New in version 0.17: random_state to support Stochastic Average Gradient.

n_gpus : int

Number of gpu’s to use in RandomForestRegressor solver. Default is -1.

glm_stop_early : bool, (Default=True)

Stop early when there is no more relative improvement in the primary and dual residuals for ADMM.

glm_stop_early_error_fraction : float, (Default=1.0)

Relative tolerance for metric-based stopping criterion (stop if relative improvement is not at least this much).

verbose : int, (Default=0)

Print verbose information to the console if set to > 0.

backend : string, (Default=”auto”)

Which backend to use. Options are ‘auto’, ‘sklearn’, ‘h2o4gpu’. Saves as attribute for actual backend used.

fit(X, y=None, sample_weight=None)[source]
get_params()[source]
predict(X)[source]
score(X, y, sample_weight=None)[source]
set_attributes()[source]

set attributes for Ridge

set_params(**params)[source]

h2o4gpu.solvers.linear_regression module

copyright:2017-2018 H2O.ai, Inc.
license:Apache License Version 2.0 (see LICENSE for details)
class h2o4gpu.solvers.linear_regression.LinearRegression(fit_intercept=True, normalize=False, copy_X=True, n_jobs=1, n_gpus=-1, tol=0.0001, glm_stop_early=True, glm_stop_early_error_fraction=1.0, verbose=False, backend='auto', **kwargs)[source]

Bases: object

H2O LinearRegression Regression Solver

Parameters:
fit_intercept : boolean, optional, default True

whether to calculate the intercept for this model. If set to False, no intercept will be used in calculations (e.g. data is expected to be already centered).

normalize : boolean, optional, default False

This parameter is ignored when fit_intercept is set to False. If True, the regressors X will be normalized before regression by subtracting the mean and dividing by the l2-norm. If you wish to standardize, please use sklearn.preprocessing.StandardScaler before calling fit on an estimator with normalize=False.

copy_X : boolean, optional, default True

If True, X will be copied; else, it may be overwritten.

n_jobs : int, optional, default 1

The number of jobs to use for the computation. If -1 all CPUs are used. This will only provide speedup for n_targets > 1 and sufficient large problems.

tol : float, (Default=1E-2)

Relative tolerance.

n_gpus : int

Number of gpu’s to use in RandomForestRegressor solver. Default is -1.

glm_stop_early : bool, (Default=True)

Stop early when there is no more relative improvement in the primary and dual residuals for ADMM.

glm_stop_early_error_fraction : float, (Default=1.0)

Relative tolerance for metric-based stopping criterion (stop if relative improvement is not at least this much).

verbose : int, (Default=0)

Print verbose information to the console if set to > 0.

backend : string, (Default=”auto”)

Which backend to use. Options are ‘auto’, ‘sklearn’, ‘h2o4gpu’. Saves as attribute for actual backend used.

fit(X, y=None, sample_weight=None)[source]
get_params()[source]
predict(X)[source]
score(X, y, sample_weight=None)[source]
set_attributes()[source]

set attributes for Linear Regression

set_params(**params)[source]

h2o4gpu.solvers.kmeans module

KMeans clustering solver.

copyright:2017-2018 H2O.ai, Inc.
license:Apache License Version 2.0 (see LICENSE for details)
class h2o4gpu.solvers.kmeans.KMeans(n_clusters=8, init='k-means++', n_init=1, max_iter=300, tol=0.0001, precompute_distances='auto', verbose=0, random_state=None, copy_x=True, n_jobs=1, algorithm='auto', gpu_id=0, n_gpus=-1, do_checks=1, backend='auto')[source]

Bases: object

K-Means clustering Wrapper

Selects between h2o4gpu.cluster.KMeansSklearn and h2o4gpu.solvers.kmeans.KMeansH2O

Parameters:
n_clusters : int, optional, default: 8

The number of clusters to form as well as the number of centroids to generate.

init : string, {‘k-means++’, ‘random’ or an ndarray}

Method for initialization, defaults to ‘random’: ‘k-means++’ : selects initial cluster centers for k-mean clustering in a smart way to speed up convergence. Not supported yet - if chosen we will use SKLearn’s methods. ‘random’: choose k observations (rows) at random from data for the initial centroids. If an ndarray is passed, it should be of shape (n_clusters, n_features) and gives the initial centers. Not supported yet - if chosen we will use SKLearn’s methods.

n_init : int, default: 1

Number of time the k-means algorithm will be run with different centroid seeds. The final results will be the best output of n_init consecutive runs in terms of inertia. Not supported yet - always runs 1.

max_iter : int, optional, default: 1000

Maximum number of iterations of the algorithm.

tol : int, optional, default: 1e-4

Relative tolerance to declare convergence.

precompute_distances : {‘auto’, True, False}

Precompute distances (faster but takes more memory). ‘auto’ : do not precompute distances if n_samples * n_clusters > 12 million. This corresponds to about 100MB overhead per job using double precision. True : always precompute distances False : never precompute distances Not supported yet - always uses auto if running h2o4gpu version.

verbose : int, optional, default 0

Logger verbosity level.

random_state : int or array_like, optional, default: None

random_state for RandomState. Must be convertible to 32 bit unsigned integers.

copy_x : boolean, default True

When pre-computing distances it is more numerically accurate to center the data first. If copy_x is True, then the original data is not modified. If False, the original data is modified, and put back before the function returns, but small numerical differences may be introduced by subtracting and then adding the data mean. Not supported yet - always uses True if running h2o4gpu version.

n_jobs : int

The number of jobs to use for the computation. This works by computing each of the n_init runs in parallel. If -1 all CPUs are used. If 1 is given, no parallel computing code is used at all, which is useful for debugging. For n_jobs below -1, (n_cpus + 1 + n_jobs) are used. Thus for n_jobs = -2, all CPUs but one are used. Not supported yet - CPU backend not yet implemented.

algorithm : string, “auto”, “full” or “elkan”, default=”auto”

K-means algorithm to use. The classical EM-style algorithm is “full”. The “elkan” variation is more efficient by using the triangle inequality, but currently doesn’t support sparse data. “auto” chooses “elkan” for dense data and “full” for sparse data. Not supported yet - always uses full if running h2o4gpu version.

gpu_id : int, optional, default: 0

ID of the GPU on which the algorithm should run.

n_gpus : int, optional, default: -1

Number of GPUs on which the algorithm should run. < 0 means all possible GPUs on the machine. 0 means no GPUs, run on CPU.

do_checks : int, optional, default: 1

If set to 0 GPU error check will not be performed.

backend : string, (Default=”auto”)

Which backend to use. Options are ‘auto’, ‘sklearn’, ‘h2o4gpu’. Saves as attribute for actual backend used.

fit(X, y=None)[source]
fit_predict(X, y=None)[source]
fit_transform(X, y=None)[source]
get_params(deep=True)[source]
predict(X)[source]
score(X, y=None)[source]
set_attributes()[source]
set_params(**params)[source]
transform(X)[source]
class h2o4gpu.solvers.kmeans.KMeansH2O(n_clusters=8, init='k-means++', n_init=1, max_iter=300, tol=0.0001, precompute_distances='auto', verbose=0, random_state=None, copy_x=True, n_jobs=1, algorithm='auto', gpu_id=0, n_gpus=-1, do_checks=1)[source]

Bases: object

K-Means clustering

Wrapper class calling an underlying (e.g. GPU or CPU)
implementation of the K-Means clustering algorithm.
Approximate GPU Memory Use:
n_clusters*rows + rows*cols + cols*n_clusters
Parameters:
n_clusters : int, optional, default: 8

The number of clusters to form as well as the number of centroids to generate.

init : string, {‘k-means++’, ‘random’ or an ndarray}

Method for initialization, defaults to ‘random’: ‘k-means++’ : selects initial cluster centers for k-mean clustering in a smart way to speed up convergence. Not supported yet - if chosen we will use SKLearn’s methods. ‘random’: choose k observations (rows) at random from data for the initial centroids. If an ndarray is passed, it should be of shape (n_clusters, n_features) and gives the initial centers. Not supported yet - if chosen we will use SKLearn’s methods.

n_init : int, default: 1

Number of time the k-means algorithm will be run with different centroid seeds. The final results will be the best output of n_init consecutive runs in terms of inertia. Not supported yet - always runs 1.

max_iter : int, optional, default: 1000

Maximum number of iterations of the algorithm.

tol : int, optional, default: 1e-4

Relative tolerance to declare convergence.

precompute_distances : {‘auto’, True, False}

Precompute distances (faster but takes more memory). ‘auto’ : do not precompute distances if n_samples * n_clusters > 12 million. This corresponds to about 100MB overhead per job using double precision. True : always precompute distances False : never precompute distances Not supported yet - always uses auto if running h2o4gpu version.

verbose : int, optional, default 0

Logger verbosity level.

random_state : int or array_like, optional, default: None

random_state for RandomState. Must be convertible to 32 bit unsigned integers.

copy_x : boolean, default True

When pre-computing distances it is more numerically accurate to center the data first. If copy_x is True, then the original data is not modified. If False, the original data is modified, and put back before the function returns, but small numerical differences may be introduced by subtracting and then adding the data mean. Not supported yet - always uses True if running h2o4gpu version.

n_jobs : int

The number of jobs to use for the computation. This works by computing each of the n_init runs in parallel. If -1 all CPUs are used. If 1 is given, no parallel computing code is used at all, which is useful for debugging. For n_jobs below -1, (n_cpus + 1 + n_jobs) are used. Thus for n_jobs = -2, all CPUs but one are used. Not supported yet - CPU backend not yet implemented.

algorithm : string, “auto”, “full” or “elkan”, default=”auto”

K-means algorithm to use. The classical EM-style algorithm is “full”. The “elkan” variation is more efficient by using the triangle inequality, but currently doesn’t support sparse data. “auto” chooses “elkan” for dense data and “full” for sparse data. Not supported yet - always uses full if running h2o4gpu version.

gpu_id : int, optional, default: 0

ID of the GPU on which the algorithm should run.

n_gpus : int, optional, default: -1

Number of GPUs on which the algorithm should run. < 0 means all possible GPUs on the machine. 0 means no GPUs, run on CPU.

do_checks : int, optional, default: 1

If set to 0 GPU error check will not be performed.

Attributes:
———-
cluster_centers_ : array, [n_clusters, n_features]

Cluster centers

labels_ : array, [n_rows,],

Labels assigned to each row during fitting.

inertia_ : float

Sum of distances of samples to their closest cluster center.

Example:
——-
>>> from h2o4gpu import KMeans
>>> import numpy as np
>>> X = np.array([[1, 2], [1, 4], [1, 0],
...               [4, 2], [4, 4], [4, 0]])
>>> kmeans = KMeans(n_clusters=2).fit(X)
>>> kmeans.labels_
>>> kmeans.predict(X)
>>> kmeans.cluster_centers_
fit(X, y=None)[source]

Compute cluster centers using KMeans algorithm.

The memory used by this algorithm depends on: - m - number of rows in X - n - number of dimensions in X - k - number of clusters - type of data in X (float32 or float64)

and should be approximately:

For float32 = 4*(m*n + k*n + 3*m + k + m*k) + 2*(4*m + k) For float64 = 8*(m*n + k*n + 3*m + k + m*k) + 2*(4*m + k)

In case of running on the GPU, a CUDA context size should be also taken into account.

Parameters:X – array-like, shape=(n_samples, n_features) Training instances.
fit_predict(X, y=None)[source]

Perform fitting and prediction on X.

Same as calling fit(X, y).labels_.

Parameters:
  • X – {array-like, sparse matrix}, shape = [n_samples, n_features] Data to be used for fitting and predictions.
  • y – array-like, optional, shape=(n_samples, 1) Initial labels for training.
Returns:

array of shape [n_samples,] A cluster index for each record

fit_transform(X, y=None)[source]

Perform fitting and transform X.

Same as calling fit(X, y).transform(X).

Parameters:
  • X – {array-like, sparse matrix}, shape = [n_samples, n_features] Data to be transformed.
  • y – array-like, optional, shape=(n_samples, 1) Initial labels for training.
Returns:

array, shape [n_samples, k] Distances to each cluster for each row.

get_params(deep=True)[source]

Get parameters for this estimator.

:param bool deep : If True, will return the parameters for this
estimator and contained subobjects that are estimators.

:returns dict params : Parameter names mapped to their values.

gpu_id
max_iter
n_clusters
predict(X)[source]

Assign the each record in X to the closest cluster.

Parameters:X – array-like or sparse matrix of shape [n_samples, n_features] Contains data points to be clustered.
Returns:array of shape [n_samples,] A cluster index for each record
set_params(**params)[source]

Set the parameters of this solver.

Returns:self
sklearn_fit(X, y=None)[source]

Instantiates a scikit-learn model using previously found, with fit(), centroids.

sklearn_predict(X, y=None)[source]

Instantiates, if necessary, a scikit-learn model using centroids found by running fit() and predicts labels using that model. This method always runs on CPU, not on GPUs.

sklearn_transform(X, y=None)[source]

Instantiates, if necessary, a scikit-learn model using centroids found by running fit() and transforms matrix X using that model. This method always runs on CPU, not on GPUs.

transform(X, y=None)[source]

Transform X to a cluster-distance space.

Each dimension is the distance to a cluster center.

Parameters:X – {array-like, sparse matrix}, shape = [n_samples, n_features] Data to be transformed.
Returns:array, shape [n_samples, k] Distances to each cluster for each row.

h2o4gpu.solvers.truncated_svd module

copyright:2017-2018 H2O.ai, Inc.
license:Apache License Version 2.0 (see LICENSE for details)
class h2o4gpu.solvers.truncated_svd.TruncatedSVD(n_components=2, algorithm='power', n_iter=100, random_state=None, tol=1e-05, verbose=False, backend='auto', n_gpus=1, gpu_id=0)[source]

Bases: object

Truncated SVD Wrapper

Selects between h2o4gpu.decomposition.TruncatedSVDSklearn and h2o4gpu.solvers.truncated_svd.TruncatedSVDH2O

Parameters:
n_components: int, Default=2

Desired dimensionality of output data

algorithm: string, Default=”power”

SVD solver to use. H2O4GPU options are either “cusolver” (similar to ARPACK) or “power” for the power method. SKlearn options are either “arpack” for the ARPACK wrapper in SciPy (scipy.sparse.linalg.svds), or “randomized” for the randomized algorithm due to Halko (2009).

n_iter: int, Default=100

number of iterations (only relevant for power method) Should be at most 2147483647 due to INT_MAX in C++ backend.

random_state: int, Default=None

seed (None for auto-generated)

tol: float, Default=1E-5

Tolerance for “power” method. Ignored by “cusolver”. Should be > 0.0 to ensure convergence. Should be 0.0 to effectively ignore and only base convergence upon n_iter

verbose: bool

Verbose or not

backend : string, (Default=”auto”)

Which backend to use. Options are ‘auto’, ‘sklearn’, ‘h2o4gpu’. Saves as attribute for actual backend used.

n_gpus : int, optional, default: 1

How many gpus to use. If 0, use CPU backup method. Currently SVD only uses 1 GPU, so >1 has no effect compared to 1.

gpu_id : int, optional, default: 0

ID of the GPU on which the algorithm should run.

fit(X, y=None)[source]
fit_transform(X, y=None)[source]
get_params(deep=True)[source]
inverse_transform(X)[source]
set_attributes()[source]
set_params(**params)[source]
transform(X)[source]
class h2o4gpu.solvers.truncated_svd.TruncatedSVDH2O(n_components=2, algorithm='power', n_iter=100, random_state=None, tol=1e-05, verbose=0, n_gpus=1, gpu_id=0)[source]

Bases: object

Dimensionality reduction using truncated SVD for GPUs

Perform linear dimensionality reduction by means of truncated singular value decomposition (SVD). Contrary to PCA, this estimator does not center the data before computing the singular value decomposition.

Parameters:
n_components: int, Default=2

Desired dimensionality of output data

algorithm: string, Default=”power”

SVD solver to use. Either “cusolver” (similar to ARPACK) or “power” for the power method.

n_iter: int, Default=100

number of iterations (only relevant for power method) Should be at most 2147483647 due to INT_MAX in C++ backend.

int random_state: seed (None for auto-generated)
float tol: float, Default=1E-5

Tolerance for “power” method. Ignored by “cusolver”. Should be > 0.0 to ensure convergence. Should be 0.0 to effectively ignore and only base convergence upon n_iter

verbose: bool

Verbose or not

n_gpus : int, optional, default: 1

How many gpus to use. If 0, use CPU backup method. Currently SVD only uses 1 GPU, so >1 has no effect compared to 1.

gpu_id : int, optional, default: 0

ID of the GPU on which the algorithm should run.

U

U Matrix

components_

Components

explained_variance_

The variance of the training samples transformed by a projection to each component.

explained_variance_ratio_

Percentage of variance explained by each of the selected components.

fit(X, y=None)[source]

Fit Truncated SVD on matrix X.

:param X : {array-like, sparse matrix}, shape (n_samples, n_features)
Training data.
:param y : Ignored
For ScikitLearn compatibility
:returns self : self
object
fit_transform(X, y=None)[source]

Fit Truncated SVD on matrix X and perform dimensionality reduction on X.

:param X : {array-like, sparse matrix}, shape (n_samples, n_features)
Training data.
:param y : Ignored
For ScikitLearn compatibility
:returns X_new : array, shape (n_samples, n_components)
Reduced version of X. This will always be a dense array.
get_params(deep=True)[source]

Get parameters for this estimator.

:param deep : bool
If True, will return the parameters for this estimator and contained subobjects that are estimators.
:returns params : dict
Parameter names mapped to their values.
inverse_transform(X)[source]

Transform X back to its original space.

:param X : array-like, shape (n_samples, n_components)
Data to transform back to original space
:returns X_original : array, shape (n_samples, n_features)
Note that this is always a dense array.
set_params(**params)[source]

Set the parameters of this solver.

:returns self : self
Returns self
singular_values_

The singular values corresponding to each of the selected components. The singular values are equal to the 2-norms of the n_components variables in the lower-dimensional space.

transform(X)[source]

Perform dimensionality reduction on X.

:param X : {array-like, sparse matrix}, shape (n_samples, n_features)
Training data.
:returns X_new : array, shape (n_samples, n_components)
Reduced version of X. This will always be a dense array.

h2o4gpu.solvers.pca module

copyright:2017-2018 H2O.ai, Inc.
license:Apache License Version 2.0 (see LICENSE for details)
class h2o4gpu.solvers.pca.PCA(n_components=2, copy=True, whiten=False, svd_solver='arpack', tol=0.0, iterated_power='auto', random_state=None, verbose=False, backend='auto', gpu_id=0)[source]

Bases: h2o4gpu.solvers.truncated_svd.TruncatedSVD

PCA Wrapper

Selects between h2o4gpu.decomposition.PCASklearn and h2o4gpu.solvers.pca.PCAH2O

Parameters:
n_components: int, Default=2

Desired dimensionality of output data

copy : bool (default True)

If False, data passed to fit are overwritten and running fit(X).transform(X) will not yield the expected results, use fit_transform(X) instead.

whiten : bool, optional

When True (False by default) the components_ vectors are multiplied by the square root of (n_samples) and divided by the singular values to ensure uncorrelated outputs with unit component-wise variances.

Whitening will remove some information from the transformed signal (the relative variance scales of the components) but can sometime improve the predictive accuracy of the downstream estimators by making their data respect some hard-wired assumptions.

svd_solver : string {‘auto’, ‘full’, ‘arpack’, ‘randomized’}

‘auto’ is selected by a default policy based on X.shape and n_components: if the input data is larger than 500x500 and the number of components to extract is lower than 80 percent of the smallest dimension of the data, then the more efficient ‘randomized’ method is enabled. Otherwise the exact full SVD is computed and optionally truncated afterwards. ‘full’ runs exact full SVD calling the standard LAPACK solver via scipy.linalg.svd and select the components by postprocessing ‘arpack’runs SVD truncated to n_components calling ARPACK solver via scipy.sparse.linalg.svds. It requires strictly 0 < n_components < columns. ‘randomized’ runs randomized SVD by the method of Halko et al.

tol : float >= 0, optional (default .0)

Tolerance for singular values computed by svd_solver == ‘arpack’.

iterated_power : int >= 0, or ‘auto’, (default ‘auto’)

Number of iterations for the power method computed by svd_solver == ‘randomized’.

random_state : int, RandomState instance or None, optional (default None)

If int, random_state is the seed used by the random number generator; If RandomState instance, random_state is the random number generator; If None, the random number generator is the RandomState instance used by np.random. Used when svd_solver == ‘arpack’ or ‘randomized’.

verbose: bool

Verbose or not

backend : string, (Default=”auto”)

Which backend to use. Options are ‘auto’, ‘sklearn’, ‘h2o4gpu’. Saves as attribute for actual backend used.

gpu_id : int, optional, default: 0

ID of the GPU on which the algorithm should run. Only used by h2o4gpu backend.

set_attributes()[source]
class h2o4gpu.solvers.pca.PCAH2O(n_components=2, whiten=False, verbose=0, gpu_id=0)[source]

Bases: h2o4gpu.solvers.truncated_svd.TruncatedSVDH2O

Principal Component Analysis (PCA)

Dimensionality reduction using truncated Singular Value Decomposition for GPU

This implementation uses the Cusolver implementation of the truncated SVD. Contrary to SVD, this estimator does center the data before computing the singular value decomposition.

Parameters:
n_components: int, Default=2

Desired dimensionality of output data

whiten : bool, optional

When True (False by default) the components_ vectors are multiplied by the square root of (n_samples) and divided by the singular values to ensure uncorrelated outputs with unit component-wise variances.

Whitening will remove some information from the transformed signal (the relative variance scales of the components) but can sometime improve the predictive accuracy of the downstream estimators by making their data respect some hard-wired assumptions.

verbose: bool

Verbose or not

gpu_id : int, optional, default: 0

ID of the GPU on which the algorithm should run.

fit(X, y=None)[source]

Fit PCA on matrix X.

:param X : {array-like, sparse matrix}, shape (n_samples, n_features)
Training data.
:param y : Ignored,
For ScikitLearn compatibility
:returns self : self
object
fit_transform(X, y=None)[source]

Fit PCA on matrix X and perform dimensionality reduction on X.

:param X : {array-like, sparse matrix}, shape (n_samples, n_features)
Training data.
:param y : Ignored
For ScikitLearn compatibility
:returns X_new : array, shape (n_samples, n_components)
Reduced version of X. This will always be a dense array.

h2o4gpu.solvers.factorization module

Matrix factorization solver.

copyright:2017-2019 H2O.ai, Inc.
license:Apache License Version 2.0 (see LICENSE for details)
class h2o4gpu.solvers.factorization.FactorizationH2O(f, lambda_, max_iter=100, double_precision=False, thetaT=None, XT=None, random_state=1234)[source]

Bases: object

Matrix Factorization on GPU with Alternating Least Square (ALS) algorithm.

Factors a sparse rating matrix X (m by n, with N_z non-zero elements) into a m-by-f and a f-by-n matrices.

Parameters:
f int

decomposition size

lambda_ float

lambda regularization

max_iter int, default: 100

number of training iterations

double_precision bool, default: False

use double precision, not yet supported

thetaT {array-like} shape (n, f), default: None

initial theta matrix

XT {array-like} shape (m, f), default: None

initial XT matrix

random_state int, default: 1234

Warning

Matrixes XT and thetaT may contain nan elements. This is because in some datasets, there are users or items with no ratings in training set. That results in solutions of a system of linear equations becomes nan. Such elements can be easily removed with numpy functions like numpy.nan_to_num, but existence of them may be useful for troubleshooting purposes.

Attributes:
XT {array-like} shape (m, f)

XT matrix contains user’s features

thetaT {array-like} shape (n, f)

transposed theta matrix, item’s features

fit(X, y=None, X_test=None, X_BATCHES=1, THETA_BATCHES=1, early_stopping_rounds=None, verbose=False, scores=None)[source]

Learn model from rating matrix X.

Parameters:
X {array-like, sparse matrix}, shape (m, n)

Data matrix to be decomposed.

y None

Ignored

X_test {array-like, coo sparse matrix}, shape (m, n)

Data matrix for cross validation.

X_BATCHES int, default: 1

Batches to split XT, increase this parameter in case out of memory error.

THETA_BATCHES int, default: 1

Batches to split theta, increase this parameter in case out of memory error.

early_stopping_rounds int, default: None

Activates early stopping. Cross validation error needs to decrease at least every <early_stopping_rounds> round(s) to continue training. Requires <X_test>. Returns the model from the last iteration (not the best one). If early stopping occurs, the model will have three additional fields: best_cv_score, best_train_score and best_iteration.

verbose bool, default: False

Prints training and validation score(if applicable) on each iteration.

scores {list}

List of tuples with train, cv score for every iteration.

Returns:
self : returns an instance of self.
predict(X)[source]

Predict none zero elements of coo sparse matrix X according to the fitted model.

Parameters:
X {array-like, sparse coo matrix} shape (m, n)

Data matrix in coo format. Values are ignored.

Returns:
{array-like, sparse coo matrix} shape (m, n)

Predicted values.

h2o4gpu.solvers.arima module

Autoregressive Integrated Moving Average (ARIMA) model.

copyright:2017-2019 H2O.ai, Inc.
license:Apache License Version 2.0 (see LICENSE for details)
class h2o4gpu.solvers.arima.ARIMA(p, d, q, double_precision=False)[source]

Bases: object

Autoregressive integrated moving average

Parameters:
p : int

AR size

d : int

differencing order

q : int

MA size

double_precision : bool, optional

use double precision, by default False

Attributes:
phi_ {array-like} shape (p,)

AR coefficients

theta_ {array-like} shape (q,)

MA coefficients

fit(y, maxiter=20)[source]

Fit ARIMA model

Parameters:
y : array-like

data to fit into ARIMA model

maxiter : int, optional

number of iterations, by default 20