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.0-cp32-abi3-manylinux1_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | ec02345b2ea7d65f2eb4be762063ce27104306fd4cac107035150d6bd512bf87 |
|
MD5 | 06e3c7d33af2f1dc266f77de3b407411 |
|
BLAKE2b-256 | 76a4045bcd5530d1821c4f7dac8610eb0b1fd98789644b28e3e3980ed05b519b |
Hashes for peak_engines-0.2.0-cp32-abi3-macosx_10_9_intel.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 56ce2e1a7f7711fd06fe80182defa996b7b5dc7e366812e5af617519e1bd8b7b |
|
MD5 | 7d850b7feedf8f23b64ccae139c01a5e |
|
BLAKE2b-256 | 67628e4d19095c079bd8cc5c85fea6023eed39c6997211b823570f5f9fa45a80 |
Hashes for peak_engines-0.2.0-cp27-cp27mu-manylinux1_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | d6cf8e1e01c74d01c2f327237e932ad90f55673ea316e7be8dd633ae2bb57851 |
|
MD5 | eb31514e6c6e4e2488b0d5d7d1f3997f |
|
BLAKE2b-256 | 488f38cffd07c6309f629de5a0945f366cebc779e766c57fe2e0b9128ee32cb1 |
Hashes for peak_engines-0.2.0-cp27-cp27mu-macosx_10_9_intel.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 96f9b98e94c0b795d537760e3752c7fe777f800c4a468848e411a7fc5ec64e30 |
|
MD5 | 6a481d56b12390ecaf549c375575ccda |
|
BLAKE2b-256 | 5482ca34bab2914668310cb9b9121ef975c9f13e12e1cf4b2e988e702ebcb0c5 |
Hashes for peak_engines-0.2.0-cp27-cp27m-manylinux1_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | db2821814cc5fc1771fd4b71d1caca8b3caf03a6766879b4b9ecd6630ce298d9 |
|
MD5 | 5166ae38698256f5aa9a5052b7a6e1df |
|
BLAKE2b-256 | bdb2fa9fdb142dff55994b85c3d830c5b07be5020df50a9fdb43319cdb20775f |
Hashes for peak_engines-0.2.0-cp27-cp27m-macosx_10_9_intel.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | fd894692edb746d7048ca929e56d3b4b458fd8983a3f756febb71e6099699d6b |
|
MD5 | 50a573650e4c261ac217a2fa28d69bbf |
|
BLAKE2b-256 | 4becd836443f99b9d982e098ef1cb9202e5a357abf7a58d4e4dd939a205c2557 |