Skip to main content

Linear generalized Huber estimator compatible with scikit-learn.

Project description

ghlestimator

Linear Generalized Huber Regressor compatible with scikit-learn. A detailed explanation of the underlying generalized Huber objective function can be found here.

The Generalized Huber Regressor depends on the definition of a invertible link function g and optimizes a term proportional to (y - ginv(X'w))**2 for samples where |g(y) - (X'w)| <= epsilon and a term proportional to |y - ginv(X'w)| for samples where |g(y) - (X'w)| > epsilon, where w is to be optimized and ginv denotes the inverse of g.

Parameters

class GeneralizedHuberRegressor(epsilon=1.0,max_iter=100,tol=1e-5, scale=10,
fit_intercept=True, link_dict={'g':_log,'ginv':_loginv,'ginvp':_loginvp})

epsilon : float, default 1.0

The parameter epsilon defines the crossover between the rmse type of loss 
and the mae type of loss.  

max_iter : int, default 100

Maximum number of iterations that
scipy.optimize.minimize(method="L-BFGS-B") should run for.

fit_intercept : bool, default True

Whether or not to fit the intercept.

tol : float, default 1e-5

The iteration will stop when max{|proj g_i | i = 1, ..., n} <= tol
where pg_i is the i-th component of the projected gradient.

scale : float, default 10.0

Preconditioner for better numerical stability. Input array is internally 
divided by scale.

link_dict : dictionary, default {'g':_log,'ginv':_loginv,'ginvp':_loginvp}

The link function 'g', it's inverse 'ginv' and the derivative of the 
latter 'ginvp' have to be specified as callables. 
The default link function is g(x) = sign(x)log(1+|x|).              

Attributes

coef_ : array, shape (n_features,)

Fitted coefficients got by optimizing the generalized Huber loss.

intercept_ : float

The bias.

n_iter_ : int

Number of iterations that
scipy.optimize.minimize(method="L-BFGS-B") has run for.

Methods

fit(self, X, y)

Fit the model to the given training features X and target y both given as 
ndarrays.

predict(self, X)

Predict using the fitted linear model.

score(self, X, y)

Return the coefficient of determination R^2 of the prediction.

Installation

Use the package manager pip to install ghlestimator.

pip install ghlestimator

Usage

from ghlestimator import GeneralizedHuberRegressor

ghl = GeneralizedHuberRegressor() # initializes default ghl estimator 
ghl.fit(X, y) # fit on features X and target y
ghl.score(X, y) # compute the R^2 score
ghl.predict(X) # make pedictions

License

MIT

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

ghlestimator-1.0.0.tar.gz (5.5 kB view details)

Uploaded Source

Built Distribution

ghlestimator-1.0.0-py3-none-any.whl (7.0 kB view details)

Uploaded Python 3

File details

Details for the file ghlestimator-1.0.0.tar.gz.

File metadata

  • Download URL: ghlestimator-1.0.0.tar.gz
  • Upload date:
  • Size: 5.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.13.0 pkginfo/1.5.0.1 requests/2.23.0 setuptools/45.2.0.post20200210 requests-toolbelt/0.9.1 tqdm/4.43.0 CPython/3.7.4

File hashes

Hashes for ghlestimator-1.0.0.tar.gz
Algorithm Hash digest
SHA256 272847542a6af45cba8ef1994577afb2b08265fe67e376b027faec5c21d38f6c
MD5 d06809283c5ccbb80280cf9077e5ac48
BLAKE2b-256 d7b641afd77a0c3a9daf4fb6e384fe7a60532f80321df28c530246d6623707ad

See more details on using hashes here.

File details

Details for the file ghlestimator-1.0.0-py3-none-any.whl.

File metadata

  • Download URL: ghlestimator-1.0.0-py3-none-any.whl
  • Upload date:
  • Size: 7.0 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.13.0 pkginfo/1.5.0.1 requests/2.23.0 setuptools/45.2.0.post20200210 requests-toolbelt/0.9.1 tqdm/4.43.0 CPython/3.7.4

File hashes

Hashes for ghlestimator-1.0.0-py3-none-any.whl
Algorithm Hash digest
SHA256 8c9593da69eabfdbe944b418869e5fc1d0ee1527a5d33dacec3c74c0da7710ae
MD5 eab2b229a1005b2d58fa9782e5d76a39
BLAKE2b-256 e3435d32ff6c07bbb0dc97b4ede83192e21bb5695666a9578686ab3f9a07d440

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page