Build Warped Linear Regression Models
Project description
peak-engines is a Python package for building Warped Linear Regression models.
Warped Linear Regression is like Ordinary Least Squares but with an extra transformation step where target values are remapped using a parameterized monotonic function and adjusted so as to maximize likelihood on a linear model. The transformation makes Warped Linear Regression more general purpose than Ordinary Least Squares and able to fit models with non-normal error distributions.
For more details on the math behind Warped Linear Regression models see What to Do When Your Model Has a Non-Normal Error Distribution.
Installation
pip install peak-engines
Getting started
Load an example dataset
from sklearn.datasets import load_boston
X, y = load_boston(return_X_y=True)
Split out training and testing portions
from sklearn.model_selection import train_test_split
X_train, X_test, y_train, y_test = train_test_split(
X, y, test_size=0.1, random_state=0)
Fit a Warped Linear Regression Model
import peak_engines
model = peak_engines.WarpedLinearRegressionModel()
model.fit(X_train, y_train)
Visualize the warping function
import numpy as np
import matplotlib.pyplot as plt
y_range = np.arange(np.min(y), np.max(y), 0.01)
z = model.warper_.compute_latent(y_range)
plt.plot(y_range, z)
plt.xlabel('Median Housing Value in $1000s')
plt.ylabel('Latent Variable')
plt.scatter(y, model.warper_.compute_latent(y))
Make predictions
from sklearn.metrics import mean_squared_error
y_pred = model.predict(X_test)
print(mean_squared_error(y_test, y_pred))
41.56037297819257
Compute and plot the error distribution of a prediction
logpdf = model.predict_logpdf([X_test[0]])
def pdf(yi):
return np.exp(logpdf([yi]))
plt.plot(y_range, [pdf(yi) for yi in y_range])
plt.axvline(y_test[0])
plt.xlabel('Median Housing Value in $1000s')
plt.ylabel('Probability Density')
Examples
example/boston_housing.ipynb: Build a model to predict housing values.
example/fish.ipynb: Predict the weight of fish.
example/abalone.ipynb: Predict the age of sea snails.
Documentation
See doc/Reference.pdf.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distributions
Built Distributions
Hashes for peak_engines-0.2.1-cp32-abi3-manylinux1_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | bdc9f30909aa67740eec28eebc293e55c21323bb7f2fa17b8d0f4887328806b0 |
|
MD5 | ccc1b7e7e426c393ebc1da84a7061827 |
|
BLAKE2b-256 | ea41e7dd6e9d42977f82b5b899347980f179dda66c4ed66d52fddecc414988c7 |
Hashes for peak_engines-0.2.1-cp32-abi3-macosx_10_9_intel.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 6ef1c6f36f49fe6a6659ca143f923b720340e62273389f97767600dd2b1b08bd |
|
MD5 | 734a3c2cea61c1c99bf67dd3e973b2db |
|
BLAKE2b-256 | cba420c18f3684a2cb0dfa30aafb960d5ad9c2e11bb82696dd9c3da24bdf7d8f |
Hashes for peak_engines-0.2.1-cp27-cp27mu-manylinux1_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 5f2155a19c5ea327c1b28804ff9abd46cc44bfe46bfb1f5310d0512349a5899d |
|
MD5 | 2f2f435cf489c019ae1975c9d7e5d137 |
|
BLAKE2b-256 | e79ab512615c33c61d4aeafcff7b79ba1aa70510d9ac6af19ea293b6f254fead |
Hashes for peak_engines-0.2.1-cp27-cp27mu-macosx_10_9_intel.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 572ccf33669d714b57dd45f2d7188b33acc7d21b9d48d9e5e8c9243c0c364b8d |
|
MD5 | af5484926e513486dbf21514edc934a1 |
|
BLAKE2b-256 | fc5d06bb6366ff85b638aa7279e66f9609ffcefafee714817142ecf5d3c28c9d |
Hashes for peak_engines-0.2.1-cp27-cp27m-manylinux1_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 7d8ef2f0df37b3a17fb969a30fe1f6d33414d4ebf18d7b09000ab93fdeee5c3f |
|
MD5 | 18a71198fb96d1e55ab1d2ff0407aa4f |
|
BLAKE2b-256 | fcd7abbce3c3a629cc0803c5f69b9e6c2eb1abd3a47cde492c6394c386d13b27 |
Hashes for peak_engines-0.2.1-cp27-cp27m-macosx_10_9_intel.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 5892331cced61b5b0a50f76702f16be2893bdfa5db4fe10bb6ddd448db2091de |
|
MD5 | dcc9b95119bef103c134ce53d8367297 |
|
BLAKE2b-256 | 5918ef21be5a076b748759650b373bfd1137bfd6521cf60da0229e00f58accaf |