Giter VIP home page Giter VIP logo

deepiv's Introduction

DeepIV

Documentation Status Updates

IMPORTANT: Newer versions of Keras have broken this implementation. This code currently only support Keras 2.0.6 (which is what will be installed if you use the pip install instructions described below).

A package for counterfactual prediction using deep instrument variable methods that builds on Keras.

You can read how the method works in our DeepIV paper.

If you use this package in your research, please cite it as:

@inproceedings{Hartford17,
author    = {Jason Hartford and
        Greg Lewis and
        Kevin Leyton-Brown and
        Matt Taddy},
title     = {Deep IV: A Flexible Approach for Counterfactual Prediction},
booktitle = {Proceedings of the 34th International Conference on Machine Learning,
        {ICML} 2017, Sydney, Australia, 6-11 August 2017},
pages     = {1--9},
year      = {2017}
}

Installation

To use DeepIV, you can simply naviage to to the DeepIV directory on your machine and run:

pip install .

You can then use the package by simply running: import deepiv in python. See the examples directory for example usage.

The package is currently under active development, so you may want to install it using the following command:

pip install -e .

By doing this, every time you git pull an update, it will be reflected in your installation.

Usage

The DeepIV package is simply a subclass of the Keras Model class that provides the necessary functions for fitting Deep instrumental variable models. Because of this, you can think of it as a drop-in replacement of the Keras Model object. The DeepIV procedure consists of two stages: 1. Fit the Treatment model. 2. Fit the Response model that takes the fitted Treatment model as input.

Example usage is shown in the experiments directory.

demand_simulation.py gives a simple example using a feedforward network for both the treatment and the response models.

demand_simulation_mnist.py is a little more complicated: it uses a convolutation network to fit an image embedding and then concatinates the embedding with other features to fit the network.

Both those examples use simulated data where ground truth is known, so they can report the causal mean squared error. On real data this isn't possible, so we advise that you use a holdout set to tune hyperparameters of the network (or cross validation in the case of small networks). You can choose hyperparameters based on the losses returned at each stage (see the paper for details on why this works).

DeepIV should be compatable with all Keras layers, so the Keras documentation is a good place to learn about designing network architectures. Feel free to file a bug report if something doesn't work.

Credits

This package was created with Cookiecutter and the audreyr/cookiecutter-pypackage project template.

deepiv's People

Contributors

jhartford avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

deepiv's Issues

[Bug] pip install is not working

From the documentation:

To install deepiv, run this command in your terminal:
$ pip install deepiv

It looks like it's not installing through this method:

$ pip install deepiv
Collecting deepiv
  Could not find a version that satisfies the requirement deepiv (from versions: )
No matching distribution found for deepiv

What's going on? Is the package no longer available?

Inference

Does this package also generate the standard errors / variance of the predictions, as mentioned in the inference section of the paper?

image

It is important for inference though. It will be nice to include this feature.

Support for newer versions of Keras

Versions of Keras newer than 2.0.6 break my implementation of the mixture of gaussian loss. This occurs because the new version of Keras requires that you supply target values that are the same dimension as the number of outputs your network has, but when we're using a mixture density network we have 3*n outputs where n is the number of mixture components (corresponding to the mean, standard deviation and mixture weight parameters for each component)...

[Bug] Keras 2.0.6 & Tensorflow compatibility

Some versions of tensorflow seem to be incompatible with Keras 2.0.6, unaddressed by pip installation listed in docs.

Traceback (most recent call last):
File "/Exploratory/DeepIV.py", line 5, in
from deepiv.models import Treatment, Response
File "/anaconda3/envs/deepiv/lib/python3.6/site-packages/deepiv/models.py", line 6, in
import deepiv.samplers as samplers
File "/anaconda3/envs/deepiv/lib/python3.6/site-packages/deepiv/samplers.py", line 4, in
from keras import backend as K
File "/anaconda3/envs/deepiv/lib/python3.6/site-packages/keras/init.py", line 4, in
from . import activations
File "/anaconda3/envs/deepiv/lib/python3.6/site-packages/keras/activations.py", line 6, in
from .engine import Layer
File "/anaconda3/envs/deepiv/lib/python3.6/site-packages/keras/engine/init.py", line 8, in
from .training import Model
File "/anaconda3/envs/deepiv/lib/python3.6/site-packages/keras/engine/training.py", line 25, in
from .. import callbacks as cbks
File "/anaconda3/envs/deepiv/lib/python3.6/site-packages/keras/callbacks.py", line 26, in
from tensorflow.contrib.tensorboard.plugins import projector
ModuleNotFoundError: No module named 'tensorflow.contrib'

include more loss functions

thanks for providing such a neat implementation! I am interested in adding poisson loss function in DeepIV since my response variable (i.e. y) is skewed to the right. I am not entirely sure if there is anything I need to modify in the code other than adding one more gradient replacement with poisson loss in the response class. Appreciates any help! Thanks!

data_generator

I think the data_generator.py is in the incorrect folder for the "pip install - e . " command to work as described in the README.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.