Skip to main content

peak-engines

PyPI version License: CC BY 4.0 API Reference

peak-engines is machine learning framework that focuses on applying advanced optimization algorithms to build better models.

Installation

pip install peak-engines

Fit Logistic Regression Hyperparameters

The leave-one-out cross-validation of logistic regression can be efficiently approximated. At a high level, this is how it works: For given hyperparameters C, we

  1. Find the parameters b that optimize logistic regression for the given C.
  2. For each data index i, we compute the hessian H_{-i} and gradient g_{-i} of the log-likelihood with the ith data entry removed. (We can reuse the hessian computed from (1) to do this with a minimal amount of work.)
  3. We apply the Matrix Inversion Lemma to efficiently compute the inverse H_{-i}^{-1}.
  4. We use H_{-i}^{-1} and g_{-i} to take a single step of Newton's method to approximate the logistic regression coefficients with the ith entry removed b_{-i}.
  5. And finally, we used the b_{-i}'s to approximate the out-of-sample predictions and estimate the leave-one-out cross-validation.

See the paper A scalable estimate of the out-of-sample prediction error via approximate leave-one-out by Kamiar Rad and Arian Maleki for more details.

We can, furthermore, differentiate the Approximate Leave-One-Out metric with respect to the hyperparameters and quickly climb to the best performing C. Here's how to do it with peak-engines:

Load an example dataset

from sklearn.datasets import load_breast_cancer
from sklearn.preprocessing import StandardScaler
X, y = load_breast_cancer(return_X_y=True)
X = StandardScaler().fit_transform(X)

Find the best performing C

model = peak_engines.LogisticRegressionModel()
model.fit(X, y)
print('C =', model.C_[0])

prints

C = 0.66474879

If we compute the LOOCV by brute force and compare to the ALOOCV, we can see how accurate the approximation is

alt text

Fit Ridge Regression Hyperparameters

By expressing cross-validation as an optimization objective and computing derivatives, peak-engines is able to efficiently find regularization parameters that lead to the best score on a leave-one-out or generalized cross-validation. It, futhermore, scales to handle multiple regularizers. Here's an example of how it works

import numpy as np
from sklearn.datasets import load_boston
X, y = load_boston(return_X_y=True)
from peak_engines import RidgeRegressionModel
model = RidgeRegressionModel(normalize=True)
# Fit will automatically find the best alpha that minimizes the Leave-one-out Cross-validation.
# when you call fit. There's no need to provide a search space because peak_engines optimizes the
# LOOCV directly. It the computes derivatives of the LOOCV with respect to the hyperparameters and
# is able to quickly zero in on the best alpha.
model.fit(X, y)
print('alpha =', model.alpha_)

prints

alpha = 0.009274259071634289

Fit Warped Linear Regression

Let X and y denote the feature matrix and target vector of a regression dataset. Under the assumption of normally distributed errors, Ordinary Least Squares (OLS) finds the linear model that maximizes the likelihood of the dataset

What happens when errors aren't normally distributed? Well, the model will be misspecified and there's no reason to think its likelihood predictions will be accurate. This is where Warped Linear Regression can help. It introduces an extra step to OLS where it transforms the target vector using a malleable, monotonic function f parameterized by ψ and adjusts the parameters to maximize the likelihood of the transformed dataset

By introducing the additional transformation step, Warped Linear Regression is more general-purpose than OLS while still retaining the strong structure and interpretability. Here's how you use it

Load an example dataset

from sklearn.datasets import load_boston
X, y = load_boston(return_X_y=True)

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))

alt text

Tutorials

Articles

Examples

Documentation

See doc/Reference.pdf

Metadata

Release files for peak-engines 0.2.8

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Built distributions (wheels)

Table of built distributions (wheels) for peak-engines 0.2.8
File
peak_engines-0.2.8-cp32-abi3-manylinux1_x86_64.whl CPython 3.2 abi3 Linux glibc 2.5+ x86-64 Details
peak_engines-0.2.8-cp32-abi3-macosx_10_9_intel.whl CPython 3.2 abi3 macOS 10.9+ Intel (x86-64, i386) Details
peak_engines-0.2.8-cp27-cp27mu-manylinux1_x86_64.whl CPython 2.7 CPython 2.7 pymalloc wide-unicode Linux glibc 2.5+ x86-64 Details
peak_engines-0.2.8-cp27-cp27mu-macosx_10_9_intel.whl CPython 2.7 CPython 2.7 pymalloc wide-unicode macOS 10.9+ Intel (x86-64, i386) Details
peak_engines-0.2.8-cp27-cp27m-manylinux1_x86_64.whl CPython 2.7 CPython 2.7 pymalloc Linux glibc 2.5+ x86-64 Details
peak_engines-0.2.8-cp27-cp27m-macosx_10_9_intel.whl CPython 2.7 CPython 2.7 pymalloc macOS 10.9+ Intel (x86-64, i386) Details

Total release size: 99.7 MB

Release files / peak_engines-0.2.8-cp32-abi3-manylinux1_x86_64.whl

Download URL peak_engines-0.2.8-cp32-abi3-manylinux1_x86_64.whl
Size 16.3 MB
Tags CPython 3.2 Linux glibc 2.5+ x86-64 abi3
SHA-256 checksum
How to use checksums
dfc086ef678495bd98585c44439e1060f72a4f6464fd50e0d671f5d67d09494c
BLAKE2b-256 checksum
How to use checksums
e6e041a6c8c9eb7188ece08dc7dc7b46e29000bf048ccbddb758ebcb41f62862
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.1.1 pkginfo/1.5.0.1 requests/2.22.0 setuptools/41.4.0 requests-toolbelt/0.9.1 tqdm/4.36.1 CPython/3.7.4

Release files / peak_engines-0.2.8-cp32-abi3-macosx_10_9_intel.whl

Download URL peak_engines-0.2.8-cp32-abi3-macosx_10_9_intel.whl
Size 16.9 MB
Tags CPython 3.2 abi3 macOS 10.9+ Intel (x86-64, i386)
SHA-256 checksum
How to use checksums
b0aa2ca6b228953dd73625002c54568f31f7da4fffca1efb6c8a7b728ae766f5
BLAKE2b-256 checksum
How to use checksums
21b3b28cfda3a336d6770da34465cda4ec132408e28d2d101da9c15500454457
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.1.1 pkginfo/1.5.0.1 requests/2.22.0 setuptools/41.4.0 requests-toolbelt/0.9.1 tqdm/4.36.1 CPython/3.7.4

Release files / peak_engines-0.2.8-cp27-cp27mu-manylinux1_x86_64.whl

Download URL peak_engines-0.2.8-cp27-cp27mu-manylinux1_x86_64.whl
Size 16.3 MB
Tags CPython 2.7 CPython 2.7 pymalloc wide-unicode Linux glibc 2.5+ x86-64
SHA-256 checksum
How to use checksums
494cfb20e08d98a7c8ba836665c598811a7f5010a0955ce45c748086857bd901
BLAKE2b-256 checksum
How to use checksums
95a35af0985586d6e3b29ca26e637feb0375bcdc8f93936bd167d924ed2ef3e0
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.1.1 pkginfo/1.5.0.1 requests/2.22.0 setuptools/41.4.0 requests-toolbelt/0.9.1 tqdm/4.36.1 CPython/3.7.4

Release files / peak_engines-0.2.8-cp27-cp27mu-macosx_10_9_intel.whl

Download URL peak_engines-0.2.8-cp27-cp27mu-macosx_10_9_intel.whl
Size 16.9 MB
Tags CPython 2.7 CPython 2.7 pymalloc wide-unicode macOS 10.9+ Intel (x86-64, i386)
SHA-256 checksum
How to use checksums
5a72b2c4423c59ef6aedb5b62390d86347c82242b6ece047180cdf45dfa8aa3f
BLAKE2b-256 checksum
How to use checksums
9deb675a5eb22a2d6a52d7adc8578e5aea7878bd32d34158c72f2f8a056d468f
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.1.1 pkginfo/1.5.0.1 requests/2.22.0 setuptools/41.4.0 requests-toolbelt/0.9.1 tqdm/4.36.1 CPython/3.7.4

Release files / peak_engines-0.2.8-cp27-cp27m-manylinux1_x86_64.whl

Download URL peak_engines-0.2.8-cp27-cp27m-manylinux1_x86_64.whl
Size 16.3 MB
Tags CPython 2.7 CPython 2.7 pymalloc Linux glibc 2.5+ x86-64
SHA-256 checksum
How to use checksums
b0a6d39dbed3b2f5aea97811d70be94ed9013a5610121c39535a730da8d9254e
BLAKE2b-256 checksum
How to use checksums
7a5179f7c79b4a99c28b525a8f498fa6a51325a0c673e773ac4a5183d0ac7e0d
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.1.1 pkginfo/1.5.0.1 requests/2.22.0 setuptools/41.4.0 requests-toolbelt/0.9.1 tqdm/4.36.1 CPython/3.7.4

Release files / peak_engines-0.2.8-cp27-cp27m-macosx_10_9_intel.whl

Download URL peak_engines-0.2.8-cp27-cp27m-macosx_10_9_intel.whl
Size 16.9 MB
Tags CPython 2.7 CPython 2.7 pymalloc macOS 10.9+ Intel (x86-64, i386)
SHA-256 checksum
How to use checksums
79600d7242d574cd46f4bbc051f4b7ff67c1da38230d9722e25d8758e6a967d3
BLAKE2b-256 checksum
How to use checksums
57dfc7afeb593097fb4f17c11fcb63d9dadb067726a1b91c437683970c5080cf
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.1.1 pkginfo/1.5.0.1 requests/2.22.0 setuptools/41.4.0 requests-toolbelt/0.9.1 tqdm/4.36.1 CPython/3.7.4

Security for peak-engines 0.2.8

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page