mojolearn.TweedieRegressor#

class mojolearn.TweedieRegressor(*, power=0.0, alpha=1.0, fit_intercept=True, link='auto', solver='lbfgs', max_iter=100, tol=0.0001, warm_start=False, verbose=0)[source]#

Bases: _GLMBase

Generalized linear model with a Tweedie distribution.

Follows scikit-learn’s TweedieRegressor. Supported powers are 0 (normal), 1 (Poisson), between 1 and 2 (compound Poisson-Gamma), 2 (Gamma) and above 2. power < 0 and 0 < power < 1 raise ValueError, as does the identity link with power > 0. Unlike scikit-learn, score returns R^2, not the deviance-based D^2.

Parameters:
  • power (float, default 0.0) – Tweedie power; sets the distribution and the valid range of y.

  • alpha (float, default 1.0) – L2 regularization strength (>= 0).

  • fit_intercept (bool, default True) – Whether to fit an intercept.

  • link ({‘auto’, ‘identity’, ‘log’}, default ‘auto’) – Link function; ‘auto’ is identity for power=0 and log otherwise.

  • solver ({‘lbfgs’, ‘newton-cholesky’}, default ‘lbfgs’) – Accepted for compatibility; both run a Newton-Cholesky solver.

  • max_iter (int, default 100) – Maximum number of solver iterations.

  • tol (float, default 1e-4) – Stopping tolerance.

  • warm_start (bool, default False) – Not supported: True raises ValueError.

  • verbose (int, default 0) – Accepted for compatibility; ignored.

  • numeric_mode (str or None, default None) – Numeric mode for this model ('identical', 'deterministic' or 'fast', which runs on Apple GPUs only); None uses the process default (see mojolearn.set_numeric_mode()).

Variables:
  • coef_ (float32 array of shape (n_features,)) – Weights.

  • intercept_ (float) – Intercept.

  • n_iter_ (int) – Number of solver iterations run.

  • n_features_in_ (int) – Number of features seen in fit.

Examples

>>> import numpy as np, mojolearn
>>> rng = np.random.default_rng(0)
>>> X = rng.random((1000, 8), dtype=np.float32)
>>> y = rng.poisson(np.exp(X[:, 0])).astype(np.float32)
>>> model = mojolearn.TweedieRegressor(power=1.5, alpha=0.01).fit(X, y)
__init__(*, power=0.0, alpha=1.0, fit_intercept=True, link='auto', solver='lbfgs', max_iter=100, tol=0.0001, warm_start=False, verbose=0)[source]#

Methods

fit(X, y[, sample_weight])

Fit the generalized linear model.

get_params([deep])

numeric_mode_used()

The numeric mode this estimator runs in.

predict(X)

Predict targets for X.

score(X, y)

Coefficient of determination R^2 of predict(X) against y.

set_params(**params)

Set constructor parameters.

vendor_used()

The GPU backend this estimator runs on.