Skip to content

Commit

Permalink
Executed the bias_variance notebooks for faster documentation build.
Browse files Browse the repository at this point in the history
  • Loading branch information
matthewgillett committed Dec 1, 2023
1 parent c7a7976 commit bb74639
Show file tree
Hide file tree
Showing 3 changed files with 339 additions and 112 deletions.
119 changes: 86 additions & 33 deletions docs/notebooks/bias_variance/BiasVarianceClassification.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,19 @@
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 1,
"id": "84f10ff2",
"metadata": {},
"outputs": [],
"outputs": [
{
"name": "stderr",
"output_type": "stream",
"text": [
"WARNING: All log messages before absl::InitializeLog() is called are written to STDERR\n",
"I0000 00:00:1701450732.304993 1 tfrt_cpu_pjrt_client.cc:349] TfrtCpuClient created.\n"
]
}
],
"source": [
"import pandas as pd\n",
"\n",
Expand All @@ -28,7 +37,7 @@
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 2,
"id": "9184a4c1-f608-4983-b6c0-31a817f20a19",
"metadata": {},
"outputs": [],
Expand All @@ -46,7 +55,7 @@
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 3,
"id": "1b6763e6",
"metadata": {},
"outputs": [],
Expand All @@ -67,7 +76,7 @@
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 4,
"id": "a838e1d8",
"metadata": {},
"outputs": [],
Expand All @@ -79,7 +88,7 @@
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 5,
"id": "5b8c734c",
"metadata": {},
"outputs": [],
Expand All @@ -97,7 +106,7 @@
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 6,
"id": "642bc9e3",
"metadata": {},
"outputs": [],
Expand All @@ -107,13 +116,24 @@
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 7,
"id": "f5ed38bf",
"metadata": {},
"outputs": [],
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"average loss: 0.06066667\n",
"average bias: 0.04444444\n",
"average variance: 0.03311111\n",
"net variance: 0.01622222\n"
]
}
],
"source": [
"# Use wrapped estimator\n",
"avg_loss, avg_bias, avg_var, net_var = bias_variance_compute(model_scikit_wrapped, X_train, y_train, X_test, y_test, iterations=10, \n",
"avg_loss, avg_bias, avg_var, net_var = bias_variance_compute(model_scikit_wrapped, X_train, y_train, X_test, y_test, iterations=200, \n",
" random_state=random_state, decomp_fn=bias_variance_0_1_loss)\n",
"\n",
"print(f'average loss: {avg_loss:10.8f}')\n",
Expand All @@ -132,7 +152,7 @@
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 8,
"id": "c8d7471f",
"metadata": {},
"outputs": [],
Expand All @@ -145,7 +165,7 @@
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 9,
"id": "d28a52e5",
"metadata": {},
"outputs": [],
Expand All @@ -158,7 +178,7 @@
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 10,
"id": "a99e7197",
"metadata": {},
"outputs": [],
Expand All @@ -177,7 +197,7 @@
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 11,
"id": "1b3c2219",
"metadata": {},
"outputs": [],
Expand All @@ -197,7 +217,7 @@
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 12,
"id": "de3dbd51",
"metadata": {},
"outputs": [],
Expand All @@ -208,7 +228,7 @@
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 13,
"id": "b344f7f5",
"metadata": {},
"outputs": [],
Expand All @@ -218,15 +238,26 @@
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 14,
"id": "b1920755",
"metadata": {},
"outputs": [],
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"average loss: 0.19355556\n",
"average bias: 0.02222222\n",
"average variance: 0.19177778\n",
"net variance: 0.17133333\n"
]
}
],
"source": [
"# Use wrapped estimator\n",
"avg_loss, avg_bias, avg_var, net_var = bias_variance_compute(model_pytorch_wrapped, X_train_torch, y_train_torch, X_test_torch, y_test, \n",
" iterations=10, random_state=random_state, decomp_fn=bias_variance_0_1_loss, \n",
" fit_kwargs={'epochs': 50})\n",
" iterations=200, random_state=random_state, decomp_fn=bias_variance_0_1_loss, \n",
" fit_kwargs={'epochs': 25})\n",
"\n",
"print(f'average loss: {avg_loss:10.8f}')\n",
"print(f'average bias: {avg_bias:10.8f}')\n",
Expand All @@ -244,7 +275,7 @@
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 15,
"id": "3f210cef",
"metadata": {},
"outputs": [],
Expand All @@ -257,7 +288,7 @@
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 16,
"id": "8352fe98",
"metadata": {},
"outputs": [],
Expand All @@ -271,7 +302,7 @@
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 17,
"id": "d6b94ef3",
"metadata": {},
"outputs": [],
Expand All @@ -291,7 +322,7 @@
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 18,
"id": "867bf004",
"metadata": {},
"outputs": [],
Expand All @@ -301,15 +332,26 @@
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 19,
"id": "b2a01764",
"metadata": {},
"outputs": [],
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"average loss: 0.18800000\n",
"average bias: 0.17777778\n",
"average variance: 0.08988889\n",
"net variance: 0.01022222\n"
]
}
],
"source": [
"# Use wrapped estimator\n",
"avg_loss, avg_bias, avg_var, net_var = bias_variance_compute(model_tensorflow_wrapped, X_train, y_train, X_test, y_test, iterations=10, \n",
"avg_loss, avg_bias, avg_var, net_var = bias_variance_compute(model_tensorflow_wrapped, X_train, y_train, X_test, y_test, iterations=200, \n",
" random_state=random_state, decomp_fn=bias_variance_0_1_loss, \n",
" fit_kwargs={'epochs': 100, 'batch_size': 50, 'verbose': False}, \n",
" fit_kwargs={'epochs': 25, 'batch_size': 50, 'verbose': False}, \n",
" predict_kwargs={'verbose': False})\n",
"\n",
"print(f'average loss: {avg_loss:10.8f}')\n",
Expand All @@ -328,17 +370,28 @@
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 21,
"id": "5900e939",
"metadata": {},
"outputs": [],
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"average loss: 0.18133333\n",
"average bias: 0.11111111\n",
"average variance: 0.13000000\n",
"net variance: 0.07022222\n"
]
}
],
"source": [
"from mvtk.bias_variance import bias_variance_compute_parallel\n",
"\n",
"avg_loss, avg_bias, avg_var, net_var = bias_variance_compute_parallel(model_tensorflow_wrapped, X_train, y_train, X_test, y_test, \n",
" iterations=10, random_state=random_state, \n",
" iterations=200, random_state=random_state, \n",
" decomp_fn=bias_variance_0_1_loss, \n",
" fit_kwargs={'epochs': 100, 'batch_size': 50, 'verbose': False}, \n",
" fit_kwargs={'epochs': 25, 'batch_size': 50, 'verbose': False}, \n",
" predict_kwargs={'verbose': False})\n",
"\n",
"print(f'average loss: {avg_loss:10.8f}')\n",
Expand Down Expand Up @@ -372,7 +425,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.10.11"
"version": "3.10.13"
}
},
"nbformat": 4,
Expand Down
Loading

0 comments on commit bb74639

Please sign in to comment.