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.2-cp32-abi3-manylinux1_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 67cced784c6caadcc5fb1a8fc14e95500e25904230328c9660c600eb8663452f |
|
MD5 | 9eb3575a4409b0dbeee2593d41d90735 |
|
BLAKE2b-256 | 1012a2395f68c33977efb31b5770b5b13fa2c65d8ed72ff32bd8f11b8d72c988 |
Hashes for peak_engines-0.2.2-cp32-abi3-macosx_10_9_intel.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 640e9c3c67e878fb6d6ac44c0250b89fb65f6e459361b667cfccb1308fe9196d |
|
MD5 | 025c51605c692d28ee2276f5f9481987 |
|
BLAKE2b-256 | 1df40b39dc2a345a724084ba5a74a18f0190106f2281e3fc07ac121f29d33c59 |
Hashes for peak_engines-0.2.2-cp27-cp27mu-manylinux1_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | aefc50ba1556917352a04245220ae5f3fc564c0bf304e5e5d1ef5ce9c176bd12 |
|
MD5 | 9d93024b7db6a44db028d68efe23d81e |
|
BLAKE2b-256 | 565498a6d909aa22f6d8c1a3cef4ef426bec7cea09e8e2e4c45de4ea807bdaf2 |
Hashes for peak_engines-0.2.2-cp27-cp27mu-macosx_10_9_intel.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 42c6a1ce66370f774e48a4efc7c309ebb04b185be1574e12f5fed00453d34ac4 |
|
MD5 | 8026548098a17ef0f44432ec6406bccd |
|
BLAKE2b-256 | 8b052f4a69229b23dd906e25fd537be6ba8108bc845eadafe79686afb0472505 |
Hashes for peak_engines-0.2.2-cp27-cp27m-manylinux1_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 7ac090e757f8a4c3da0cdaf5a40faf14adf5a7cf6dbdd27d4978b722a8a79180 |
|
MD5 | 57f56e5f738894f6403593daa84a6010 |
|
BLAKE2b-256 | 987eda17f9fd206b64f5f45ada5bf96e795988dc83cf631783b3334746c20966 |
Hashes for peak_engines-0.2.2-cp27-cp27m-macosx_10_9_intel.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 25d7181ad1c2183331c2b8b0295efb93349c1b863ef9193c6de490ea189b4f43 |
|
MD5 | 04d0fe6991132b5c32725d057adc8dfb |
|
BLAKE2b-256 | 6b2601599fad5e8f4ce6fe47a03dfc5b66c527238592e468c29c7cd22783d7e2 |