πThanks for playing around with PyExplainer, I really appreciate your time! π
\n",
"####
π₯ More Features will be Released Soon π₯
"
]
},
{
"cell_type": "markdown",
"id": "difficult-algeria",
"metadata": {},
"source": [
"# π Appendex π"
]
},
{
"cell_type": "markdown",
"id": "numeric-efficiency",
"metadata": {},
"source": [
"## A. π΅π» What's in the Rule Object (rule_obj) ? Let's unbox it ! π¦"
]
},
{
"cell_type": "markdown",
"id": "increased-indicator",
"metadata": {},
"source": [
"### Basic Data Check"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "respective-program",
"metadata": {},
"outputs": [],
"source": [
"print(\"Type of Rule Object: \", type(load_pyExp_rule_obj))\n",
"print()\n",
"print(\"All of the keys in Rule Object\")\n",
"i = 1\n",
"for k in load_pyExp_rule_obj.keys():\n",
" print(\"Key \", i, \" - \",k)\n",
" i += 1"
]
},
{
"cell_type": "markdown",
"id": "forward-freeze",
"metadata": {},
"source": [
"### π Key 1 - synthetic_data\n",
"#### As can be seen below, the synthetic data are data coming from feature columns\n",
"#### This synthetic data was generated internally by the PyExplainer when the .explain(...) method is triggered\n",
"#### Currently we have 2 approaches to generate synthetic_data\n",
"#### Approach (1) Crossover and Interpolation\n",
"#### Approach (2) Random Pertubation\n",
"#### After the process of C&I. or RP., synthetic_data will be generated as a DataFrame below"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "laden-doubt",
"metadata": {},
"outputs": [],
"source": [
"print(\"Type of pyExp_rule_obj['synthetic_data'] - \", type(load_pyExp_rule_obj['synthetic_data']), \"\\n\")\n",
"print(\"Example\", \"\\n\\n\", load_pyExp_rule_obj['synthetic_data'].head(2))"
]
},
{
"cell_type": "markdown",
"id": "blind-mustang",
"metadata": {},
"source": [
"### π Key 2 - synthetic_predictions\n",
"#### As can be seen below, the synthetic prediction are data coming from the prediction column\n",
"#### This synthetic prediction was generated internally by the PyExplainer when the .explain(...) method is triggered\n",
"#### This synthetic prediction is created based on the black box model we passed to the PyExplainer when initialising (section 1.5 & 2.3)\n",
"#### This synthetic prediction is generated based on the synthetic data above therefore it's called synthetic_predictions\n",
"#### >>> e.g. synthetic_predictions = blackbox_model.predict(synthetic_data) Note. we only need feature cols in synthetic_data"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "municipal-operation",
"metadata": {},
"outputs": [],
"source": [
"print(\"Type of pyExp_rule_obj['synthetic_predictions'] - \", type(load_pyExp_rule_obj['synthetic_predictions']), \"\\n\")\n",
"print(\"Example\", \"\\n\\n\", load_pyExp_rule_obj['synthetic_predictions'])"
]
},
{
"cell_type": "markdown",
"id": "adjacent-begin",
"metadata": {},
"source": [
"### π Key 3 - X_explain\n",
"#### This X_explain is exactly the same as the one we passed to .explain(...) method (section 3.3 & section 3.4)"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "according-profession",
"metadata": {},
"outputs": [],
"source": [
"print(\"Type of pyExp_rule_obj['X_explain'] - \", type(load_pyExp_rule_obj['X_explain']), \"\\n\")\n",
"print(\"Example\", \"\\n\\n\", load_pyExp_rule_obj['X_explain'])"
]
},
{
"cell_type": "markdown",
"id": "spectacular-feeling",
"metadata": {},
"source": [
"### π Key 4 - y_explain\n",
"#### This y_explain is exactly the same as the one we passed to .explain(...) method (section 3.3 & section 3.4)"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "present-breakdown",
"metadata": {},
"outputs": [],
"source": [
"print(\"Type of pyExp_rule_obj['y_explain'] - \", type(load_pyExp_rule_obj['y_explain']), \"\\n\")\n",
"print(\"Example\", \"\\n\\n\", load_pyExp_rule_obj['y_explain'])"
]
},
{
"cell_type": "markdown",
"id": "serious-territory",
"metadata": {},
"source": [
"### π Key 5 - indep\n",
"#### Names of the Selected Feature Cols"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "sublime-ethernet",
"metadata": {},
"outputs": [],
"source": [
"print(\"Type of pyExp_rule_obj['indep'] - \", type(load_pyExp_rule_obj['indep']), \"\\n\")\n",
"print(\"Example\", \"\\n\\n\", load_pyExp_rule_obj['indep'])"
]
},
{
"cell_type": "markdown",
"id": "designed-barbados",
"metadata": {},
"source": [
"### π Key 6 - dep\n",
"#### Names of the Label Col (Prediction Col)"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "agreed-health",
"metadata": {},
"outputs": [],
"source": [
"print(\"Type of pyExp_rule_obj['dep'] - \", type(load_pyExp_rule_obj['dep']), \"\\n\")\n",
"print(\"Example\", \"\\n\\n\", load_pyExp_rule_obj['dep'])"
]
},
{
"cell_type": "markdown",
"id": "noted-wiring",
"metadata": {},
"source": [
"### π Key 7 - top_k_positive_rules\n",
"#### This shows the top k positive rules generated by the RuleFit model inside the .explain(...) function\n",
"#### The value of 'top_k' can be tuned in when we create a Rule Object manually (section 3.4), the default value is 3"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "northern-registration",
"metadata": {},
"outputs": [],
"source": [
"print(\"Type of pyExp_rule_obj['top_k_positive_rules'] - \", type(load_pyExp_rule_obj['top_k_positive_rules']), \"\\n\")\n",
"print(\"Example\", \"\\n\\n\", load_pyExp_rule_obj['top_k_positive_rules'])"
]
},
{
"cell_type": "markdown",
"id": "contemporary-honolulu",
"metadata": {},
"source": [
"### π Key 8 - top_k_negative_rules\n",
"#### This shows the top k negative rules generated by the RuleFit model inside the .explain(...) function\n",
"#### The value of 'top_k' can be tuned in when we create a Rule Object manually (section 3.4), the default value is 3\n",
"#### However, in the current version, the top_k value is always the same for both negative and positive rules which can be improved in the future version"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "swiss-costa",
"metadata": {},
"outputs": [],
"source": [
"print(\"Type of pyExp_rule_obj['top_k_negative_rules'] - \", type(load_pyExp_rule_obj['top_k_negative_rules']), \"\\n\")\n",
"print(\"Example\", \"\\n\\n\", load_pyExp_rule_obj['top_k_negative_rules'])"
]
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3",
"language": "python",
"name": "python3"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.8.8"
}
},
"nbformat": 4,
"nbformat_minor": 5
}