Deep ensembles for Keras
Project description
Keras Deep Ensemble Implementation
This is an implementation of Lakshminarayanan et al. deep ensembles paper in Keras. It creates an ensemble of models that can predict uncertainty. You provide a model which outputs two values (mean, variance) and the library will ensemble and resample your data for ensemble training. We have made some modifications, which will be described more fully in an upcoming paper. Please no scoops.
This package is meant to be really simple. It has one function and one class: resample(y)
, which reshapes data for ensemble training and DeepEnsemble
, which ensembles a Keras model.
Quickstart
This example makes a Keras model inside a function and then reshapes data for ensemble training. Notice a DeepEnsemble
model acts just like a Keras model.
import kdens
import tensorflow as tf
# this is where you define your model
def make_model():
i = tf.keras.Input((None,))
x = tf.keras.layers.Dense(10, activation="relu")
mean = tf.keras.layers.Dense(1)(x)
# this activation makes our variance strictly positive
var = tf.keras.layers.Dense(1, activation='softplus')(x)
out = tf.squeeze(tf.stack([muhat, stdhat], axis=-1))
model = tf.keras.Model(inputs=inputs, outputs=out)
return model
# prepare data for ensemble training
resampled_idx = kdens.resample(y)
x_train = x[idx]
y_train = y[idx]
deep_ens = kdens.DeepEnsemble(make_model)
# loss is always log-likelihood, so not specified
deep_ens.compile()
deep_ens.fit(x_train, y_train)
deep_ens(x)
API
Citation
Deep ensemble paper:
@article{lakshminarayanan2017simple,
title={Simple and scalable predictive uncertainty estimation using deep ensembles},
author={Lakshminarayanan, Balaji and Pritzel, Alexander and Blundell, Charles},
journal={Advances in neural information processing systems},
volume={30},
year={2017}
}
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Hashes for kdeepensemble-0.1.0-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 976839ee4c422bf55056ce616c0219231ac7377f42ce17298e046c2fc0b5b3d3 |
|
MD5 | eb7d447965152a09807064e78a613f69 |
|
BLAKE2b-256 | c5236a443e8c019d206b38f74862a3742303f847d13f31c29b75030ec46d8446 |