Skip to content
Open
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
962 changes: 495 additions & 467 deletions examples/example.ipynb

Large diffs are not rendered by default.

143 changes: 143 additions & 0 deletions examples/example_advanced.ipynb
Original file line number Diff line number Diff line change
@@ -0,0 +1,143 @@
{
"cells": [
{
"cell_type": "markdown",
"metadata": {},
"source": [
"# Advanced functionalities\n",
"\n",
"In the example notebook, we learned how to measure the grouping loss and grouping risks with partitioning estimates fitted on the residuals. We can also use broader models such as **Histogram Gradient Boosting** or **Random Forests** directly fitted on the residuals to provide estimates. \n",
"\n",
"\n",
"> **⚠️ Warning:** These estimates come with no theoretical guarantee in our work."
]
},
{
"cell_type": "code",
"execution_count": 1,
"metadata": {},
"outputs": [],
"source": [
"from sklearn.datasets import make_classification\n",
"from sklearn.linear_model import LogisticRegression\n",
"from sklearn.model_selection import train_test_split\n",
"\n",
"X, y = make_classification(\n",
" n_samples=200000, random_state=42, n_features=20, n_informative=20, n_redundant=0\n",
")\n",
"\n",
"X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.5, random_state=0)\n",
"\n",
"est = LogisticRegression()\n",
"est.fit(X_train, y_train)\n",
"S_test = est.predict_proba(X_test)[:, 1]"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"To indicate that we aren't using a partitioning estimator, we use the `residual_estimator` option."
]
},
{
"cell_type": "code",
"execution_count": 2,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"GLEstimator()\n",
" Scoring Rule : Brier: 0.1403\n",
" Grouping loss : 0.1313\n",
" Calibration Loss : 0.0025\n",
" Epistemic Loss : 0.1338\n",
"\n"
]
}
],
"source": [
"from glest.core import GLEstimator\n",
"from sklearn.ensemble import RandomForestRegressor\n",
"\n",
"\n",
"gle_custom = GLEstimator(\n",
" residual_estimator=RandomForestRegressor(n_estimators=100, random_state=42)\n",
")\n",
"gle_custom.fit(X_test, S_test, y_test)\n",
"gle_custom.estimate()\n",
"\n",
"print(gle_custom)"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"The same goes for the RiskEstimator"
]
},
{
"cell_type": "code",
"execution_count": 3,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"(array([0., 0., 0., ..., 0., 0., 0.], shape=(50000,)),\n",
" array([0., 0., 0., ..., 0., 0., 0.], shape=(50000,)))"
]
},
"execution_count": 3,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"from glest.core import RiskEstimator\n",
"\n",
"X_test, X_risk, y_test, y_risk = train_test_split(\n",
" X_test, y_test, test_size=0.5, random_state=0\n",
")\n",
"\n",
"\n",
"S_test = est.predict_proba(X_test)[:, 1]\n",
"\n",
"risk = RiskEstimator(\n",
" residual_estimator=RandomForestRegressor(n_estimators=100, random_state=42)\n",
")\n",
"risk.fit(X_test, S_test, y_test)\n",
"risk.predict(X_risk, est.predict_proba(X_risk)[:, 1].reshape(-1, 1), t=0.5)"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": []
}
],
"metadata": {
"kernelspec": {
"display_name": "glestest",
"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.11.13"
}
},
"nbformat": 4,
"nbformat_minor": 2
}
4 changes: 2 additions & 2 deletions glest/__init__.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
__version__ = "0.0.1-alpha.1"
__version__ = "0.0.2-alpha.1"

from .core import GLEstimator, GLEstimatorCV, Partitioner
from .core import GLEstimator, PartitioningEstimate, RiskEstimator
Loading