Documentation
Classes
TweedieRegressor

TweedieRegressor

Generalized Linear Model with a Tweedie distribution.

This estimator can be used to model different GLMs depending on the power parameter, which determines the underlying distribution.

Read more in the User Guide.

Python Reference (opens in a new tab)

Constructors

constructor()

Signature

new TweedieRegressor(opts?: object): TweedieRegressor;

Parameters

NameTypeDescription
opts?object-
opts.alpha?numberConstant that multiplies the L2 penalty term and determines the regularization strength. alpha \= 0 is equivalent to unpenalized GLMs. In this case, the design matrix X must have full column rank (no collinearities). Values of alpha must be in the range \[0.0, inf). Default Value 1
opts.fit_intercept?booleanSpecifies if a constant (a.k.a. bias or intercept) should be added to the linear predictor (X @ coef + intercept). Default Value true
opts.link?"auto" | "log" | "identity"The link function of the GLM, i.e. mapping from linear predictor X @ coeff + intercept to prediction y\_pred. Option ‘auto’ sets the link depending on the chosen power parameter as follows: Default Value 'auto'
opts.max_iter?numberThe maximal number of iterations for the solver. Values must be in the range \[1, inf). Default Value 100
opts.power?numberThe power determines the underlying target distribution according to the following table: Default Value 0
opts.solver?"lbfgs" | "newton-cholesky"Algorithm to use in the optimization problem: Default Value 'lbfgs'
opts.tol?numberStopping criterion. For the lbfgs solver, the iteration will stop when max{|g\_j|, j \= 1, ..., d} <= tol where g\_j is the j-th component of the gradient (derivative) of the objective function. Values must be in the range (0.0, inf). Default Value 0.0001
opts.verbose?numberFor the lbfgs solver set verbose to any positive number for verbosity. Values must be in the range \[0, inf). Default Value 0
opts.warm_start?booleanIf set to true, reuse the solution of the previous call to fit as initialization for coef\_ and intercept\_ . Default Value false

Returns

TweedieRegressor

Defined in: generated/linear_model/TweedieRegressor.ts:25 (opens in a new tab)

Properties

_isDisposed

boolean = false

Defined in: generated/linear_model/TweedieRegressor.ts:23 (opens in a new tab)

_isInitialized

boolean = false

Defined in: generated/linear_model/TweedieRegressor.ts:22 (opens in a new tab)

_py

PythonBridge

Defined in: generated/linear_model/TweedieRegressor.ts:21 (opens in a new tab)

id

string

Defined in: generated/linear_model/TweedieRegressor.ts:18 (opens in a new tab)

opts

any

Defined in: generated/linear_model/TweedieRegressor.ts:19 (opens in a new tab)

Accessors

coef_

Estimated coefficients for the linear predictor (X @ coef\_ + intercept\_) in the GLM.

Signature

coef_(): Promise<any[]>;

Returns

Promise<any[]>

Defined in: generated/linear_model/TweedieRegressor.ts:310 (opens in a new tab)

feature_names_in_

Names of features seen during fit. Defined only when X has feature names that are all strings.

Signature

feature_names_in_(): Promise<ArrayLike>;

Returns

Promise<ArrayLike>

Defined in: generated/linear_model/TweedieRegressor.ts:418 (opens in a new tab)

intercept_

Intercept (a.k.a. bias) added to linear predictor.

Signature

intercept_(): Promise<number>;

Returns

Promise<number>

Defined in: generated/linear_model/TweedieRegressor.ts:337 (opens in a new tab)

n_features_in_

Number of features seen during fit.

Signature

n_features_in_(): Promise<number>;

Returns

Promise<number>

Defined in: generated/linear_model/TweedieRegressor.ts:391 (opens in a new tab)

n_iter_

Actual number of iterations used in the solver.

Signature

n_iter_(): Promise<number>;

Returns

Promise<number>

Defined in: generated/linear_model/TweedieRegressor.ts:364 (opens in a new tab)

py

Signature

py(): PythonBridge;

Returns

PythonBridge

Defined in: generated/linear_model/TweedieRegressor.ts:93 (opens in a new tab)

Signature

py(pythonBridge: PythonBridge): void;

Parameters

NameType
pythonBridgePythonBridge

Returns

void

Defined in: generated/linear_model/TweedieRegressor.ts:97 (opens in a new tab)

Methods

dispose()

Disposes of the underlying Python resources.

Once dispose() is called, the instance is no longer usable.

Signature

dispose(): Promise<void>;

Returns

Promise<void>

Defined in: generated/linear_model/TweedieRegressor.ts:156 (opens in a new tab)

fit()

Fit a Generalized Linear Model.

Signature

fit(opts: object): Promise<any>;

Parameters

NameTypeDescription
optsobject-
opts.X?ArrayLikeTraining data.
opts.sample_weight?ArrayLikeSample weights.
opts.y?ArrayLikeTarget values.

Returns

Promise<any>

Defined in: generated/linear_model/TweedieRegressor.ts:173 (opens in a new tab)

init()

Initializes the underlying Python resources.

This instance is not usable until the Promise returned by init() resolves.

Signature

init(py: PythonBridge): Promise<void>;

Parameters

NameType
pyPythonBridge

Returns

Promise<void>

Defined in: generated/linear_model/TweedieRegressor.ts:106 (opens in a new tab)

predict()

Predict using GLM with feature matrix X.

Signature

predict(opts: object): Promise<any[]>;

Parameters

NameTypeDescription
optsobject-
opts.X?ArrayLikeSamples.

Returns

Promise<any[]>

Defined in: generated/linear_model/TweedieRegressor.ts:222 (opens in a new tab)

score()

Compute D^2, the percentage of deviance explained.

D^2 is a generalization of the coefficient of determination R^2. R^2 uses squared error and D^2 uses the deviance of this GLM, see the User Guide.

D^2 is defined as \(D^2 = 1-\frac{D(y_{true},y_{pred})}{D_{null}}\), \(D_{null}\) is the null deviance, i.e. the deviance of a model with intercept alone, which corresponds to \(y_{pred} = \bar{y}\). The mean \(\bar{y}\) is averaged by sample_weight. Best possible score is 1.0 and it can be negative (because the model can be arbitrarily worse).

Signature

score(opts: object): Promise<number>;

Parameters

NameTypeDescription
optsobject-
opts.X?ArrayLikeTest samples.
opts.sample_weight?ArrayLikeSample weights.
opts.y?ArrayLikeTrue values of target.

Returns

Promise<number>

Defined in: generated/linear_model/TweedieRegressor.ts:261 (opens in a new tab)