Skip to content

Commit

Permalink
Merge pull request #739 from erikcs/maq-optional
Browse files Browse the repository at this point in the history
Remove maq git+pip dependency
  • Loading branch information
ras44 committed Feb 13, 2024
2 parents 57332cb + 892bcba commit 7ccbaf7
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 21 deletions.
1 change: 0 additions & 1 deletion causalml/metrics/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,4 +32,3 @@
SensitivitySubsetData,
SensitivitySelectionBias,
) # noqa
from maq import MAQ, get_ipw_scores # noqa
22 changes: 20 additions & 2 deletions docs/examples/qini_curves_for_costly_treatment_arms.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,25 @@
"source": [
"# Qini curves with multiple costly treatment arms\n",
"\n",
"This notebook gives a brief overview of Qini curves for multi-armed treatment rules and a simple simulated example."
"This notebook shows approaches to evaluating multi-armed CATE estimators from `causalML` with the Multi-Armed Qini metric available in the `maq` package (available at https://github.com/grf-labs/maq).\n",
"\n",
"\n",
"This metric is a generalization of the familiar *Qini curve* to settings where we have multiple treatment arms available, and the cost of assigning treatment can vary by both unit and treatment arm according to some known cost structure. At a high level, this metric essentially allows you to quantify the value of targeting with more treatment arms by undertaking a cost-benefit exercise that uses your CATE estimates to assign the arm to the unit that is most cost-beneficial at various budget constraints.\n",
"\n",
"This notebook gives a brief overview of the statistical setup and a walkthrough with a simple simulated example. \n",
"\n",
"\n",
"To use this functionality, you first have to install the `maq` Python package from GitHub. The latest source release can be installed with:"
]
},
{
"cell_type": "markdown",
"id": "0a633fa7",
"metadata": {},
"source": [
"```\n",
"pip install \"git+https://github.com/grf-labs/maq.git#egg=maq&subdirectory=python-package\"\n",
"```"
]
},
{
Expand All @@ -22,7 +40,7 @@
"from xgboost import XGBRFRegressor\n",
"\n",
"# Generalized Qini curves\n",
"from causalml.metrics import MAQ, get_ipw_scores\n",
"from maq import MAQ, get_ipw_scores\n",
"\n",
"import numpy as np\n",
"np.random.seed(42)"
Expand Down
1 change: 0 additions & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,6 @@ dependencies = [
"torch",
"pyro-ppl",
"graphviz",
"maq@git+https://github.com/grf-labs/maq.git@py0.2.2#egg=maq&subdirectory=python-package",
]

[project.optional-dependencies]
Expand Down
17 changes: 0 additions & 17 deletions tests/test_metrics.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
import pandas as pd
import numpy as np
from numpy import isclose
from causalml.metrics.visualize import qini_score
from causalml.metrics import MAQ, get_ipw_scores


def test_qini_score():
Expand All @@ -28,18 +26,3 @@ def test_qini_score():
# for each learner, its qini score should stay same no matter calling with another model or calling separately
assert isclose(full_result["learner_1"], learner_1_result["learner_1"])
assert isclose(full_result["learner_2"], learner_2_result["learner_2"])


def test_MAQ():
np.random.seed(42)
n = 1000
K = 5
tau_hat = np.random.randn(n, K)
cost = np.random.rand(n, K)
DR_scores = np.random.randn(n, K)

mq = MAQ(n_bootstrap=200)
mq.fit(tau_hat, cost, DR_scores)

# (0.005729002695991717, 0.019814651108894354)
assert isclose(mq.average_gain(spend=0.1)[0], 0.005729)

0 comments on commit 7ccbaf7

Please sign in to comment.