Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Minor fixes #891

Merged
merged 6 commits into from
Jul 3, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 10 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,6 @@
[![PyPI wheel](https://img.shields.io/pypi/wheel/econml.svg)](https://pypi.org/project/econml/)
[![Supported Python versions](https://img.shields.io/pypi/pyversions/econml.svg)](https://pypi.org/project/econml/)



<h1>
<a href="https://econml.azurewebsites.net/">
<img src="doc/econml-logo-icon.png" width="80px" align="left" style="margin-right: 10px;", alt="econml-logo">
Expand Down Expand Up @@ -51,6 +49,8 @@ For information on use cases and background material on causal inference and het

# News

If you'd like to contribute to this project, see the [Help Wanted](#help-wanted) section below.

**February 12, 2024:** Release v0.15.0, see release notes [here](https://github.com/py-why/EconML/releases/tag/v0.15.0)

<details><summary>Previous releases</summary>
Expand Down Expand Up @@ -665,11 +665,15 @@ You can get started by cloning this repository. We use
We rely on some recent features of setuptools, so make sure to upgrade to a recent version with
`pip install setuptools --upgrade`. Then from your local copy of the repository you can run `pip install -e .` to get started (but depending on what you're doing you might want to install with extras instead, like `pip install -e .[plt]` if you want to use matplotlib integration, or you can use `pip install -e .[all]` to include all extras).

## Help wanted

If you're looking to contribute to the project, we have a number of issues tagged with the [`help wanted`](https://github.com/py-why/EconML/issues?q=is%3Aopen+is%3Aissue+label%3A%22help+wanted%22) label that are valuable improvements to the library that our team currently does not have time to prioritize where we would greatly appreciate community-initiated PRs.

## Running the tests

This project uses [pytest](https://docs.pytest.org/) for testing. To run tests locally after installing the package, you can use `pip install pytest-runner` followed by `python setup.py pytest`.
This project uses [pytest](https://docs.pytest.org/) for testing. To run all tests locally after installing the package, you can use `pip install pytest-runner` followed by `python setup.py pytest`.

We have added pytest marks to some tests to make it easier to run a subset, and you can set the PYTEST_ADDOPTS environment variable to take advantage of this. For instance, you can set it to `-m "not (notebook or automl)"` to skip notebook and automl tests that have some additional dependencies.
However, running all tests can be very time-consuming, so you may prefer to run just a relevant subset of tests when developing locally. The easiest way to do this is to rely on `pytest`'s compatibility with `unittest`, so you can just run `python -m unittest econml.tests.test_module` to run all tests in a given module, or `python -m unittest econml.tests.test_module.TestClass` to run all tests in a given class. You can also run `python -m unittest econml.tests.test_module.TestClass.test_method` to run a single test method.

## Generating the documentation

Expand All @@ -691,6 +695,8 @@ We use GitHub Actions to build and publish the package and documentation. To cr

# Blogs and Publications

* May 2021: [Be Careful When Interpreting Predictive Models in Search of Causal Insights](https://towardsdatascience.com/be-careful-when-interpreting-predictive-models-in-search-of-causal-insights-e68626e664b6)

* June 2019: [Treatment Effects with Instruments paper](https://arxiv.org/pdf/1905.10176.pdf)

* May 2019: [Open Data Science Conference Workshop](https://odsc.com/speakers/machine-learning-estimation-of-heterogeneous-treatment-effect-the-microsoft-econml-library/)
Expand Down
7 changes: 6 additions & 1 deletion econml/_ensemble/_ensemble.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,14 @@
import numpy as np
from abc import ABCMeta, abstractmethod
from sklearn.base import BaseEstimator, clone
from sklearn.utils import _print_elapsed_time
from sklearn.utils import check_random_state
from joblib import effective_n_jobs
from packaging.version import parse
import sklearn
if parse(sklearn.__version__) < parse("1.5"):
from sklearn.utils import _print_elapsed_time
else:
from sklearn.utils._user_interface import _print_elapsed_time


def _fit_single_estimator(estimator, X, y, sample_weight=None,
Expand Down
4 changes: 2 additions & 2 deletions econml/dml/causal_forest.py
Original file line number Diff line number Diff line change
Expand Up @@ -567,7 +567,7 @@ class CausalForestDML(_BaseDML):
ate_ : ndarray of shape (n_outcomes, n_treatments)
The average constant marginal treatment effect of each treatment for each outcome,
averaged over the training data and with a doubly robust correction. Available only
when `discrete_treatment=True` and `oob=True`.
when `discrete_treatment=True` and `drate=True`.
ate_stderr_ : ndarray of shape (n_outcomes, n_treatments)
The standard error of the `ate_` attribute.
feature_importances_ : ndarray of shape (n_features,)
Expand Down Expand Up @@ -997,7 +997,7 @@ def att__inference(self, *, T):
Inference results information for the `att_` attribute, which is the average
constant marginal treatment effect of each treatment for each outcome, averaged
over the training data treated with treatment T and with a doubly robust correction.
Available only when `discrete_treatment=True` and `oob=True`.
Available only when `discrete_treatment=True` and `drate=True`.
"""
return NormalInferenceResults(d_t=self._d_t[0] if self._d_t else 1,
d_y=self._d_y[0] if self._d_y else 1,
Expand Down
3 changes: 2 additions & 1 deletion econml/policy/_drlearner.py
Original file line number Diff line number Diff line change
Expand Up @@ -854,7 +854,8 @@ def _gen_drpolicy_learner(self):
cv=self.cv,
mc_iters=self.mc_iters,
mc_agg=self.mc_agg,
model_final=PolicyForest(max_depth=self.max_depth,
model_final=PolicyForest(n_estimators=self.n_estimators,
max_depth=self.max_depth,
min_samples_split=self.min_samples_split,
min_samples_leaf=self.min_samples_leaf,
min_weight_fraction_leaf=self.min_weight_fraction_leaf,
Expand Down
7 changes: 6 additions & 1 deletion econml/solutions/causal_analysis/_causal_analysis.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,12 @@
# TODO: this utility is documented but internal; reimplement?
from sklearn.utils import _safe_indexing
# TODO: this utility is even less public...
from sklearn.utils import _get_column_indices
from packaging.version import parse
import sklearn
if parse(sklearn.__version__) < parse("1.5"):
from sklearn.utils import _get_column_indices
else:
from sklearn.utils._indexing import _get_column_indices


class _CausalInsightsConstants:
Expand Down
4 changes: 2 additions & 2 deletions econml/tests/test_policy_forest.py
Original file line number Diff line number Diff line change
Expand Up @@ -321,8 +321,8 @@ def test_non_standard_input(self,):
model_propensity=DummyClassifier(strategy='uniform'),
featurizer=PolynomialFeatures(degree=1, include_bias=False),
cv=GroupKFold(n_splits=2),
n_estimators=20, n_jobs=1, random_state=123).fit(y, T, X=X,
groups=groups)
n_estimators=100, n_jobs=1, random_state=123).fit(y, T, X=X,
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this for test stability?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Because n_estimators was never passed correctly to DRPolicyForest in the past, this has always effectively run with n_estimators=100 (the default value), and the tests don't pass if we actually pass 20 through instead.

groups=groups)
mask = np.abs(Xraw[:, 0]) > .1
np.testing.assert_allclose(pred[mask], forest.predict(Xraw[mask]))
np.testing.assert_allclose(pred_val[mask, 1] - pred_val[mask, 0],
Expand Down
4 changes: 2 additions & 2 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,9 @@ classifiers = [
"Operating System :: POSIX :: Linux"
]
dependencies = [
"numpy",
"numpy<2",
"scipy > 1.4.0",
"scikit-learn >= 1.0, < 1.5",
"scikit-learn >= 1.0, < 1.6",
"sparse",
"joblib >= 0.13.0",
"statsmodels >= 0.10",
Expand Down
Loading