Skip to content

Commit

Permalink
Add causal analysis
Browse files Browse the repository at this point in the history
  • Loading branch information
kbattocchi committed Apr 15, 2021
1 parent 9630421 commit 32d321e
Show file tree
Hide file tree
Showing 9 changed files with 1,088 additions and 1 deletion.
5 changes: 5 additions & 0 deletions azure-pipelines-steps.yml
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,11 @@ jobs:
displayName: 'Install graphviz on Linux'
condition: and(succeeded(), eq(variables['Agent.OS'], 'Linux'))

# Install OpenMP on Mac to support lightgbm
- script: 'brew install libomp'
displayName: 'Install OpenMP on Mac'
condition: and(succeeded(), eq(variables['Agent.OS'], 'Darwin'))

# Install the package
- script: 'python -m pip install --upgrade pip && pip install --upgrade setuptools wheel Cython && pip install ${{ parameters.package }}'
displayName: 'Install dependencies'
Expand Down
11 changes: 11 additions & 0 deletions doc/reference.rst
Original file line number Diff line number Diff line change
Expand Up @@ -252,6 +252,17 @@ Utilities

econml.utilities

Solutions
---------

Causal Feature Importance
^^^^^^^^^^^^^^^^^^^^^^^^^

.. autosummary::
:toctree: _autosummary

econml.solutions.causal_analysis

Private Module Reference
========================

Expand Down
1 change: 1 addition & 0 deletions econml/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
'ortho_iv',
'policy',
'score',
'solutions',
'sklearn_extensions',
'tree',
'two_stage_least_squares',
Expand Down
21 changes: 21 additions & 0 deletions econml/inference/_inference.py
Original file line number Diff line number Diff line change
Expand Up @@ -867,6 +867,19 @@ def _expand_outputs(self, n_rows):
"""
pass

def translate(self, offset):
"""
Update the results in place by translating by an offset.
Parameters
----------
offset: array-like
The offset by which to translate these results
"""
# NOTE: use np.asarray(offset) becuase if offset is a pd.Series direct addition would make the sum
# a Series as well, which would subsequently break summary_frame because flatten isn't supported
self.pred = self.pred + np.asarray(offset)


class NormalInferenceResults(InferenceResults):
"""
Expand Down Expand Up @@ -1081,6 +1094,14 @@ def _expand_outputs(self, n_rows):
return EmpiricalInferenceResults(self.d_t, self.d_y, pred, pred_dist, self.inf_type, self.fname_transformer,
self.feature_names, self.output_names, self.treatment_names)

def translate(self, other):
# offset preds
super().translate(other)
# offset the distribution, too
self.pred_dist = self.pred_dist + np.asarray(other)

translate.__doc__ = InferenceResults.translate.__doc__


class PopulationSummaryResults:
"""
Expand Down
6 changes: 6 additions & 0 deletions econml/solutions/causal_analysis/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
# Copyright (c) Microsoft Corporation. All rights reserved.
# Licensed under the MIT License.

from ._causal_analysis import CausalAnalysis

__all__ = ["CausalAnalysis"]
Loading

0 comments on commit 32d321e

Please sign in to comment.