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.1.1-cp32-abi3-manylinux1_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 7ee7dda20ff6aa8fc2a6317caa58546045cc4efa217b7326a6ff0e48fe07c42a |
|
MD5 | f8edddb6ade887f307a7af289a81e430 |
|
BLAKE2b-256 | 2bc1a1f97dcb00f07aa780e53cb1176a503c5c1c9fb7260290426c48bafcf500 |
Hashes for peak_engines-0.1.1-cp32-abi3-macosx_10_9_intel.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | b6e8c510fb051819ce2383a0f958fa2054b28b0c77b632314b23f43056863f1e |
|
MD5 | 904abfad2afa403fd730c8ffa33f4112 |
|
BLAKE2b-256 | 8f7bf27010a3d5557eb47a952a5dfc49bf25ffdbaa926c2c3b28893a06323bfc |
Hashes for peak_engines-0.1.1-cp27-cp27mu-manylinux1_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | ba78d4f2d3de2c5252d569ae36d75f330d66ab6fc5f1e3b3975272094e728c96 |
|
MD5 | 9d6d66bd7c487614ca6ba325ac7a80c7 |
|
BLAKE2b-256 | f4470de9079bb1482c82f4b7a278aa9f2e74e355c03139f446dfa1fde3fda679 |
Hashes for peak_engines-0.1.1-cp27-cp27mu-macosx_10_9_intel.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 1654edc521fe9a8df3228f4448c8fa73987ceefda132d56483c5519ed3a45b86 |
|
MD5 | d7fa214865c64b23bd5effe633f3d4c8 |
|
BLAKE2b-256 | 7c63e8a23266096b0bfa0d0ff460f62f78ac97568b87c2b8f60af988ed69d84e |
Hashes for peak_engines-0.1.1-cp27-cp27m-manylinux1_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | fcebc7e778d2497346d4da3a3d78c9f399084032f027be0c6aad13b7a2c49441 |
|
MD5 | 6f36f7ef117eec6cf5e50a02c747ccb1 |
|
BLAKE2b-256 | ed36c18e2bbff7e8091409e7a13f4c156b473d43224a5b68b1889cb80e3f9801 |
Hashes for peak_engines-0.1.1-cp27-cp27m-macosx_10_9_intel.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | e985cf3f2a5feac9e6683fbd2ff41a23f361db22eec231396fa2519dc4ea9cc8 |
|
MD5 | 5308db84ee9350a6d823f480460e782a |
|
BLAKE2b-256 | 87b69ab1b2172caf6ff9fedf758fb8ca0565b50eb60f820b9b257eb51ab7d545 |