Fix bootstrap (#80)

* update README.md for v2.2.3

* fixing issue for dataframes with duplicates in the index

* bump labs version to v2.2.4 in README

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

---------

Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
Jonathan TaylorandClaude Opus 5.5 authored and GitHub committed 2026-10-08 10:27:26 -07:00
1 parent 4854ffe66a
commit 452410232a
2 files changed
+33 -197

No files matched your search

+25 -189
View File
@@ -32,12 +32,6 @@
"execution_count": 1,
"id": "f1deb5cc",
"metadata": {
"execution": {
"iopub.execute_input": "2026-02-05T00:47:05.730449Z",
"iopub.status.busy": "2026-02-05T00:47:05.730329Z",
"iopub.status.idle": "2026-02-05T00:47:06.513542Z",
"shell.execute_reply": "2026-02-05T00:47:06.513033Z"
},
"lines_to_next_cell": 2
},
"outputs": [],
@@ -64,12 +58,6 @@
"execution_count": 2,
"id": "268c41b3",
"metadata": {
"execution": {
"iopub.execute_input": "2026-02-05T00:47:06.515215Z",
"iopub.status.busy": "2026-02-05T00:47:06.515043Z",
"iopub.status.idle": "2026-02-05T00:47:06.517293Z",
"shell.execute_reply": "2026-02-05T00:47:06.516837Z"
},
"lines_to_next_cell": 2
},
"outputs": [],
@@ -107,14 +95,7 @@
"cell_type": "code",
"execution_count": 3,
"id": "22f44ae0",
"metadata": {
"execution": {
"iopub.execute_input": "2026-02-05T00:47:06.518601Z",
"iopub.status.busy": "2026-02-05T00:47:06.518485Z",
"iopub.status.idle": "2026-02-05T00:47:06.524299Z",
"shell.execute_reply": "2026-02-05T00:47:06.523724Z"
}
},
"metadata": {},
"outputs": [],
"source": [
"Auto = load_data('Auto')\n",
@@ -135,14 +116,7 @@
"cell_type": "code",
"execution_count": 4,
"id": "0c32e917",
"metadata": {
"execution": {
"iopub.execute_input": "2026-02-05T00:47:06.525648Z",
"iopub.status.busy": "2026-02-05T00:47:06.525549Z",
"iopub.status.idle": "2026-02-05T00:47:06.531033Z",
"shell.execute_reply": "2026-02-05T00:47:06.530633Z"
}
},
"metadata": {},
"outputs": [],
"source": [
"hp_mm = MS(['horsepower'])\n",
@@ -165,14 +139,7 @@
"cell_type": "code",
"execution_count": 5,
"id": "86ce4f85",
"metadata": {
"execution": {
"iopub.execute_input": "2026-02-05T00:47:06.532517Z",
"iopub.status.busy": "2026-02-05T00:47:06.532422Z",
"iopub.status.idle": "2026-02-05T00:47:06.537369Z",
"shell.execute_reply": "2026-02-05T00:47:06.536814Z"
}
},
"metadata": {},
"outputs": [
{
"data": {
@@ -209,14 +176,7 @@
"cell_type": "code",
"execution_count": 6,
"id": "50a66a97",
"metadata": {
"execution": {
"iopub.execute_input": "2026-02-05T00:47:06.538690Z",
"iopub.status.busy": "2026-02-05T00:47:06.538577Z",
"iopub.status.idle": "2026-02-05T00:47:06.540965Z",
"shell.execute_reply": "2026-02-05T00:47:06.540491Z"
}
},
"metadata": {},
"outputs": [],
"source": [
"def evalMSE(terms,\n",
@@ -252,14 +212,7 @@
"cell_type": "code",
"execution_count": 7,
"id": "d49b6999",
"metadata": {
"execution": {
"iopub.execute_input": "2026-02-05T00:47:06.542270Z",
"iopub.status.busy": "2026-02-05T00:47:06.542165Z",
"iopub.status.idle": "2026-02-05T00:47:06.560011Z",
"shell.execute_reply": "2026-02-05T00:47:06.559510Z"
}
},
"metadata": {},
"outputs": [
{
"data": {
@@ -296,14 +249,7 @@
"cell_type": "code",
"execution_count": 8,
"id": "dac8bd54",
"metadata": {
"execution": {
"iopub.execute_input": "2026-02-05T00:47:06.561313Z",
"iopub.status.busy": "2026-02-05T00:47:06.561212Z",
"iopub.status.idle": "2026-02-05T00:47:06.579372Z",
"shell.execute_reply": "2026-02-05T00:47:06.578863Z"
}
},
"metadata": {},
"outputs": [
{
"data": {
@@ -380,12 +326,6 @@
"execution_count": 9,
"id": "601ae443",
"metadata": {
"execution": {
"iopub.execute_input": "2026-02-05T00:47:06.580908Z",
"iopub.status.busy": "2026-02-05T00:47:06.580793Z",
"iopub.status.idle": "2026-02-05T00:47:07.783382Z",
"shell.execute_reply": "2026-02-05T00:47:07.782912Z"
},
"lines_to_next_cell": 0
},
"outputs": [
@@ -448,19 +388,13 @@
"execution_count": 10,
"id": "11226c85",
"metadata": {
"execution": {
"iopub.execute_input": "2026-02-05T00:47:07.785034Z",
"iopub.status.busy": "2026-02-05T00:47:07.784918Z",
"iopub.status.idle": "2026-02-05T00:47:08.636881Z",
"shell.execute_reply": "2026-02-05T00:47:08.636274Z"
},
"lines_to_next_cell": 0
},
"outputs": [
{
"data": {
"text/plain": [
"array([24.23151352, 19.24821312, 19.33498406, 19.4244303 , 19.03321527])"
"array([24.23151352, 19.24821312, 19.33498406, 19.42443031, 19.03321669])"
]
},
"execution_count": 10,
@@ -504,14 +438,7 @@
"cell_type": "code",
"execution_count": 11,
"id": "64b64d97",
"metadata": {
"execution": {
"iopub.execute_input": "2026-02-05T00:47:08.638904Z",
"iopub.status.busy": "2026-02-05T00:47:08.638760Z",
"iopub.status.idle": "2026-02-05T00:47:08.641760Z",
"shell.execute_reply": "2026-02-05T00:47:08.641094Z"
}
},
"metadata": {},
"outputs": [
{
"data": {
@@ -547,19 +474,13 @@
"execution_count": 12,
"id": "ca0f972f",
"metadata": {
"execution": {
"iopub.execute_input": "2026-02-05T00:47:08.643305Z",
"iopub.status.busy": "2026-02-05T00:47:08.643162Z",
"iopub.status.idle": "2026-02-05T00:47:08.675141Z",
"shell.execute_reply": "2026-02-05T00:47:08.674740Z"
},
"lines_to_next_cell": 0
},
"outputs": [
{
"data": {
"text/plain": [
"array([24.20766449, 19.18533142, 19.27626666, 19.47848402, 19.13718373])"
"array([24.20766449, 19.18533142, 19.27626666, 19.47848402, 19.13718162])"
]
},
"execution_count": 12,
@@ -613,12 +534,6 @@
"execution_count": 13,
"id": "080cdb29",
"metadata": {
"execution": {
"iopub.execute_input": "2026-02-05T00:47:08.677151Z",
"iopub.status.busy": "2026-02-05T00:47:08.676983Z",
"iopub.status.idle": "2026-02-05T00:47:08.685777Z",
"shell.execute_reply": "2026-02-05T00:47:08.685174Z"
},
"lines_to_next_cell": 2
},
"outputs": [
@@ -656,19 +571,12 @@
"cell_type": "code",
"execution_count": 14,
"id": "7c46de2b",
"metadata": {
"execution": {
"iopub.execute_input": "2026-02-05T00:47:08.687387Z",
"iopub.status.busy": "2026-02-05T00:47:08.687268Z",
"iopub.status.idle": "2026-02-05T00:47:08.726376Z",
"shell.execute_reply": "2026-02-05T00:47:08.725862Z"
}
},
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"(np.float64(23.802232661034168), np.float64(1.4218450941091916))"
"(np.float64(23.80223266103417), np.float64(1.4218450941091905))"
]
},
"execution_count": 14,
@@ -731,12 +639,6 @@
"execution_count": 15,
"id": "a4b6d9b3",
"metadata": {
"execution": {
"iopub.execute_input": "2026-02-05T00:47:08.727991Z",
"iopub.status.busy": "2026-02-05T00:47:08.727860Z",
"iopub.status.idle": "2026-02-05T00:47:08.731089Z",
"shell.execute_reply": "2026-02-05T00:47:08.730582Z"
},
"lines_to_next_cell": 0
},
"outputs": [],
@@ -764,14 +666,7 @@
"cell_type": "code",
"execution_count": 16,
"id": "81498a11",
"metadata": {
"execution": {
"iopub.execute_input": "2026-02-05T00:47:08.732467Z",
"iopub.status.busy": "2026-02-05T00:47:08.732368Z",
"iopub.status.idle": "2026-02-05T00:47:08.735439Z",
"shell.execute_reply": "2026-02-05T00:47:08.734958Z"
}
},
"metadata": {},
"outputs": [
{
"data": {
@@ -804,12 +699,6 @@
"execution_count": 17,
"id": "64fe1cb6",
"metadata": {
"execution": {
"iopub.execute_input": "2026-02-05T00:47:08.736816Z",
"iopub.status.busy": "2026-02-05T00:47:08.736715Z",
"iopub.status.idle": "2026-02-05T00:47:08.739777Z",
"shell.execute_reply": "2026-02-05T00:47:08.739384Z"
},
"lines_to_next_cell": 2
},
"outputs": [
@@ -839,7 +728,9 @@
"source": [
"This process can be generalized to create a simple function `boot_SE()` for\n",
"computing the bootstrap standard error for arbitrary\n",
"functions that take only a data frame as an argument."
"functions that take only a data frame as an argument. We will assume the the `.index` is not used in\n",
"within `func` besides to index rows, thus we can replace the index with integers. This will avoid\n",
"issues that arises when an index has duplicate values."
]
},
{
@@ -847,12 +738,6 @@
"execution_count": 18,
"id": "dd16bbae",
"metadata": {
"execution": {
"iopub.execute_input": "2026-02-05T00:47:08.741328Z",
"iopub.status.busy": "2026-02-05T00:47:08.741207Z",
"iopub.status.idle": "2026-02-05T00:47:08.743628Z",
"shell.execute_reply": "2026-02-05T00:47:08.743222Z"
},
"lines_to_next_cell": 0
},
"outputs": [],
@@ -865,11 +750,12 @@
" rng = np.random.default_rng(seed)\n",
" first_, second_ = 0, 0\n",
" n = n or D.shape[0]\n",
" D_int = D.reset_index(drop=True)\n",
" for _ in range(B):\n",
" idx = rng.choice(D.index,\n",
" idx = rng.choice(n,\n",
" n,\n",
" replace=True)\n",
" value = func(D, idx)\n",
" value = func(D_int, idx)\n",
" first_ += value\n",
" second_ += value**2\n",
" return np.sqrt(second_ / B - (first_ / B)**2)"
@@ -891,14 +777,7 @@
"cell_type": "code",
"execution_count": 19,
"id": "b42b4585",
"metadata": {
"execution": {
"iopub.execute_input": "2026-02-05T00:47:08.744970Z",
"iopub.status.busy": "2026-02-05T00:47:08.744866Z",
"iopub.status.idle": "2026-02-05T00:47:09.034568Z",
"shell.execute_reply": "2026-02-05T00:47:09.034067Z"
}
},
"metadata": {},
"outputs": [
{
"data": {
@@ -958,12 +837,6 @@
"execution_count": 20,
"id": "6bc11784",
"metadata": {
"execution": {
"iopub.execute_input": "2026-02-05T00:47:09.036186Z",
"iopub.status.busy": "2026-02-05T00:47:09.036064Z",
"iopub.status.idle": "2026-02-05T00:47:09.038120Z",
"shell.execute_reply": "2026-02-05T00:47:09.037695Z"
},
"lines_to_next_cell": 0
},
"outputs": [],
@@ -993,12 +866,6 @@
"execution_count": 21,
"id": "740cd50c",
"metadata": {
"execution": {
"iopub.execute_input": "2026-02-05T00:47:09.039473Z",
"iopub.status.busy": "2026-02-05T00:47:09.039363Z",
"iopub.status.idle": "2026-02-05T00:47:09.041198Z",
"shell.execute_reply": "2026-02-05T00:47:09.040802Z"
},
"lines_to_next_cell": 0
},
"outputs": [],
@@ -1026,12 +893,6 @@
"execution_count": 22,
"id": "ffb3ec50",
"metadata": {
"execution": {
"iopub.execute_input": "2026-02-05T00:47:09.042630Z",
"iopub.status.busy": "2026-02-05T00:47:09.042520Z",
"iopub.status.idle": "2026-02-05T00:47:09.074556Z",
"shell.execute_reply": "2026-02-05T00:47:09.074079Z"
},
"lines_to_next_cell": 0
},
"outputs": [
@@ -1077,20 +938,14 @@
"execution_count": 23,
"id": "7d561f70",
"metadata": {
"execution": {
"iopub.execute_input": "2026-02-05T00:47:09.076044Z",
"iopub.status.busy": "2026-02-05T00:47:09.075921Z",
"iopub.status.idle": "2026-02-05T00:47:11.975218Z",
"shell.execute_reply": "2026-02-05T00:47:11.974653Z"
},
"lines_to_next_cell": 2
},
"outputs": [
{
"data": {
"text/plain": [
"intercept 0.731176\n",
"horsepower 0.006092\n",
"intercept 0.848807\n",
"horsepower 0.007352\n",
"dtype: float64"
]
},
@@ -1127,12 +982,6 @@
"execution_count": 24,
"id": "3888aa0a",
"metadata": {
"execution": {
"iopub.execute_input": "2026-02-05T00:47:11.976651Z",
"iopub.status.busy": "2026-02-05T00:47:11.976530Z",
"iopub.status.idle": "2026-02-05T00:47:11.995335Z",
"shell.execute_reply": "2026-02-05T00:47:11.994822Z"
},
"lines_to_next_cell": 2
},
"outputs": [
@@ -1198,21 +1047,14 @@
"cell_type": "code",
"execution_count": 25,
"id": "acc3e32c",
"metadata": {
"execution": {
"iopub.execute_input": "2026-02-05T00:47:11.996827Z",
"iopub.status.busy": "2026-02-05T00:47:11.996698Z",
"iopub.status.idle": "2026-02-05T00:47:16.184970Z",
"shell.execute_reply": "2026-02-05T00:47:16.184301Z"
}
},
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"intercept 1.538641\n",
"poly(horsepower, degree=2, raw=True)[0] 0.024696\n",
"poly(horsepower, degree=2, raw=True)[1] 0.000090\n",
"intercept 2.067840\n",
"poly(horsepower, degree=2, raw=True)[0] 0.033019\n",
"poly(horsepower, degree=2, raw=True)[1] 0.000120\n",
"dtype: float64"
]
},
@@ -1242,12 +1084,6 @@
"execution_count": 26,
"id": "dca5340c",
"metadata": {
"execution": {
"iopub.execute_input": "2026-02-05T00:47:16.186711Z",
"iopub.status.busy": "2026-02-05T00:47:16.186585Z",
"iopub.status.idle": "2026-02-05T00:47:16.197450Z",
"shell.execute_reply": "2026-02-05T00:47:16.197112Z"
},
"lines_to_next_cell": 0
},
"outputs": [
+8 -8
View File
@@ -34,7 +34,7 @@ intent is that building a virtual environment with
To install the current version of the requirements run
```
uv pip install -r https://raw.githubusercontent.com/intro-stat-learning/ISLP_labs/v2.2.2/requirements.txt;
uv pip install -r https://raw.githubusercontent.com/intro-stat-learning/ISLP_labs/v2.2.4/requirements.txt;
```
The labs can now be run via:
@@ -46,7 +46,7 @@ uv run jupyter lab Ch02-statlearn-lab.ipynb
# Zip / tarball
You can download all the labs as a `.zip` or `.tar.gz` [here](https://github.com/intro-stat-learning/ISLP_labs/releases/tag/v2.2.2)
You can download all the labs as a `.zip` or `.tar.gz` [here](https://github.com/intro-stat-learning/ISLP_labs/releases/tag/v2.2.4)
# Setup script
@@ -87,16 +87,16 @@ curl -LO https://raw.githubusercontent.com/intro-stat-learning/ISLP_labs/main/se
### 2. Run the setup script
Open your terminal and run the following command to set up the environment for version `v2.2.2` of the labs with Python `3.12`.
Open your terminal and run the following command to set up the environment for version `v2.2.4` of the labs with Python `3.12`.
```
uv run python setup_notebook_env.py --outdir ISLP_v2.2.2 --commit v2.2.2 --python-version 3.12
uv run python setup_notebook_env.py --outdir ISLP --commit v2.2.4 --python-version 3.12
```
You can also specify one or more notebooks to run automatically after setup.
* `--outdir ISLP_v2.2.2`: This will create a directory named `ISLP_v2.2.2` for your labs.
* `--commit v2.2.2`: This specifies that you want to use version `v2.2.2` of the labs.
* `--outdir ISLP`: This will create a directory named `ISLP` for your labs.
* `--commit v2.2.4`: This specifies that you want to use version `v2.2.4` of the labs.
* `--python-version 3.12`: This will use Python 3.12 for the environment.
* `Ch02-statlearn-lab.ipynb`: This is an optional argument to run a specific notebook after the setup is complete. It is meant for testing to be sure given notebooks run but is not required. You can list more than one notebook.
@@ -106,12 +106,12 @@ Once the script is finished, you can activate the virtual environment to run oth
* **On macOS and Linux:**
```bash
source ISLP_v2.2.2/.venv/bin/activate
source ISLP/.venv/bin/activate
```
* **On Windows:**
```bash
ISLP_v2.2.2\.venv\Scripts\activate
ISLP\.venv\Scripts\activate
```
### 4. Run other notebooks