Skip to content

Commit

Permalink
#21 update examples with reflective and pessimistic uplift
Browse files Browse the repository at this point in the history
  • Loading branch information
andrewtavis committed Apr 3, 2021
1 parent c0dd783 commit 99ece7e
Show file tree
Hide file tree
Showing 2 changed files with 87 additions and 1 deletion.
12 changes: 12 additions & 0 deletions examples/an_iterated_model_dataset_comparison.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -954,6 +954,18 @@
" ),\n",
" regularize=True,\n",
" )\n",
"\n",
" ru = ReflectiveUplift(\n",
" model=RandomForestClassifier(\n",
" n_estimators=200, criterion=\"gini\", bootstrap=True\n",
" )\n",
" )\n",
"\n",
" pu = PessimisticUplift(\n",
" model=RandomForestClassifier(\n",
" n_estimators=200, criterion=\"gini\", bootstrap=True\n",
" )\n",
" )\n",
" print(\"---{} Iterations---\".format(dataset))\n",
" for model in [tm_class, it_class, bt_class, qt_class]:\n",
" (\n",
Expand Down
76 changes: 75 additions & 1 deletion examples/business_hilstrom.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
},
"source": [
"<h1>Table of Contents<span class=\"tocSkip\"></span></h1>\n",
"<div class=\"toc\"><ul class=\"toc-item\"><li><span><a href=\"#Load-Data\" data-toc-modified-id=\"Load-Data-1\"><span class=\"toc-item-num\">1&nbsp;&nbsp;</span>Load Data</a></span><ul class=\"toc-item\"><li><span><a href=\"#Exploration-Data\" data-toc-modified-id=\"Exploration-Data-1.1\"><span class=\"toc-item-num\">1.1&nbsp;&nbsp;</span>Exploration Data</a></span></li><li><span><a href=\"#Modeling-Data\" data-toc-modified-id=\"Modeling-Data-1.2\"><span class=\"toc-item-num\">1.2&nbsp;&nbsp;</span>Modeling Data</a></span></li></ul></li><li><span><a href=\"#Data-Exploration\" data-toc-modified-id=\"Data-Exploration-2\"><span class=\"toc-item-num\">2&nbsp;&nbsp;</span>Data Exploration</a></span><ul class=\"toc-item\"><li><span><a href=\"#Full-Data-Visualization\" data-toc-modified-id=\"Full-Data-Visualization-2.1\"><span class=\"toc-item-num\">2.1&nbsp;&nbsp;</span>Full Data Visualization</a></span></li><li><span><a href=\"#Modeling-Data-Preparation\" data-toc-modified-id=\"Modeling-Data-Preparation-2.2\"><span class=\"toc-item-num\">2.2&nbsp;&nbsp;</span>Modeling Data Preparation</a></span></li></ul></li><li><span><a href=\"#Standard-Models\" data-toc-modified-id=\"Standard-Models-3\"><span class=\"toc-item-num\">3&nbsp;&nbsp;</span>Standard Models</a></span><ul class=\"toc-item\"><li><span><a href=\"#Two-Model\" data-toc-modified-id=\"Two-Model-3.1\"><span class=\"toc-item-num\">3.1&nbsp;&nbsp;</span>Two Model</a></span></li><li><span><a href=\"#Interaction-Term\" data-toc-modified-id=\"Interaction-Term-3.2\"><span class=\"toc-item-num\">3.2&nbsp;&nbsp;</span>Interaction Term</a></span></li><li><span><a href=\"#Class-Transformations\" data-toc-modified-id=\"Class-Transformations-3.3\"><span class=\"toc-item-num\">3.3&nbsp;&nbsp;</span>Class Transformations</a></span><ul class=\"toc-item\"><li><span><a href=\"#Binary-Transformation\" data-toc-modified-id=\"Binary-Transformation-3.3.1\"><span class=\"toc-item-num\">3.3.1&nbsp;&nbsp;</span>Binary Transformation</a></span></li><li><span><a href=\"#Quaternary-Transformation\" data-toc-modified-id=\"Quaternary-Transformation-3.3.2\"><span class=\"toc-item-num\">3.3.2&nbsp;&nbsp;</span>Quaternary Transformation</a></span></li></ul></li></ul></li><li><span><a href=\"#Evaluation\" data-toc-modified-id=\"Evaluation-4\"><span class=\"toc-item-num\">4&nbsp;&nbsp;</span>Evaluation</a></span><ul class=\"toc-item\"><li><span><a href=\"#Iterations\" data-toc-modified-id=\"Iterations-4.1\"><span class=\"toc-item-num\">4.1&nbsp;&nbsp;</span>Iterations</a></span></li><li><span><a href=\"#Visual\" data-toc-modified-id=\"Visual-4.2\"><span class=\"toc-item-num\">4.2&nbsp;&nbsp;</span>Visual</a></span></li><li><span><a href=\"#Iterated-Evaluation-and-Variance\" data-toc-modified-id=\"Iterated-Evaluation-and-Variance-4.3\"><span class=\"toc-item-num\">4.3&nbsp;&nbsp;</span>Iterated Evaluation and Variance</a></span></li></ul></li></ul></div>"
"<div class=\"toc\"><ul class=\"toc-item\"><li><span><a href=\"#Load-Data\" data-toc-modified-id=\"Load-Data-1\"><span class=\"toc-item-num\">1&nbsp;&nbsp;</span>Load Data</a></span><ul class=\"toc-item\"><li><span><a href=\"#Exploration-Data\" data-toc-modified-id=\"Exploration-Data-1.1\"><span class=\"toc-item-num\">1.1&nbsp;&nbsp;</span>Exploration Data</a></span></li><li><span><a href=\"#Modeling-Data\" data-toc-modified-id=\"Modeling-Data-1.2\"><span class=\"toc-item-num\">1.2&nbsp;&nbsp;</span>Modeling Data</a></span></li></ul></li><li><span><a href=\"#Data-Exploration\" data-toc-modified-id=\"Data-Exploration-2\"><span class=\"toc-item-num\">2&nbsp;&nbsp;</span>Data Exploration</a></span><ul class=\"toc-item\"><li><span><a href=\"#Full-Data-Visualization\" data-toc-modified-id=\"Full-Data-Visualization-2.1\"><span class=\"toc-item-num\">2.1&nbsp;&nbsp;</span>Full Data Visualization</a></span></li><li><span><a href=\"#Modeling-Data-Preparation\" data-toc-modified-id=\"Modeling-Data-Preparation-2.2\"><span class=\"toc-item-num\">2.2&nbsp;&nbsp;</span>Modeling Data Preparation</a></span></li></ul></li><li><span><a href=\"#Standard-Models\" data-toc-modified-id=\"Standard-Models-3\"><span class=\"toc-item-num\">3&nbsp;&nbsp;</span>Standard Models</a></span><ul class=\"toc-item\"><li><span><a href=\"#Two-Model\" data-toc-modified-id=\"Two-Model-3.1\"><span class=\"toc-item-num\">3.1&nbsp;&nbsp;</span>Two Model</a></span></li><li><span><a href=\"#Interaction-Term\" data-toc-modified-id=\"Interaction-Term-3.2\"><span class=\"toc-item-num\">3.2&nbsp;&nbsp;</span>Interaction Term</a></span></li><li><span><a href=\"#Class-Transformations\" data-toc-modified-id=\"Class-Transformations-3.3\"><span class=\"toc-item-num\">3.3&nbsp;&nbsp;</span>Class Transformations</a></span><ul class=\"toc-item\"><li><span><a href=\"#Binary-Transformation\" data-toc-modified-id=\"Binary-Transformation-3.3.1\"><span class=\"toc-item-num\">3.3.1&nbsp;&nbsp;</span>Binary Transformation</a></span></li><li><span><a href=\"#Quaternary-Transformation\" data-toc-modified-id=\"Quaternary-Transformation-3.3.2\"><span class=\"toc-item-num\">3.3.2&nbsp;&nbsp;</span>Quaternary Transformation</a></span></li></ul></li><li><span><a href=\"#Reflective-Uplift\" data-toc-modified-id=\"Reflective-Uplift-3.4\"><span class=\"toc-item-num\">3.4&nbsp;&nbsp;</span>Reflective Uplift</a></span></li><li><span><a href=\"#Pessimistic-Uplift\" data-toc-modified-id=\"Pessimistic-Uplift-3.5\"><span class=\"toc-item-num\">3.5&nbsp;&nbsp;</span>Pessimistic Uplift</a></span></li></ul></li><li><span><a href=\"#Evaluation\" data-toc-modified-id=\"Evaluation-4\"><span class=\"toc-item-num\">4&nbsp;&nbsp;</span>Evaluation</a></span><ul class=\"toc-item\"><li><span><a href=\"#Iterations\" data-toc-modified-id=\"Iterations-4.1\"><span class=\"toc-item-num\">4.1&nbsp;&nbsp;</span>Iterations</a></span></li><li><span><a href=\"#Visual\" data-toc-modified-id=\"Visual-4.2\"><span class=\"toc-item-num\">4.2&nbsp;&nbsp;</span>Visual</a></span></li><li><span><a href=\"#Iterated-Evaluation-and-Variance\" data-toc-modified-id=\"Iterated-Evaluation-and-Variance-4.3\"><span class=\"toc-item-num\">4.3&nbsp;&nbsp;</span>Iterated Evaluation and Variance</a></span></li></ul></li></ul></div>"
]
},
{
Expand Down Expand Up @@ -1569,6 +1569,60 @@
"qt_probas[:5]"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Reflective Uplift"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"ru = ReflectiveUplift(model=RandomForestClassifier())\n",
"ru.fit(X=X_train, y=y_train, w=w_train)"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"ru_probas = ru.predict_proba(X=X_test)\n",
"ru_probas"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Pessimistic Uplift"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"pu = PessimisticUplift(model=RandomForestClassifier())\n",
"pu.fit(X=X_train, y=y_train, w=w_train)"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"pu_probas = pu.predict_proba(X=X_test)\n",
"pu_probas"
]
},
{
"cell_type": "markdown",
"metadata": {},
Expand Down Expand Up @@ -1616,6 +1670,14 @@
"qt = QuaternaryTransformation(\n",
" model=RandomForestClassifier(n_estimators=200, criterion=\"gini\", bootstrap=True),\n",
" regularize=False,\n",
")\n",
"\n",
"ru = ReflectiveUplift(\n",
" model=RandomForestClassifier(n_estimators=200, criterion=\"gini\", bootstrap=True)\n",
")\n",
"\n",
"pu = PessimisticUplift(\n",
" model=RandomForestClassifier(n_estimators=200, criterion=\"gini\", bootstrap=True)\n",
")"
]
},
Expand Down Expand Up @@ -1731,6 +1793,18 @@
"qt_effects = [\n",
" proba[0] - proba[1]\n",
" for proba in model_eval_dict[\"Hillstrom\"][\"QuaternaryTransformation\"][\"avg_preds\"]\n",
"]\n",
"\n",
"# Reflective favorable and unfavorable class probability subtraction\n",
"ru_effects = [\n",
" proba[0] - proba[1]\n",
" for proba in model_eval_dict[\"Hillstrom\"][\"ReflectiveUplift\"][\"avg_preds\"]\n",
"]\n",
"\n",
"# Pessimistic favorable and unfavorable class probability subtraction\n",
"pu_effects = [\n",
" proba[0] - proba[1]\n",
" for proba in model_eval_dict[\"Hillstrom\"][\"PessimisticUplift\"][\"avg_preds\"]\n",
"]"
]
},
Expand Down

0 comments on commit 99ece7e

Please sign in to comment.