Skip to content

Commit

Permalink
Add mapie
Browse files Browse the repository at this point in the history
  • Loading branch information
baniasbaabe committed Jan 15, 2024
1 parent 1d37a28 commit 59091fd
Showing 1 changed file with 52 additions and 0 deletions.
52 changes: 52 additions & 0 deletions book/machinelearning/modeltraining.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -1837,6 +1837,58 @@
"model = timm.create_model('densenet121', pretrained=True)\n",
"output = model(torch.randn(2, 3, 224, 224))"
]
},
{
"cell_type": "markdown",
"id": "69feb793",
"metadata": {},
"source": [
"## Generate Guaranteed Prediction Intervals and Sets with `MAPIE`"
]
},
{
"cell_type": "markdown",
"id": "41226b58",
"metadata": {},
"source": [
"For quantifying uncertainties of your models, use MAPIE.\n",
"\n",
"`MAPIE` (Model Agnostic Prediction Interval Estimator) takes your sklearn-/tensorflow-/pytorch-compatible model and generate prediction intervals or sets with guaranteed coverage."
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "f7abfe51",
"metadata": {},
"outputs": [],
"source": [
"!pip install mapie"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "ecf3cdf1",
"metadata": {},
"outputs": [],
"source": [
"from mapie.regression import MapieRegressor\n",
"import numpy as np\n",
"from sklearn.linear_model import LinearRegression\n",
"from sklearn.datasets import make_regression\n",
"from sklearn.model_selection import train_test_split\n",
"\n",
"X, y = make_regression(n_samples=500, n_features=1, noise=20, random_state=59)\n",
"X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.5)\n",
"regressor = LinearRegression()\n",
"\n",
"mapie_regressor = MapieRegressor(regressor)\n",
"mapie_regressor.fit(X_train, y_train)\n",
"\n",
"alpha = [0.05, 0.20]\n",
"y_pred, y_pis = mapie_regressor.predict(X_test, alpha=alpha)"
]
}
],
"metadata": {
Expand Down

0 comments on commit 59091fd

Please sign in to comment.