first edit to v2

This commit is contained in:
Jonathan Taylor committed 2023-07-26 15:37:40 -04:00
1 parent 58b88498ea
commit 447faa9820
14 files changed
+7001 -12769

No files matched your search

+854 -6065
View File
File diff suppressed because it is too large. Load diff
+193 -210
View File
@@ -5,9 +5,7 @@
"id": "c7f4eb5a",
"metadata": {},
"source": [
"\n",
"# Chapter 11\n",
"\n"
"# Chapter 11"
]
},
{
@@ -34,10 +32,10 @@
"id": "91ac40fd",
"metadata": {
"execution": {
"iopub.execute_input": "2023-07-26T05:18:03.064349Z",
"iopub.status.busy": "2023-07-26T05:18:03.064029Z",
"iopub.status.idle": "2023-07-26T05:18:04.312445Z",
"shell.execute_reply": "2023-07-26T05:18:04.312016Z"
"iopub.execute_input": "2023-07-26T19:30:26.003002Z",
"iopub.status.busy": "2023-07-26T19:30:26.002908Z",
"iopub.status.idle": "2023-07-26T19:30:27.205801Z",
"shell.execute_reply": "2023-07-26T19:30:27.205421Z"
}
},
"outputs": [],
@@ -46,7 +44,7 @@
"import numpy as np\n",
"import pandas as pd\n",
"from ISLP.models import ModelSpec as MS\n",
"from ISLP import load_data\n"
"from ISLP import load_data"
]
},
{
@@ -64,10 +62,10 @@
"id": "99782418",
"metadata": {
"execution": {
"iopub.execute_input": "2023-07-26T05:18:04.315115Z",
"iopub.status.busy": "2023-07-26T05:18:04.314859Z",
"iopub.status.idle": "2023-07-26T05:18:04.379768Z",
"shell.execute_reply": "2023-07-26T05:18:04.379303Z"
"iopub.execute_input": "2023-07-26T19:30:27.207779Z",
"iopub.status.busy": "2023-07-26T19:30:27.207612Z",
"iopub.status.idle": "2023-07-26T19:30:27.296296Z",
"shell.execute_reply": "2023-07-26T19:30:27.295956Z"
}
},
"outputs": [],
@@ -78,7 +76,7 @@
"from lifelines.statistics import \\\n",
" (logrank_test,\n",
" multivariate_logrank_test)\n",
"from ISLP.survival import sim_time\n"
"from ISLP.survival import sim_time"
]
},
{
@@ -97,10 +95,10 @@
"id": "3137149a",
"metadata": {
"execution": {
"iopub.execute_input": "2023-07-26T05:18:04.382594Z",
"iopub.status.busy": "2023-07-26T05:18:04.382386Z",
"iopub.status.idle": "2023-07-26T05:18:04.389761Z",
"shell.execute_reply": "2023-07-26T05:18:04.389375Z"
"iopub.execute_input": "2023-07-26T19:30:27.298114Z",
"iopub.status.busy": "2023-07-26T19:30:27.297992Z",
"iopub.status.idle": "2023-07-26T19:30:27.304678Z",
"shell.execute_reply": "2023-07-26T19:30:27.304388Z"
}
},
"outputs": [
@@ -117,7 +115,7 @@
],
"source": [
"BrainCancer = load_data('BrainCancer')\n",
"BrainCancer.columns\n"
"BrainCancer.columns"
]
},
{
@@ -135,12 +133,11 @@
"id": "45963c92",
"metadata": {
"execution": {
"iopub.execute_input": "2023-07-26T05:18:04.392289Z",
"iopub.status.busy": "2023-07-26T05:18:04.392117Z",
"iopub.status.idle": "2023-07-26T05:18:04.396285Z",
"shell.execute_reply": "2023-07-26T05:18:04.395840Z"
},
"lines_to_next_cell": 2
"iopub.execute_input": "2023-07-26T19:30:27.306221Z",
"iopub.status.busy": "2023-07-26T19:30:27.306076Z",
"iopub.status.idle": "2023-07-26T19:30:27.309094Z",
"shell.execute_reply": "2023-07-26T19:30:27.308833Z"
}
},
"outputs": [
{
@@ -157,7 +154,7 @@
}
],
"source": [
"BrainCancer['sex'].value_counts()\n"
"BrainCancer['sex'].value_counts()"
]
},
{
@@ -166,12 +163,11 @@
"id": "73be61f6",
"metadata": {
"execution": {
"iopub.execute_input": "2023-07-26T05:18:04.400201Z",
"iopub.status.busy": "2023-07-26T05:18:04.399975Z",
"iopub.status.idle": "2023-07-26T05:18:04.403967Z",
"shell.execute_reply": "2023-07-26T05:18:04.403581Z"
},
"lines_to_next_cell": 2
"iopub.execute_input": "2023-07-26T19:30:27.310531Z",
"iopub.status.busy": "2023-07-26T19:30:27.310431Z",
"iopub.status.idle": "2023-07-26T19:30:27.313426Z",
"shell.execute_reply": "2023-07-26T19:30:27.313121Z"
}
},
"outputs": [
{
@@ -190,7 +186,7 @@
}
],
"source": [
"BrainCancer['diagnosis'].value_counts()\n"
"BrainCancer['diagnosis'].value_counts()"
]
},
{
@@ -199,12 +195,11 @@
"id": "572f0b9e",
"metadata": {
"execution": {
"iopub.execute_input": "2023-07-26T05:18:04.406232Z",
"iopub.status.busy": "2023-07-26T05:18:04.406110Z",
"iopub.status.idle": "2023-07-26T05:18:04.409773Z",
"shell.execute_reply": "2023-07-26T05:18:04.409374Z"
},
"lines_to_next_cell": 2
"iopub.execute_input": "2023-07-26T19:30:27.314866Z",
"iopub.status.busy": "2023-07-26T19:30:27.314779Z",
"iopub.status.idle": "2023-07-26T19:30:27.317867Z",
"shell.execute_reply": "2023-07-26T19:30:27.317610Z"
}
},
"outputs": [
{
@@ -221,7 +216,7 @@
}
],
"source": [
"BrainCancer['status'].value_counts()\n"
"BrainCancer['status'].value_counts()"
]
},
{
@@ -255,10 +250,10 @@
"id": "92c39707",
"metadata": {
"execution": {
"iopub.execute_input": "2023-07-26T05:18:04.411840Z",
"iopub.status.busy": "2023-07-26T05:18:04.411663Z",
"iopub.status.idle": "2023-07-26T05:18:04.539774Z",
"shell.execute_reply": "2023-07-26T05:18:04.539439Z"
"iopub.execute_input": "2023-07-26T19:30:27.319267Z",
"iopub.status.busy": "2023-07-26T19:30:27.319172Z",
"iopub.status.idle": "2023-07-26T19:30:27.501692Z",
"shell.execute_reply": "2023-07-26T19:30:27.500343Z"
}
},
"outputs": [
@@ -287,7 +282,7 @@
"fig, ax = subplots(figsize=(8,8))\n",
"km = KaplanMeierFitter()\n",
"km_brain = km.fit(BrainCancer['time'], BrainCancer['status'])\n",
"km_brain.plot(label='Kaplan Meier estimate', ax=ax)\n"
"km_brain.plot(label='Kaplan Meier estimate', ax=ax)"
]
},
{
@@ -321,10 +316,10 @@
"id": "3fc7848c",
"metadata": {
"execution": {
"iopub.execute_input": "2023-07-26T05:18:04.542265Z",
"iopub.status.busy": "2023-07-26T05:18:04.542002Z",
"iopub.status.idle": "2023-07-26T05:18:04.674613Z",
"shell.execute_reply": "2023-07-26T05:18:04.674126Z"
"iopub.execute_input": "2023-07-26T19:30:27.507068Z",
"iopub.status.busy": "2023-07-26T19:30:27.506706Z",
"iopub.status.idle": "2023-07-26T19:30:27.653319Z",
"shell.execute_reply": "2023-07-26T19:30:27.653011Z"
}
},
"outputs": [
@@ -345,7 +340,7 @@
"for sex, df in BrainCancer.groupby('sex'):\n",
" by_sex[sex] = df\n",
" km_sex = km.fit(df['time'], df['status'])\n",
" km_sex.plot(label='Sex=%s' % sex, ax=ax)\n"
" km_sex.plot(label='Sex=%s' % sex, ax=ax)"
]
},
{
@@ -366,12 +361,11 @@
"id": "bf30d26f",
"metadata": {
"execution": {
"iopub.execute_input": "2023-07-26T05:18:04.679625Z",
"iopub.status.busy": "2023-07-26T05:18:04.679410Z",
"iopub.status.idle": "2023-07-26T05:18:04.743501Z",
"shell.execute_reply": "2023-07-26T05:18:04.743166Z"
},
"lines_to_next_cell": 2
"iopub.execute_input": "2023-07-26T19:30:27.654929Z",
"iopub.status.busy": "2023-07-26T19:30:27.654810Z",
"iopub.status.idle": "2023-07-26T19:30:27.710525Z",
"shell.execute_reply": "2023-07-26T19:30:27.710247Z"
}
},
"outputs": [
{
@@ -457,7 +451,7 @@
"logrank_test(by_sex['Male']['time'],\n",
" by_sex['Female']['time'],\n",
" by_sex['Male']['status'],\n",
" by_sex['Female']['status'])\n"
" by_sex['Female']['status'])"
]
},
{
@@ -479,10 +473,10 @@
"id": "2ab78e07",
"metadata": {
"execution": {
"iopub.execute_input": "2023-07-26T05:18:04.746088Z",
"iopub.status.busy": "2023-07-26T05:18:04.745814Z",
"iopub.status.idle": "2023-07-26T05:18:04.773972Z",
"shell.execute_reply": "2023-07-26T05:18:04.773498Z"
"iopub.execute_input": "2023-07-26T19:30:27.712399Z",
"iopub.status.busy": "2023-07-26T19:30:27.712248Z",
"iopub.status.idle": "2023-07-26T19:30:27.738130Z",
"shell.execute_reply": "2023-07-26T19:30:27.737857Z"
}
},
"outputs": [
@@ -548,7 +542,7 @@
"cox_fit = coxph().fit(model_df,\n",
" 'time',\n",
" 'status')\n",
"cox_fit.summary[['coef', 'se(coef)', 'p']]\n"
"cox_fit.summary[['coef', 'se(coef)', 'p']]"
]
},
{
@@ -572,10 +566,10 @@
"id": "4716b7b0",
"metadata": {
"execution": {
"iopub.execute_input": "2023-07-26T05:18:04.776775Z",
"iopub.status.busy": "2023-07-26T05:18:04.776463Z",
"iopub.status.idle": "2023-07-26T05:18:04.783362Z",
"shell.execute_reply": "2023-07-26T05:18:04.782865Z"
"iopub.execute_input": "2023-07-26T19:30:27.739771Z",
"iopub.status.busy": "2023-07-26T19:30:27.739667Z",
"iopub.status.idle": "2023-07-26T19:30:27.745096Z",
"shell.execute_reply": "2023-07-26T19:30:27.744797Z"
}
},
"outputs": [
@@ -654,7 +648,7 @@
}
],
"source": [
"cox_fit.log_likelihood_ratio_test()\n"
"cox_fit.log_likelihood_ratio_test()"
]
},
{
@@ -678,10 +672,10 @@
"id": "c2767d88",
"metadata": {
"execution": {
"iopub.execute_input": "2023-07-26T05:18:04.785790Z",
"iopub.status.busy": "2023-07-26T05:18:04.785586Z",
"iopub.status.idle": "2023-07-26T05:18:04.824235Z",
"shell.execute_reply": "2023-07-26T05:18:04.823739Z"
"iopub.execute_input": "2023-07-26T19:30:27.746715Z",
"iopub.status.busy": "2023-07-26T19:30:27.746605Z",
"iopub.status.idle": "2023-07-26T19:30:27.777796Z",
"shell.execute_reply": "2023-07-26T19:30:27.777514Z"
}
},
"outputs": [
@@ -795,7 +789,7 @@
"fit_all = coxph().fit(all_df,\n",
" 'time',\n",
" 'status')\n",
"fit_all.summary[['coef', 'se(coef)', 'p']]\n"
"fit_all.summary[['coef', 'se(coef)', 'p']]"
]
},
{
@@ -826,10 +820,10 @@
"id": "ede1d219",
"metadata": {
"execution": {
"iopub.execute_input": "2023-07-26T05:18:04.826852Z",
"iopub.status.busy": "2023-07-26T05:18:04.826662Z",
"iopub.status.idle": "2023-07-26T05:18:04.831013Z",
"shell.execute_reply": "2023-07-26T05:18:04.830464Z"
"iopub.execute_input": "2023-07-26T19:30:27.779481Z",
"iopub.status.busy": "2023-07-26T19:30:27.779362Z",
"iopub.status.idle": "2023-07-26T19:30:27.783153Z",
"shell.execute_reply": "2023-07-26T19:30:27.782873Z"
}
},
"outputs": [],
@@ -840,7 +834,7 @@
" return pd.Series.mode(series)\n",
" else:\n",
" return series.mean()\n",
"modal_data = cleaned.apply(representative, axis=0)\n"
"modal_data = cleaned.apply(representative, axis=0)"
]
},
{
@@ -859,10 +853,10 @@
"id": "dc032a71",
"metadata": {
"execution": {
"iopub.execute_input": "2023-07-26T05:18:04.833522Z",
"iopub.status.busy": "2023-07-26T05:18:04.833389Z",
"iopub.status.idle": "2023-07-26T05:18:04.840549Z",
"shell.execute_reply": "2023-07-26T05:18:04.840260Z"
"iopub.execute_input": "2023-07-26T19:30:27.784638Z",
"iopub.status.busy": "2023-07-26T19:30:27.784539Z",
"iopub.status.idle": "2023-07-26T19:30:27.790155Z",
"shell.execute_reply": "2023-07-26T19:30:27.789921Z"
}
},
"outputs": [
@@ -969,7 +963,7 @@
"modal_df = pd.DataFrame(\n",
" [modal_data.iloc[0] for _ in range(len(levels))])\n",
"modal_df['diagnosis'] = levels\n",
"modal_df\n"
"modal_df"
]
},
{
@@ -987,10 +981,10 @@
"id": "e7c1fe43",
"metadata": {
"execution": {
"iopub.execute_input": "2023-07-26T05:18:04.843157Z",
"iopub.status.busy": "2023-07-26T05:18:04.843004Z",
"iopub.status.idle": "2023-07-26T05:18:04.852876Z",
"shell.execute_reply": "2023-07-26T05:18:04.852545Z"
"iopub.execute_input": "2023-07-26T19:30:27.791678Z",
"iopub.status.busy": "2023-07-26T19:30:27.791583Z",
"iopub.status.idle": "2023-07-26T19:30:27.798851Z",
"shell.execute_reply": "2023-07-26T19:30:27.798573Z"
}
},
"outputs": [
@@ -1112,7 +1106,7 @@
"source": [
"modal_X = all_MS.transform(modal_df)\n",
"modal_X.index = levels\n",
"modal_X\n"
"modal_X"
]
},
{
@@ -1129,12 +1123,11 @@
"id": "f89fbed7",
"metadata": {
"execution": {
"iopub.execute_input": "2023-07-26T05:18:04.855400Z",
"iopub.status.busy": "2023-07-26T05:18:04.855197Z",
"iopub.status.idle": "2023-07-26T05:18:04.864584Z",
"shell.execute_reply": "2023-07-26T05:18:04.864194Z"
},
"lines_to_next_cell": 0
"iopub.execute_input": "2023-07-26T19:30:27.800416Z",
"iopub.status.busy": "2023-07-26T19:30:27.800308Z",
"iopub.status.idle": "2023-07-26T19:30:27.806596Z",
"shell.execute_reply": "2023-07-26T19:30:27.806285Z"
}
},
"outputs": [
{
@@ -1271,7 +1264,7 @@
],
"source": [
"predicted_survival = fit_all.predict_survival_function(modal_X)\n",
"predicted_survival\n"
"predicted_survival"
]
},
{
@@ -1290,12 +1283,11 @@
"id": "8f0329b4",
"metadata": {
"execution": {
"iopub.execute_input": "2023-07-26T05:18:04.867553Z",
"iopub.status.busy": "2023-07-26T05:18:04.867105Z",
"iopub.status.idle": "2023-07-26T05:18:04.987503Z",
"shell.execute_reply": "2023-07-26T05:18:04.986681Z"
},
"lines_to_next_cell": 2
"iopub.execute_input": "2023-07-26T19:30:27.808158Z",
"iopub.status.busy": "2023-07-26T19:30:27.808049Z",
"iopub.status.idle": "2023-07-26T19:30:27.914231Z",
"shell.execute_reply": "2023-07-26T19:30:27.913906Z"
}
},
"outputs": [
{
@@ -1311,7 +1303,7 @@
],
"source": [
"fig, ax = subplots(figsize=(8, 8))\n",
"predicted_survival.plot(ax=ax);\n"
"predicted_survival.plot(ax=ax);"
]
},
{
@@ -1333,10 +1325,10 @@
"id": "3045bfc0",
"metadata": {
"execution": {
"iopub.execute_input": "2023-07-26T05:18:04.990450Z",
"iopub.status.busy": "2023-07-26T05:18:04.990225Z",
"iopub.status.idle": "2023-07-26T05:18:05.181343Z",
"shell.execute_reply": "2023-07-26T05:18:05.178676Z"
"iopub.execute_input": "2023-07-26T19:30:27.915979Z",
"iopub.status.busy": "2023-07-26T19:30:27.915852Z",
"iopub.status.idle": "2023-07-26T19:30:28.029175Z",
"shell.execute_reply": "2023-07-26T19:30:28.028888Z"
}
},
"outputs": [
@@ -1358,7 +1350,7 @@
"for result, df in Publication.groupby('posres'):\n",
" by_result[result] = df\n",
" km_result = km.fit(df['time'], df['status'])\n",
" km_result.plot(label='Result=%d' % result, ax=ax)\n"
" km_result.plot(label='Result=%d' % result, ax=ax)"
]
},
{
@@ -1378,12 +1370,11 @@
"id": "d070f716",
"metadata": {
"execution": {
"iopub.execute_input": "2023-07-26T05:18:05.184743Z",
"iopub.status.busy": "2023-07-26T05:18:05.184569Z",
"iopub.status.idle": "2023-07-26T05:18:05.222538Z",
"shell.execute_reply": "2023-07-26T05:18:05.221996Z"
},
"lines_to_next_cell": 2
"iopub.execute_input": "2023-07-26T19:30:28.030858Z",
"iopub.status.busy": "2023-07-26T19:30:28.030749Z",
"iopub.status.idle": "2023-07-26T19:30:28.059324Z",
"shell.execute_reply": "2023-07-26T19:30:28.059043Z"
}
},
"outputs": [
{
@@ -1448,7 +1439,7 @@
"posres_fit = coxph().fit(posres_df,\n",
" 'time',\n",
" 'status')\n",
"posres_fit.summary[['coef', 'se(coef)', 'p']]\n"
"posres_fit.summary[['coef', 'se(coef)', 'p']]"
]
},
{
@@ -1467,10 +1458,10 @@
"id": "2bbcdd0c",
"metadata": {
"execution": {
"iopub.execute_input": "2023-07-26T05:18:05.225196Z",
"iopub.status.busy": "2023-07-26T05:18:05.224969Z",
"iopub.status.idle": "2023-07-26T05:18:05.270258Z",
"shell.execute_reply": "2023-07-26T05:18:05.269721Z"
"iopub.execute_input": "2023-07-26T19:30:28.060927Z",
"iopub.status.busy": "2023-07-26T19:30:28.060812Z",
"iopub.status.idle": "2023-07-26T19:30:28.098525Z",
"shell.execute_reply": "2023-07-26T19:30:28.098223Z"
}
},
"outputs": [
@@ -1568,7 +1559,7 @@
" intercept=False)\n",
"coxph().fit(model.fit_transform(Publication),\n",
" 'time',\n",
" 'status').summary[['coef', 'se(coef)', 'p']]\n"
" 'status').summary[['coef', 'se(coef)', 'p']]"
]
},
{
@@ -1602,7 +1593,7 @@
"`Time` of day (Morning, Afternoon, or Evening). We generate data\n",
"for these covariates so that all possibilities are equally likely: for\n",
"instance, morning, afternoon and evening calls are equally likely, and\n",
"any number of operators from $5$ to $15$ is equally likely. "
"any number of operators from $5$ to $15$ is equally likely."
]
},
{
@@ -1611,10 +1602,10 @@
"id": "b8ece43a",
"metadata": {
"execution": {
"iopub.execute_input": "2023-07-26T05:18:05.272852Z",
"iopub.status.busy": "2023-07-26T05:18:05.272613Z",
"iopub.status.idle": "2023-07-26T05:18:05.277670Z",
"shell.execute_reply": "2023-07-26T05:18:05.277169Z"
"iopub.execute_input": "2023-07-26T19:30:28.100149Z",
"iopub.status.busy": "2023-07-26T19:30:28.100033Z",
"iopub.status.idle": "2023-07-26T19:30:28.103545Z",
"shell.execute_reply": "2023-07-26T19:30:28.103271Z"
}
},
"outputs": [],
@@ -1649,10 +1640,10 @@
"id": "3e4f766f",
"metadata": {
"execution": {
"iopub.execute_input": "2023-07-26T05:18:05.279951Z",
"iopub.status.busy": "2023-07-26T05:18:05.279774Z",
"iopub.status.idle": "2023-07-26T05:18:05.289519Z",
"shell.execute_reply": "2023-07-26T05:18:05.288948Z"
"iopub.execute_input": "2023-07-26T19:30:28.105054Z",
"iopub.status.busy": "2023-07-26T19:30:28.104974Z",
"iopub.status.idle": "2023-07-26T19:30:28.112380Z",
"shell.execute_reply": "2023-07-26T19:30:28.112135Z"
}
},
"outputs": [],
@@ -1681,10 +1672,10 @@
"id": "72f42d14",
"metadata": {
"execution": {
"iopub.execute_input": "2023-07-26T05:18:05.292713Z",
"iopub.status.busy": "2023-07-26T05:18:05.292424Z",
"iopub.status.idle": "2023-07-26T05:18:05.299084Z",
"shell.execute_reply": "2023-07-26T05:18:05.298414Z"
"iopub.execute_input": "2023-07-26T19:30:28.113965Z",
"iopub.status.busy": "2023-07-26T19:30:28.113885Z",
"iopub.status.idle": "2023-07-26T19:30:28.117874Z",
"shell.execute_reply": "2023-07-26T19:30:28.117640Z"
}
},
"outputs": [
@@ -1776,7 +1767,7 @@
}
],
"source": [
"X[:5]\n"
"X[:5]"
]
},
{
@@ -1793,17 +1784,17 @@
"id": "8b921536",
"metadata": {
"execution": {
"iopub.execute_input": "2023-07-26T05:18:05.301800Z",
"iopub.status.busy": "2023-07-26T05:18:05.301580Z",
"iopub.status.idle": "2023-07-26T05:18:05.340807Z",
"shell.execute_reply": "2023-07-26T05:18:05.311843Z"
"iopub.execute_input": "2023-07-26T19:30:28.119472Z",
"iopub.status.busy": "2023-07-26T19:30:28.119352Z",
"iopub.status.idle": "2023-07-26T19:30:28.127116Z",
"shell.execute_reply": "2023-07-26T19:30:28.126300Z"
}
},
"outputs": [],
"source": [
"true_beta = np.array([0.04, -0.3, 0, 0.2, -0.2])\n",
"true_linpred = X.dot(true_beta)\n",
"hazard = lambda t: 1e-5 * t\n"
"hazard = lambda t: 1e-5 * t"
]
},
{
@@ -1840,16 +1831,15 @@
"id": "96ce0f99",
"metadata": {
"execution": {
"iopub.execute_input": "2023-07-26T05:18:05.399214Z",
"iopub.status.busy": "2023-07-26T05:18:05.386941Z",
"iopub.status.idle": "2023-07-26T05:18:05.423513Z",
"shell.execute_reply": "2023-07-26T05:18:05.417411Z"
},
"lines_to_next_cell": 0
"iopub.execute_input": "2023-07-26T19:30:28.134404Z",
"iopub.status.busy": "2023-07-26T19:30:28.134012Z",
"iopub.status.idle": "2023-07-26T19:30:28.139431Z",
"shell.execute_reply": "2023-07-26T19:30:28.137672Z"
}
},
"outputs": [],
"source": [
"cum_hazard = lambda t: 1e-5 * t**2 / 2\n"
"cum_hazard = lambda t: 1e-5 * t**2 / 2"
]
},
{
@@ -1871,17 +1861,17 @@
"id": "63d78ff9",
"metadata": {
"execution": {
"iopub.execute_input": "2023-07-26T05:18:05.450050Z",
"iopub.status.busy": "2023-07-26T05:18:05.449814Z",
"iopub.status.idle": "2023-07-26T05:18:05.587170Z",
"shell.execute_reply": "2023-07-26T05:18:05.586673Z"
"iopub.execute_input": "2023-07-26T19:30:28.143620Z",
"iopub.status.busy": "2023-07-26T19:30:28.143294Z",
"iopub.status.idle": "2023-07-26T19:30:28.332708Z",
"shell.execute_reply": "2023-07-26T19:30:28.331511Z"
}
},
"outputs": [],
"source": [
"W = np.array([sim_time(l, cum_hazard, rng)\n",
" for l in true_linpred])\n",
"D['Wait time'] = np.clip(W, 0, 1000)\n"
"D['Wait time'] = np.clip(W, 0, 1000)"
]
},
{
@@ -1900,12 +1890,11 @@
"id": "fe008dbf",
"metadata": {
"execution": {
"iopub.execute_input": "2023-07-26T05:18:05.590252Z",
"iopub.status.busy": "2023-07-26T05:18:05.589902Z",
"iopub.status.idle": "2023-07-26T05:18:05.596018Z",
"shell.execute_reply": "2023-07-26T05:18:05.595604Z"
},
"lines_to_next_cell": 2
"iopub.execute_input": "2023-07-26T19:30:28.337898Z",
"iopub.status.busy": "2023-07-26T19:30:28.336191Z",
"iopub.status.idle": "2023-07-26T19:30:28.348465Z",
"shell.execute_reply": "2023-07-26T19:30:28.347537Z"
}
},
"outputs": [
{
@@ -1999,7 +1988,7 @@
"D['Failed'] = rng.choice([1, 0],\n",
" N,\n",
" p=[0.9, 0.1])\n",
"D[:5]\n"
"D[:5]"
]
},
{
@@ -2008,10 +1997,10 @@
"id": "c3a2bec7",
"metadata": {
"execution": {
"iopub.execute_input": "2023-07-26T05:18:05.598122Z",
"iopub.status.busy": "2023-07-26T05:18:05.597969Z",
"iopub.status.idle": "2023-07-26T05:18:05.601009Z",
"shell.execute_reply": "2023-07-26T05:18:05.600579Z"
"iopub.execute_input": "2023-07-26T19:30:28.352144Z",
"iopub.status.busy": "2023-07-26T19:30:28.351650Z",
"iopub.status.idle": "2023-07-26T19:30:28.358415Z",
"shell.execute_reply": "2023-07-26T19:30:28.357683Z"
}
},
"outputs": [
@@ -2027,7 +2016,7 @@
}
],
"source": [
"D['Failed'].mean()\n"
"D['Failed'].mean()"
]
},
{
@@ -2044,10 +2033,10 @@
"id": "2b27af56",
"metadata": {
"execution": {
"iopub.execute_input": "2023-07-26T05:18:05.603318Z",
"iopub.status.busy": "2023-07-26T05:18:05.603142Z",
"iopub.status.idle": "2023-07-26T05:18:05.827076Z",
"shell.execute_reply": "2023-07-26T05:18:05.826151Z"
"iopub.execute_input": "2023-07-26T19:30:28.361989Z",
"iopub.status.busy": "2023-07-26T19:30:28.361496Z",
"iopub.status.idle": "2023-07-26T19:30:28.527528Z",
"shell.execute_reply": "2023-07-26T19:30:28.527187Z"
}
},
"outputs": [
@@ -2079,7 +2068,7 @@
" by_center[center] = df\n",
" km_center = km.fit(df['Wait time'], df['Failed'])\n",
" km_center.plot(label='Center=%s' % center, ax=ax)\n",
"ax.set_title(\"Probability of Still Being on Hold\")\n"
"ax.set_title(\"Probability of Still Being on Hold\")"
]
},
{
@@ -2096,10 +2085,10 @@
"id": "9625598d",
"metadata": {
"execution": {
"iopub.execute_input": "2023-07-26T05:18:05.830554Z",
"iopub.status.busy": "2023-07-26T05:18:05.830059Z",
"iopub.status.idle": "2023-07-26T05:18:06.008529Z",
"shell.execute_reply": "2023-07-26T05:18:06.008079Z"
"iopub.execute_input": "2023-07-26T19:30:28.529240Z",
"iopub.status.busy": "2023-07-26T19:30:28.529144Z",
"iopub.status.idle": "2023-07-26T19:30:28.726030Z",
"shell.execute_reply": "2023-07-26T19:30:28.725744Z"
}
},
"outputs": [
@@ -2131,7 +2120,7 @@
" by_time[time] = df\n",
" km_time = km.fit(df['Wait time'], df['Failed'])\n",
" km_time.plot(label='Time=%s' % time, ax=ax)\n",
"ax.set_title(\"Probability of Still Being on Hold\")\n"
"ax.set_title(\"Probability of Still Being on Hold\")"
]
},
{
@@ -2152,12 +2141,11 @@
"id": "75a744ef",
"metadata": {
"execution": {
"iopub.execute_input": "2023-07-26T05:18:06.012649Z",
"iopub.status.busy": "2023-07-26T05:18:06.012037Z",
"iopub.status.idle": "2023-07-26T05:18:06.033832Z",
"shell.execute_reply": "2023-07-26T05:18:06.033320Z"
},
"lines_to_next_cell": 2
"iopub.execute_input": "2023-07-26T19:30:28.727718Z",
"iopub.status.busy": "2023-07-26T19:30:28.727608Z",
"iopub.status.idle": "2023-07-26T19:30:28.745292Z",
"shell.execute_reply": "2023-07-26T19:30:28.744982Z"
}
},
"outputs": [
{
@@ -2242,7 +2230,7 @@
"source": [
"multivariate_logrank_test(D['Wait time'],\n",
" D['Center'],\n",
" D['Failed'])\n"
" D['Failed'])"
]
},
{
@@ -2259,12 +2247,11 @@
"id": "9badb3e3",
"metadata": {
"execution": {
"iopub.execute_input": "2023-07-26T05:18:06.036375Z",
"iopub.status.busy": "2023-07-26T05:18:06.036170Z",
"iopub.status.idle": "2023-07-26T05:18:06.055850Z",
"shell.execute_reply": "2023-07-26T05:18:06.055183Z"
},
"lines_to_next_cell": 2
"iopub.execute_input": "2023-07-26T19:30:28.746932Z",
"iopub.status.busy": "2023-07-26T19:30:28.746812Z",
"iopub.status.idle": "2023-07-26T19:30:28.764031Z",
"shell.execute_reply": "2023-07-26T19:30:28.763730Z"
}
},
"outputs": [
{
@@ -2349,7 +2336,7 @@
"source": [
"multivariate_logrank_test(D['Wait time'],\n",
" D['Time'],\n",
" D['Failed'])\n"
" D['Failed'])"
]
},
{
@@ -2369,12 +2356,11 @@
"id": "026e9ff8",
"metadata": {
"execution": {
"iopub.execute_input": "2023-07-26T05:18:06.058057Z",
"iopub.status.busy": "2023-07-26T05:18:06.057906Z",
"iopub.status.idle": "2023-07-26T05:18:06.184883Z",
"shell.execute_reply": "2023-07-26T05:18:06.184356Z"
},
"lines_to_next_cell": 2
"iopub.execute_input": "2023-07-26T19:30:28.765683Z",
"iopub.status.busy": "2023-07-26T19:30:28.765567Z",
"iopub.status.idle": "2023-07-26T19:30:28.888155Z",
"shell.execute_reply": "2023-07-26T19:30:28.887853Z"
}
},
"outputs": [
{
@@ -2457,7 +2443,7 @@
" 'Center'],\n",
" intercept=False).fit_transform(D)\n",
"F = coxph().fit(X, 'Wait time', 'Failed')\n",
"F.log_likelihood_ratio_test()\n"
"F.log_likelihood_ratio_test()"
]
},
{
@@ -2474,12 +2460,11 @@
"id": "7cab3789",
"metadata": {
"execution": {
"iopub.execute_input": "2023-07-26T05:18:06.187428Z",
"iopub.status.busy": "2023-07-26T05:18:06.187255Z",
"iopub.status.idle": "2023-07-26T05:18:06.315832Z",
"shell.execute_reply": "2023-07-26T05:18:06.314374Z"
},
"lines_to_next_cell": 2
"iopub.execute_input": "2023-07-26T19:30:28.889732Z",
"iopub.status.busy": "2023-07-26T19:30:28.889626Z",
"iopub.status.idle": "2023-07-26T19:30:29.012622Z",
"shell.execute_reply": "2023-07-26T19:30:29.012324Z"
}
},
"outputs": [
{
@@ -2562,7 +2547,7 @@
" 'Time'],\n",
" intercept=False).fit_transform(D)\n",
"F = coxph().fit(X, 'Wait time', 'Failed')\n",
"F.log_likelihood_ratio_test()\n"
"F.log_likelihood_ratio_test()"
]
},
{
@@ -2582,12 +2567,11 @@
"id": "5cc4b898",
"metadata": {
"execution": {
"iopub.execute_input": "2023-07-26T05:18:06.320288Z",
"iopub.status.busy": "2023-07-26T05:18:06.319261Z",
"iopub.status.idle": "2023-07-26T05:18:06.585074Z",
"shell.execute_reply": "2023-07-26T05:18:06.577564Z"
},
"lines_to_next_cell": 2
"iopub.execute_input": "2023-07-26T19:30:29.014300Z",
"iopub.status.busy": "2023-07-26T19:30:29.014186Z",
"iopub.status.idle": "2023-07-26T19:30:29.163409Z",
"shell.execute_reply": "2023-07-26T19:30:29.160684Z"
}
},
"outputs": [
{
@@ -2679,7 +2663,7 @@
" X,\n",
" 'Wait time',\n",
" 'Failed')\n",
"fit_queuing.summary[['coef', 'se(coef)', 'p']]\n"
"fit_queuing.summary[['coef', 'se(coef)', 'p']]"
]
},
{
@@ -2695,16 +2679,15 @@
" `Operators`, `Center = B`, `Center = C`, \n",
"`Time = Even.` and `Time = Morn.` are $0.04$, $-0.3$,\n",
"$0$, $0.2$, and $-0.2$, respectively. The coefficient estimates\n",
"from the fitted Cox model are fairly accurate.\n",
"\n"
"from the fitted Cox model are fairly accurate."
]
}
],
"metadata": {
"jupytext": {
"cell_metadata_filter": "-all",
"main_language": "python",
"notebook_metadata_filter": "-all"
"formats": "ipynb,md:myst",
"main_language": "python"
},
"language_info": {
"codemirror_mode": {
@@ -2716,7 +2699,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.9.17"
"version": "3.11.4"
}
},
"nbformat": 4,
+358 -404
View File
File diff suppressed because it is too large. Load diff
+176 -210
View File
@@ -5,11 +5,9 @@
"id": "75b2d75c",
"metadata": {},
"source": [
"\n",
"# Chapter 13\n",
"\n",
"# Lab: Multiple Testing\n",
" "
"# Lab: Multiple Testing"
]
},
{
@@ -26,10 +24,10 @@
"id": "1f928b2d",
"metadata": {
"execution": {
"iopub.execute_input": "2023-07-26T10:52:21.791802Z",
"iopub.status.busy": "2023-07-26T10:52:21.791660Z",
"iopub.status.idle": "2023-07-26T10:52:23.360588Z",
"shell.execute_reply": "2023-07-26T10:52:23.359991Z"
"iopub.execute_input": "2023-07-26T19:30:40.174249Z",
"iopub.status.busy": "2023-07-26T19:30:40.174147Z",
"iopub.status.idle": "2023-07-26T19:30:41.295542Z",
"shell.execute_reply": "2023-07-26T19:30:41.294997Z"
}
},
"outputs": [],
@@ -38,7 +36,7 @@
"import pandas as pd\n",
"import matplotlib.pyplot as plt\n",
"import statsmodels.api as sm\n",
"from ISLP import load_data\n"
"from ISLP import load_data"
]
},
{
@@ -56,12 +54,11 @@
"id": "eb4b32aa",
"metadata": {
"execution": {
"iopub.execute_input": "2023-07-26T10:52:23.363356Z",
"iopub.status.busy": "2023-07-26T10:52:23.362843Z",
"iopub.status.idle": "2023-07-26T10:52:23.365980Z",
"shell.execute_reply": "2023-07-26T10:52:23.365438Z"
},
"lines_to_next_cell": 2
"iopub.execute_input": "2023-07-26T19:30:41.298057Z",
"iopub.status.busy": "2023-07-26T19:30:41.297544Z",
"iopub.status.idle": "2023-07-26T19:30:41.300143Z",
"shell.execute_reply": "2023-07-26T19:30:41.299888Z"
}
},
"outputs": [],
"source": [
@@ -73,7 +70,7 @@
"from statsmodels.stats.multicomp import \\\n",
" pairwise_tukeyhsd\n",
"from statsmodels.stats.multitest import \\\n",
" multipletests as mult_test\n"
" multipletests as mult_test"
]
},
{
@@ -95,10 +92,10 @@
"id": "e12ac0cd",
"metadata": {
"execution": {
"iopub.execute_input": "2023-07-26T10:52:23.368340Z",
"iopub.status.busy": "2023-07-26T10:52:23.368164Z",
"iopub.status.idle": "2023-07-26T10:52:23.371202Z",
"shell.execute_reply": "2023-07-26T10:52:23.370779Z"
"iopub.execute_input": "2023-07-26T19:30:41.301702Z",
"iopub.status.busy": "2023-07-26T19:30:41.301592Z",
"iopub.status.idle": "2023-07-26T19:30:41.303876Z",
"shell.execute_reply": "2023-07-26T19:30:41.303617Z"
}
},
"outputs": [],
@@ -106,7 +103,7 @@
"rng = np.random.default_rng(12)\n",
"X = rng.standard_normal((10, 100))\n",
"true_mean = np.array([0.5]*50 + [0]*50)\n",
"X += true_mean[None,:]\n"
"X += true_mean[None,:]"
]
},
{
@@ -125,10 +122,10 @@
"id": "04d0f49e",
"metadata": {
"execution": {
"iopub.execute_input": "2023-07-26T10:52:23.373512Z",
"iopub.status.busy": "2023-07-26T10:52:23.373319Z",
"iopub.status.idle": "2023-07-26T10:52:23.378383Z",
"shell.execute_reply": "2023-07-26T10:52:23.377960Z"
"iopub.execute_input": "2023-07-26T19:30:41.305411Z",
"iopub.status.busy": "2023-07-26T19:30:41.305302Z",
"iopub.status.idle": "2023-07-26T19:30:41.309554Z",
"shell.execute_reply": "2023-07-26T19:30:41.309317Z"
}
},
"outputs": [
@@ -145,7 +142,7 @@
],
"source": [
"result = ttest_1samp(X[:,0], 0)\n",
"result.pvalue\n"
"result.pvalue"
]
},
{
@@ -172,12 +169,11 @@
"id": "d1f0c695",
"metadata": {
"execution": {
"iopub.execute_input": "2023-07-26T10:52:23.380819Z",
"iopub.status.busy": "2023-07-26T10:52:23.380641Z",
"iopub.status.idle": "2023-07-26T10:52:23.408797Z",
"shell.execute_reply": "2023-07-26T10:52:23.408278Z"
},
"lines_to_next_cell": 0
"iopub.execute_input": "2023-07-26T19:30:41.311030Z",
"iopub.status.busy": "2023-07-26T19:30:41.310945Z",
"iopub.status.idle": "2023-07-26T19:30:41.336675Z",
"shell.execute_reply": "2023-07-26T19:30:41.336337Z"
}
},
"outputs": [],
"source": [
@@ -190,7 +186,7 @@
" 'Do not reject H0'])\n",
"truth = pd.Categorical(true_mean == 0,\n",
" categories=[True, False],\n",
" ordered=True)\n"
" ordered=True)"
]
},
{
@@ -208,12 +204,11 @@
"id": "7a9594a0",
"metadata": {
"execution": {
"iopub.execute_input": "2023-07-26T10:52:23.411256Z",
"iopub.status.busy": "2023-07-26T10:52:23.411053Z",
"iopub.status.idle": "2023-07-26T10:52:23.422652Z",
"shell.execute_reply": "2023-07-26T10:52:23.422286Z"
},
"lines_to_next_cell": 0
"iopub.execute_input": "2023-07-26T19:30:41.338368Z",
"iopub.status.busy": "2023-07-26T19:30:41.338270Z",
"iopub.status.idle": "2023-07-26T19:30:41.347923Z",
"shell.execute_reply": "2023-07-26T19:30:41.347609Z"
}
},
"outputs": [
{
@@ -277,7 +272,7 @@
"pd.crosstab(decision,\n",
" truth,\n",
" rownames=['Decision'],\n",
" colnames=['H0'])\n"
" colnames=['H0'])"
]
},
{
@@ -299,7 +294,7 @@
"amounts to quite a weak signal, and it resulted in a high number of\n",
"Type II errors. Let’s instead simulate data with a stronger signal,\n",
"so that the ratio of the mean to the standard deviation for the false\n",
"null hypotheses equals $1$. We make only 10 Type II errors.\n"
"null hypotheses equals $1$. We make only 10 Type II errors."
]
},
{
@@ -308,12 +303,11 @@
"id": "25f7fc5d",
"metadata": {
"execution": {
"iopub.execute_input": "2023-07-26T10:52:23.425157Z",
"iopub.status.busy": "2023-07-26T10:52:23.424798Z",
"iopub.status.idle": "2023-07-26T10:52:23.455752Z",
"shell.execute_reply": "2023-07-26T10:52:23.455052Z"
},
"lines_to_next_cell": 0
"iopub.execute_input": "2023-07-26T19:30:41.349462Z",
"iopub.status.busy": "2023-07-26T19:30:41.349374Z",
"iopub.status.idle": "2023-07-26T19:30:41.377229Z",
"shell.execute_reply": "2023-07-26T19:30:41.376963Z"
}
},
"outputs": [
{
@@ -389,15 +383,7 @@
"pd.crosstab(decision,\n",
" truth,\n",
" rownames=['Decision'],\n",
" colnames=['H0'])\n"
]
},
{
"cell_type": "markdown",
"id": "bb70c597",
"metadata": {},
"source": [
" "
" colnames=['H0'])"
]
},
{
@@ -420,10 +406,10 @@
"id": "369b5bd3",
"metadata": {
"execution": {
"iopub.execute_input": "2023-07-26T10:52:23.458631Z",
"iopub.status.busy": "2023-07-26T10:52:23.458434Z",
"iopub.status.idle": "2023-07-26T10:52:23.710141Z",
"shell.execute_reply": "2023-07-26T10:52:23.709635Z"
"iopub.execute_input": "2023-07-26T19:30:41.378742Z",
"iopub.status.busy": "2023-07-26T19:30:41.378656Z",
"iopub.status.idle": "2023-07-26T19:30:41.640684Z",
"shell.execute_reply": "2023-07-26T19:30:41.639810Z"
}
},
"outputs": [
@@ -449,7 +435,7 @@
"ax.set_xlabel('Number of Hypotheses')\n",
"ax.set_ylabel('Family-Wise Error Rate')\n",
"ax.legend()\n",
"ax.axhline(0.05, c='k', ls='--');\n"
"ax.axhline(0.05, c='k', ls='--');"
]
},
{
@@ -476,10 +462,10 @@
"id": "9ce7a19f",
"metadata": {
"execution": {
"iopub.execute_input": "2023-07-26T10:52:23.713438Z",
"iopub.status.busy": "2023-07-26T10:52:23.713214Z",
"iopub.status.idle": "2023-07-26T10:52:23.754484Z",
"shell.execute_reply": "2023-07-26T10:52:23.754038Z"
"iopub.execute_input": "2023-07-26T19:30:41.651427Z",
"iopub.status.busy": "2023-07-26T19:30:41.646298Z",
"iopub.status.idle": "2023-07-26T19:30:41.691862Z",
"shell.execute_reply": "2023-07-26T19:30:41.691584Z"
}
},
"outputs": [
@@ -500,7 +486,7 @@
"fund_mini_pvals = np.empty(5)\n",
"for i in range(5):\n",
" fund_mini_pvals[i] = ttest_1samp(fund_mini.iloc[:,i], 0).pvalue\n",
"fund_mini_pvals\n"
"fund_mini_pvals"
]
},
{
@@ -544,12 +530,11 @@
"id": "de6cffed",
"metadata": {
"execution": {
"iopub.execute_input": "2023-07-26T10:52:23.756665Z",
"iopub.status.busy": "2023-07-26T10:52:23.756493Z",
"iopub.status.idle": "2023-07-26T10:52:23.759438Z",
"shell.execute_reply": "2023-07-26T10:52:23.759028Z"
},
"lines_to_next_cell": 2
"iopub.execute_input": "2023-07-26T19:30:41.693537Z",
"iopub.status.busy": "2023-07-26T19:30:41.693432Z",
"iopub.status.idle": "2023-07-26T19:30:41.695845Z",
"shell.execute_reply": "2023-07-26T19:30:41.695583Z"
}
},
"outputs": [
{
@@ -565,7 +550,7 @@
],
"source": [
"reject, bonf = mult_test(fund_mini_pvals, method = \"bonferroni\")[:2]\n",
"reject\n"
"reject"
]
},
{
@@ -583,10 +568,10 @@
"id": "0de71500",
"metadata": {
"execution": {
"iopub.execute_input": "2023-07-26T10:52:23.761459Z",
"iopub.status.busy": "2023-07-26T10:52:23.761287Z",
"iopub.status.idle": "2023-07-26T10:52:23.764317Z",
"shell.execute_reply": "2023-07-26T10:52:23.763952Z"
"iopub.execute_input": "2023-07-26T19:30:41.697297Z",
"iopub.status.busy": "2023-07-26T19:30:41.697186Z",
"iopub.status.idle": "2023-07-26T19:30:41.699576Z",
"shell.execute_reply": "2023-07-26T19:30:41.699333Z"
}
},
"outputs": [
@@ -603,7 +588,7 @@
}
],
"source": [
"bonf, np.minimum(fund_mini_pvals * 5, 1)\n"
"bonf, np.minimum(fund_mini_pvals * 5, 1)"
]
},
{
@@ -625,12 +610,11 @@
"id": "f7e87bdb",
"metadata": {
"execution": {
"iopub.execute_input": "2023-07-26T10:52:23.766793Z",
"iopub.status.busy": "2023-07-26T10:52:23.766606Z",
"iopub.status.idle": "2023-07-26T10:52:23.810152Z",
"shell.execute_reply": "2023-07-26T10:52:23.809736Z"
},
"lines_to_next_cell": 2
"iopub.execute_input": "2023-07-26T19:30:41.700975Z",
"iopub.status.busy": "2023-07-26T19:30:41.700886Z",
"iopub.status.idle": "2023-07-26T19:30:41.744972Z",
"shell.execute_reply": "2023-07-26T19:30:41.744690Z"
}
},
"outputs": [
{
@@ -646,7 +630,7 @@
}
],
"source": [
"mult_test(fund_mini_pvals, method = \"holm\", alpha=0.05)[:2]\n"
"mult_test(fund_mini_pvals, method = \"holm\", alpha=0.05)[:2]"
]
},
{
@@ -664,12 +648,11 @@
"id": "e88be376",
"metadata": {
"execution": {
"iopub.execute_input": "2023-07-26T10:52:23.812384Z",
"iopub.status.busy": "2023-07-26T10:52:23.812232Z",
"iopub.status.idle": "2023-07-26T10:52:23.815971Z",
"shell.execute_reply": "2023-07-26T10:52:23.815576Z"
},
"lines_to_next_cell": 2
"iopub.execute_input": "2023-07-26T19:30:41.746473Z",
"iopub.status.busy": "2023-07-26T19:30:41.746386Z",
"iopub.status.idle": "2023-07-26T19:30:41.749362Z",
"shell.execute_reply": "2023-07-26T19:30:41.749117Z"
}
},
"outputs": [
{
@@ -689,7 +672,7 @@
}
],
"source": [
"fund_mini.mean()\n"
"fund_mini.mean()"
]
},
{
@@ -708,10 +691,10 @@
"id": "41149af6",
"metadata": {
"execution": {
"iopub.execute_input": "2023-07-26T10:52:23.817997Z",
"iopub.status.busy": "2023-07-26T10:52:23.817852Z",
"iopub.status.idle": "2023-07-26T10:52:23.821301Z",
"shell.execute_reply": "2023-07-26T10:52:23.820976Z"
"iopub.execute_input": "2023-07-26T19:30:41.750766Z",
"iopub.status.busy": "2023-07-26T19:30:41.750681Z",
"iopub.status.idle": "2023-07-26T19:30:41.753275Z",
"shell.execute_reply": "2023-07-26T19:30:41.753015Z"
}
},
"outputs": [
@@ -728,7 +711,7 @@
],
"source": [
"ttest_rel(fund_mini['Manager1'],\n",
" fund_mini['Manager2']).pvalue\n"
" fund_mini['Manager2']).pvalue"
]
},
{
@@ -760,12 +743,11 @@
"id": "61aabda7",
"metadata": {
"execution": {
"iopub.execute_input": "2023-07-26T10:52:23.823367Z",
"iopub.status.busy": "2023-07-26T10:52:23.823190Z",
"iopub.status.idle": "2023-07-26T10:52:24.308715Z",
"shell.execute_reply": "2023-07-26T10:52:24.308222Z"
},
"lines_to_next_cell": 2
"iopub.execute_input": "2023-07-26T19:30:41.754673Z",
"iopub.status.busy": "2023-07-26T19:30:41.754580Z",
"iopub.status.idle": "2023-07-26T19:30:42.239556Z",
"shell.execute_reply": "2023-07-26T19:30:42.239231Z"
}
},
"outputs": [
{
@@ -794,7 +776,7 @@
"returns = np.hstack([fund_mini.iloc[:,i] for i in range(5)])\n",
"managers = np.hstack([[i+1]*50 for i in range(5)])\n",
"tukey = pairwise_tukeyhsd(returns, managers)\n",
"print(tukey.summary())\n"
"print(tukey.summary())"
]
},
{
@@ -820,10 +802,10 @@
"id": "cbcad4de",
"metadata": {
"execution": {
"iopub.execute_input": "2023-07-26T10:52:24.311170Z",
"iopub.status.busy": "2023-07-26T10:52:24.310960Z",
"iopub.status.idle": "2023-07-26T10:52:24.410742Z",
"shell.execute_reply": "2023-07-26T10:52:24.410212Z"
"iopub.execute_input": "2023-07-26T19:30:42.241228Z",
"iopub.status.busy": "2023-07-26T19:30:42.241113Z",
"iopub.status.idle": "2023-07-26T19:30:42.322033Z",
"shell.execute_reply": "2023-07-26T19:30:42.321731Z"
}
},
"outputs": [
@@ -840,7 +822,7 @@
],
"source": [
"fig, ax = plt.subplots(figsize=(8,8))\n",
"tukey.plot_simultaneous(ax=ax);\n"
"tukey.plot_simultaneous(ax=ax);"
]
},
{
@@ -861,17 +843,17 @@
"id": "b5842190",
"metadata": {
"execution": {
"iopub.execute_input": "2023-07-26T10:52:24.413638Z",
"iopub.status.busy": "2023-07-26T10:52:24.413455Z",
"iopub.status.idle": "2023-07-26T10:52:24.827343Z",
"shell.execute_reply": "2023-07-26T10:52:24.826609Z"
"iopub.execute_input": "2023-07-26T19:30:42.323675Z",
"iopub.status.busy": "2023-07-26T19:30:42.323560Z",
"iopub.status.idle": "2023-07-26T19:30:42.738874Z",
"shell.execute_reply": "2023-07-26T19:30:42.738524Z"
}
},
"outputs": [],
"source": [
"fund_pvalues = np.empty(2000)\n",
"for i, manager in enumerate(Fund.columns):\n",
" fund_pvalues[i] = ttest_1samp(Fund[manager], 0).pvalue\n"
" fund_pvalues[i] = ttest_1samp(Fund[manager], 0).pvalue"
]
},
{
@@ -890,10 +872,10 @@
"id": "7c9d8bed",
"metadata": {
"execution": {
"iopub.execute_input": "2023-07-26T10:52:24.830214Z",
"iopub.status.busy": "2023-07-26T10:52:24.830015Z",
"iopub.status.idle": "2023-07-26T10:52:24.834953Z",
"shell.execute_reply": "2023-07-26T10:52:24.834464Z"
"iopub.execute_input": "2023-07-26T19:30:42.740722Z",
"iopub.status.busy": "2023-07-26T19:30:42.740600Z",
"iopub.status.idle": "2023-07-26T19:30:42.743374Z",
"shell.execute_reply": "2023-07-26T19:30:42.743108Z"
}
},
"outputs": [
@@ -911,7 +893,7 @@
],
"source": [
"fund_qvalues = mult_test(fund_pvalues, method = \"fdr_bh\")[1]\n",
"fund_qvalues[:10]\n"
"fund_qvalues[:10]"
]
},
{
@@ -935,12 +917,11 @@
"id": "bfa39f7c",
"metadata": {
"execution": {
"iopub.execute_input": "2023-07-26T10:52:24.837627Z",
"iopub.status.busy": "2023-07-26T10:52:24.837419Z",
"iopub.status.idle": "2023-07-26T10:52:24.840834Z",
"shell.execute_reply": "2023-07-26T10:52:24.840316Z"
},
"lines_to_next_cell": 0
"iopub.execute_input": "2023-07-26T19:30:42.744900Z",
"iopub.status.busy": "2023-07-26T19:30:42.744792Z",
"iopub.status.idle": "2023-07-26T19:30:42.747030Z",
"shell.execute_reply": "2023-07-26T19:30:42.746764Z"
}
},
"outputs": [
{
@@ -955,7 +936,7 @@
}
],
"source": [
"(fund_qvalues <= 0.1).sum()\n"
"(fund_qvalues <= 0.1).sum()"
]
},
{
@@ -979,12 +960,11 @@
"id": "70b69b47",
"metadata": {
"execution": {
"iopub.execute_input": "2023-07-26T10:52:24.843470Z",
"iopub.status.busy": "2023-07-26T10:52:24.843237Z",
"iopub.status.idle": "2023-07-26T10:52:24.846889Z",
"shell.execute_reply": "2023-07-26T10:52:24.846276Z"
},
"lines_to_next_cell": 2
"iopub.execute_input": "2023-07-26T19:30:42.748394Z",
"iopub.status.busy": "2023-07-26T19:30:42.748301Z",
"iopub.status.idle": "2023-07-26T19:30:42.750369Z",
"shell.execute_reply": "2023-07-26T19:30:42.750115Z"
}
},
"outputs": [
{
@@ -999,7 +979,7 @@
}
],
"source": [
"(fund_pvalues <= 0.1 / 2000).sum()\n"
"(fund_pvalues <= 0.1 / 2000).sum()"
]
},
{
@@ -1029,10 +1009,10 @@
"id": "4c0ddea1",
"metadata": {
"execution": {
"iopub.execute_input": "2023-07-26T10:52:24.849388Z",
"iopub.status.busy": "2023-07-26T10:52:24.849238Z",
"iopub.status.idle": "2023-07-26T10:52:24.852847Z",
"shell.execute_reply": "2023-07-26T10:52:24.852354Z"
"iopub.execute_input": "2023-07-26T19:30:42.751896Z",
"iopub.status.busy": "2023-07-26T19:30:42.751792Z",
"iopub.status.idle": "2023-07-26T19:30:42.754281Z",
"shell.execute_reply": "2023-07-26T19:30:42.754006Z"
}
},
"outputs": [],
@@ -1046,7 +1026,7 @@
" sorted_set_ = np.arange(sorted_set_.max())\n",
"else:\n",
" selected_ = []\n",
" sorted_set_ = []\n"
" sorted_set_ = []"
]
},
{
@@ -1063,12 +1043,11 @@
"id": "0314eac9",
"metadata": {
"execution": {
"iopub.execute_input": "2023-07-26T10:52:24.855721Z",
"iopub.status.busy": "2023-07-26T10:52:24.855334Z",
"iopub.status.idle": "2023-07-26T10:52:25.156072Z",
"shell.execute_reply": "2023-07-26T10:52:25.155438Z"
},
"lines_to_next_cell": 2
"iopub.execute_input": "2023-07-26T19:30:42.755678Z",
"iopub.status.busy": "2023-07-26T19:30:42.755585Z",
"iopub.status.idle": "2023-07-26T19:30:42.999460Z",
"shell.execute_reply": "2023-07-26T19:30:42.998935Z"
}
},
"outputs": [
{
@@ -1091,7 +1070,7 @@
"ax.set_ylabel('P-Value')\n",
"ax.set_xlabel('Index')\n",
"ax.scatter(sorted_set_+1, sorted_[sorted_set_], c='r', s=20)\n",
"ax.axline((0, 0), (1,q/m), c='k', ls='--', linewidth=3);\n"
"ax.axline((0, 0), (1,q/m), c='k', ls='--', linewidth=3);"
]
},
{
@@ -1113,12 +1092,11 @@
"id": "b59b8137",
"metadata": {
"execution": {
"iopub.execute_input": "2023-07-26T10:52:25.158998Z",
"iopub.status.busy": "2023-07-26T10:52:25.158769Z",
"iopub.status.idle": "2023-07-26T10:52:25.243020Z",
"shell.execute_reply": "2023-07-26T10:52:25.242512Z"
},
"lines_to_next_cell": 2
"iopub.execute_input": "2023-07-26T19:30:43.001457Z",
"iopub.status.busy": "2023-07-26T19:30:43.001301Z",
"iopub.status.idle": "2023-07-26T19:30:43.079281Z",
"shell.execute_reply": "2023-07-26T19:30:43.078814Z"
}
},
"outputs": [
{
@@ -1140,7 +1118,7 @@
"Khan = load_data('Khan') \n",
"D = pd.concat([Khan['xtrain'], Khan['xtest']])\n",
"D['Y'] = pd.concat([Khan['ytrain'], Khan['ytest']])\n",
"D['Y'].value_counts()\n"
"D['Y'].value_counts()"
]
},
{
@@ -1164,12 +1142,11 @@
"id": "96fb2f61",
"metadata": {
"execution": {
"iopub.execute_input": "2023-07-26T10:52:25.245359Z",
"iopub.status.busy": "2023-07-26T10:52:25.245172Z",
"iopub.status.idle": "2023-07-26T10:52:25.250139Z",
"shell.execute_reply": "2023-07-26T10:52:25.249644Z"
},
"lines_to_next_cell": 2
"iopub.execute_input": "2023-07-26T19:30:43.081705Z",
"iopub.status.busy": "2023-07-26T19:30:43.081539Z",
"iopub.status.idle": "2023-07-26T19:30:43.086400Z",
"shell.execute_reply": "2023-07-26T19:30:43.086081Z"
}
},
"outputs": [
{
@@ -1190,7 +1167,7 @@
"observedT, pvalue = ttest_ind(D2[gene_11],\n",
" D4[gene_11],\n",
" equal_var=True)\n",
"observedT, pvalue\n"
"observedT, pvalue"
]
},
{
@@ -1217,12 +1194,11 @@
"id": "fdc229fa",
"metadata": {
"execution": {
"iopub.execute_input": "2023-07-26T10:52:25.252510Z",
"iopub.status.busy": "2023-07-26T10:52:25.252319Z",
"iopub.status.idle": "2023-07-26T10:52:26.208474Z",
"shell.execute_reply": "2023-07-26T10:52:26.207894Z"
},
"lines_to_next_cell": 2
"iopub.execute_input": "2023-07-26T19:30:43.088801Z",
"iopub.status.busy": "2023-07-26T19:30:43.088456Z",
"iopub.status.idle": "2023-07-26T19:30:45.428003Z",
"shell.execute_reply": "2023-07-26T19:30:45.427711Z"
}
},
"outputs": [
{
@@ -1248,7 +1224,7 @@
" D_null[n_:],\n",
" equal_var=True)\n",
" Tnull[b] = ttest_.statistic\n",
"(np.abs(Tnull) > np.abs(observedT)).mean()\n"
"(np.abs(Tnull) > np.abs(observedT)).mean()"
]
},
{
@@ -1268,12 +1244,11 @@
"id": "e3894695",
"metadata": {
"execution": {
"iopub.execute_input": "2023-07-26T10:52:26.210995Z",
"iopub.status.busy": "2023-07-26T10:52:26.210826Z",
"iopub.status.idle": "2023-07-26T10:52:26.458716Z",
"shell.execute_reply": "2023-07-26T10:52:26.458144Z"
},
"lines_to_next_cell": 0
"iopub.execute_input": "2023-07-26T19:30:45.429626Z",
"iopub.status.busy": "2023-07-26T19:30:45.429511Z",
"iopub.status.idle": "2023-07-26T19:30:45.644637Z",
"shell.execute_reply": "2023-07-26T19:30:45.644276Z"
}
},
"outputs": [
{
@@ -1302,7 +1277,7 @@
" c='b',\n",
" label='Observed')\n",
"ax.legend()\n",
"ax.set_xlabel(\"Null Distribution of Test Statistic\");\n"
"ax.set_xlabel(\"Null Distribution of Test Statistic\");"
]
},
{
@@ -1328,10 +1303,10 @@
"id": "3b7392cb",
"metadata": {
"execution": {
"iopub.execute_input": "2023-07-26T10:52:26.461754Z",
"iopub.status.busy": "2023-07-26T10:52:26.461349Z",
"iopub.status.idle": "2023-07-26T12:21:43.650925Z",
"shell.execute_reply": "2023-07-26T12:21:43.650584Z"
"iopub.execute_input": "2023-07-26T19:30:45.646419Z",
"iopub.status.busy": "2023-07-26T19:30:45.646303Z",
"iopub.status.idle": "2023-07-26T19:34:40.348681Z",
"shell.execute_reply": "2023-07-26T19:34:40.347928Z"
}
},
"outputs": [],
@@ -1353,7 +1328,7 @@
" ttest_ = ttest_ind(D_null[:n_],\n",
" D_null[n_:],\n",
" equal_var=True)\n",
" Tnull_vals[j,b] = ttest_.statistic\n"
" Tnull_vals[j,b] = ttest_.statistic"
]
},
{
@@ -1374,10 +1349,10 @@
"id": "cac15616",
"metadata": {
"execution": {
"iopub.execute_input": "2023-07-26T12:21:43.653105Z",
"iopub.status.busy": "2023-07-26T12:21:43.652856Z",
"iopub.status.idle": "2023-07-26T12:21:43.895651Z",
"shell.execute_reply": "2023-07-26T12:21:43.895292Z"
"iopub.execute_input": "2023-07-26T19:34:40.352699Z",
"iopub.status.busy": "2023-07-26T19:34:40.352545Z",
"iopub.status.idle": "2023-07-26T19:34:40.476265Z",
"shell.execute_reply": "2023-07-26T19:34:40.475900Z"
}
},
"outputs": [],
@@ -1389,7 +1364,7 @@
" V = np.sum(np.abs(Tnull_vals) >= cutoffs[j]) / B\n",
" Rs[j] = R\n",
" Vs[j] = V\n",
" FDRs[j] = V / R\n"
" FDRs[j] = V / R"
]
},
{
@@ -1415,10 +1390,10 @@
"id": "9661eb10",
"metadata": {
"execution": {
"iopub.execute_input": "2023-07-26T12:21:43.897943Z",
"iopub.status.busy": "2023-07-26T12:21:43.897797Z",
"iopub.status.idle": "2023-07-26T12:21:43.901002Z",
"shell.execute_reply": "2023-07-26T12:21:43.900637Z"
"iopub.execute_input": "2023-07-26T19:34:40.478059Z",
"iopub.status.busy": "2023-07-26T19:34:40.477950Z",
"iopub.status.idle": "2023-07-26T19:34:40.481159Z",
"shell.execute_reply": "2023-07-26T19:34:40.480856Z"
}
},
"outputs": [
@@ -1452,7 +1427,7 @@
}
],
"source": [
"sorted(idx[np.abs(T_vals) >= cutoffs[FDRs < 0.1].min()])\n"
"sorted(idx[np.abs(T_vals) >= cutoffs[FDRs < 0.1].min()])"
]
},
{
@@ -1470,10 +1445,10 @@
"id": "18ad4900",
"metadata": {
"execution": {
"iopub.execute_input": "2023-07-26T12:21:43.902778Z",
"iopub.status.busy": "2023-07-26T12:21:43.902684Z",
"iopub.status.idle": "2023-07-26T12:21:43.905535Z",
"shell.execute_reply": "2023-07-26T12:21:43.905228Z"
"iopub.execute_input": "2023-07-26T19:34:40.483066Z",
"iopub.status.busy": "2023-07-26T19:34:40.482980Z",
"iopub.status.idle": "2023-07-26T19:34:40.485451Z",
"shell.execute_reply": "2023-07-26T19:34:40.485202Z"
}
},
"outputs": [
@@ -1519,7 +1494,7 @@
}
],
"source": [
"sorted(idx[np.abs(T_vals) >= cutoffs[FDRs < 0.2].min()])\n"
"sorted(idx[np.abs(T_vals) >= cutoffs[FDRs < 0.2].min()])"
]
},
{
@@ -1538,12 +1513,11 @@
"id": "28c276b6",
"metadata": {
"execution": {
"iopub.execute_input": "2023-07-26T12:21:43.907278Z",
"iopub.status.busy": "2023-07-26T12:21:43.907150Z",
"iopub.status.idle": "2023-07-26T12:21:43.988689Z",
"shell.execute_reply": "2023-07-26T12:21:43.988352Z"
},
"lines_to_next_cell": 0
"iopub.execute_input": "2023-07-26T19:34:40.487079Z",
"iopub.status.busy": "2023-07-26T19:34:40.486999Z",
"iopub.status.idle": "2023-07-26T19:34:40.563798Z",
"shell.execute_reply": "2023-07-26T19:34:40.563460Z"
}
},
"outputs": [
{
@@ -1561,23 +1535,15 @@
"fig, ax = plt.subplots()\n",
"ax.plot(Rs, FDRs, 'b', linewidth=3)\n",
"ax.set_xlabel(\"Number of Rejections\")\n",
"ax.set_ylabel(\"False Discovery Rate\");\n"
]
},
{
"cell_type": "markdown",
"id": "e4b5d621",
"metadata": {},
"source": [
"\n"
"ax.set_ylabel(\"False Discovery Rate\");"
]
}
],
"metadata": {
"jupytext": {
"cell_metadata_filter": "-all",
"main_language": "python",
"notebook_metadata_filter": "-all"
"formats": "ipynb,md:myst",
"main_language": "python"
},
"language_info": {
"codemirror_mode": {
@@ -1589,7 +1555,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.9.17"
"version": "3.11.4"
}
},
"nbformat": 4,
+208 -404
View File
File diff suppressed because it is too large. Load diff
+259 -267
View File
File diff suppressed because it is too large. Load diff
File diff suppressed because it is too large. Load diff
+147 -173
View File
@@ -5,9 +5,7 @@
"id": "3a3f2f85",
"metadata": {},
"source": [
"\n",
"# Chapter 5\n",
"\n"
"# Chapter 5"
]
},
{
@@ -29,12 +27,11 @@
"id": "60fad148",
"metadata": {
"execution": {
"iopub.execute_input": "2023-07-26T05:16:58.904948Z",
"iopub.status.busy": "2023-07-26T05:16:58.904833Z",
"iopub.status.idle": "2023-07-26T05:16:59.817459Z",
"shell.execute_reply": "2023-07-26T05:16:59.816977Z"
},
"lines_to_next_cell": 2
"iopub.execute_input": "2023-07-26T19:27:27.380786Z",
"iopub.status.busy": "2023-07-26T19:27:27.380697Z",
"iopub.status.idle": "2023-07-26T19:27:28.278575Z",
"shell.execute_reply": "2023-07-26T19:27:28.278161Z"
}
},
"outputs": [],
"source": [
@@ -44,7 +41,7 @@
"from ISLP.models import (ModelSpec as MS,\n",
" summarize,\n",
" poly)\n",
"from sklearn.model_selection import train_test_split\n"
"from sklearn.model_selection import train_test_split"
]
},
{
@@ -61,12 +58,11 @@
"id": "2478aeb4",
"metadata": {
"execution": {
"iopub.execute_input": "2023-07-26T05:16:59.820190Z",
"iopub.status.busy": "2023-07-26T05:16:59.819944Z",
"iopub.status.idle": "2023-07-26T05:16:59.822616Z",
"shell.execute_reply": "2023-07-26T05:16:59.822236Z"
},
"lines_to_next_cell": 2
"iopub.execute_input": "2023-07-26T19:27:28.280720Z",
"iopub.status.busy": "2023-07-26T19:27:28.280499Z",
"iopub.status.idle": "2023-07-26T19:27:28.282928Z",
"shell.execute_reply": "2023-07-26T19:27:28.282654Z"
}
},
"outputs": [],
"source": [
@@ -76,7 +72,7 @@
" KFold,\n",
" ShuffleSplit)\n",
"from sklearn.base import clone\n",
"from ISLP.models import sklearn_sm\n"
"from ISLP.models import sklearn_sm"
]
},
{
@@ -96,7 +92,7 @@
"when performing operations like this that contain an\n",
"element of randomness, so that the results obtained can be reproduced\n",
"precisely at a later time. We set the random seed of the splitter\n",
"with the argument `random_state=0`. "
"with the argument `random_state=0`."
]
},
{
@@ -105,10 +101,10 @@
"id": "99c95faf",
"metadata": {
"execution": {
"iopub.execute_input": "2023-07-26T05:16:59.824651Z",
"iopub.status.busy": "2023-07-26T05:16:59.824498Z",
"iopub.status.idle": "2023-07-26T05:16:59.830661Z",
"shell.execute_reply": "2023-07-26T05:16:59.830199Z"
"iopub.execute_input": "2023-07-26T19:27:28.284475Z",
"iopub.status.busy": "2023-07-26T19:27:28.284367Z",
"iopub.status.idle": "2023-07-26T19:27:28.289789Z",
"shell.execute_reply": "2023-07-26T19:27:28.289527Z"
}
},
"outputs": [],
@@ -116,7 +112,7 @@
"Auto = load_data('Auto')\n",
"Auto_train, Auto_valid = train_test_split(Auto,\n",
" test_size=196,\n",
" random_state=0)\n"
" random_state=0)"
]
},
{
@@ -133,10 +129,10 @@
"id": "41b0717d",
"metadata": {
"execution": {
"iopub.execute_input": "2023-07-26T05:16:59.832904Z",
"iopub.status.busy": "2023-07-26T05:16:59.832740Z",
"iopub.status.idle": "2023-07-26T05:16:59.837926Z",
"shell.execute_reply": "2023-07-26T05:16:59.837164Z"
"iopub.execute_input": "2023-07-26T19:27:28.291330Z",
"iopub.status.busy": "2023-07-26T19:27:28.291243Z",
"iopub.status.idle": "2023-07-26T19:27:28.295395Z",
"shell.execute_reply": "2023-07-26T19:27:28.295119Z"
}
},
"outputs": [],
@@ -145,7 +141,7 @@
"X_train = hp_mm.fit_transform(Auto_train)\n",
"y_train = Auto_train['mpg']\n",
"model = sm.OLS(y_train, X_train)\n",
"results = model.fit()\n"
"results = model.fit()"
]
},
{
@@ -163,10 +159,10 @@
"id": "d7ea3c0d",
"metadata": {
"execution": {
"iopub.execute_input": "2023-07-26T05:16:59.840693Z",
"iopub.status.busy": "2023-07-26T05:16:59.840426Z",
"iopub.status.idle": "2023-07-26T05:16:59.847201Z",
"shell.execute_reply": "2023-07-26T05:16:59.846618Z"
"iopub.execute_input": "2023-07-26T19:27:28.296942Z",
"iopub.status.busy": "2023-07-26T19:27:28.296835Z",
"iopub.status.idle": "2023-07-26T19:27:28.301179Z",
"shell.execute_reply": "2023-07-26T19:27:28.300912Z"
}
},
"outputs": [
@@ -185,7 +181,7 @@
"X_valid = hp_mm.transform(Auto_valid)\n",
"y_valid = Auto_valid['mpg']\n",
"valid_pred = results.predict(X_valid)\n",
"np.mean((y_valid - valid_pred)**2)\n"
"np.mean((y_valid - valid_pred)**2)"
]
},
{
@@ -207,10 +203,10 @@
"id": "a02a2d05",
"metadata": {
"execution": {
"iopub.execute_input": "2023-07-26T05:16:59.849828Z",
"iopub.status.busy": "2023-07-26T05:16:59.849638Z",
"iopub.status.idle": "2023-07-26T05:16:59.852938Z",
"shell.execute_reply": "2023-07-26T05:16:59.852364Z"
"iopub.execute_input": "2023-07-26T19:27:28.302713Z",
"iopub.status.busy": "2023-07-26T19:27:28.302612Z",
"iopub.status.idle": "2023-07-26T19:27:28.304865Z",
"shell.execute_reply": "2023-07-26T19:27:28.304576Z"
}
},
"outputs": [],
@@ -230,7 +226,7 @@
" results = sm.OLS(y_train, X_train).fit()\n",
" test_pred = results.predict(X_test)\n",
"\n",
" return np.mean((y_test - test_pred)**2)\n"
" return np.mean((y_test - test_pred)**2)"
]
},
{
@@ -250,10 +246,10 @@
"id": "51d93dea",
"metadata": {
"execution": {
"iopub.execute_input": "2023-07-26T05:16:59.855432Z",
"iopub.status.busy": "2023-07-26T05:16:59.855267Z",
"iopub.status.idle": "2023-07-26T05:16:59.867911Z",
"shell.execute_reply": "2023-07-26T05:16:59.867517Z"
"iopub.execute_input": "2023-07-26T19:27:28.306297Z",
"iopub.status.busy": "2023-07-26T19:27:28.306199Z",
"iopub.status.idle": "2023-07-26T19:27:28.316464Z",
"shell.execute_reply": "2023-07-26T19:27:28.316226Z"
}
},
"outputs": [
@@ -275,7 +271,7 @@
" 'mpg',\n",
" Auto_train,\n",
" Auto_valid)\n",
"MSE\n"
"MSE"
]
},
{
@@ -294,10 +290,10 @@
"id": "83432f06",
"metadata": {
"execution": {
"iopub.execute_input": "2023-07-26T05:16:59.870663Z",
"iopub.status.busy": "2023-07-26T05:16:59.870321Z",
"iopub.status.idle": "2023-07-26T05:16:59.884091Z",
"shell.execute_reply": "2023-07-26T05:16:59.883749Z"
"iopub.execute_input": "2023-07-26T19:27:28.317859Z",
"iopub.status.busy": "2023-07-26T19:27:28.317761Z",
"iopub.status.idle": "2023-07-26T19:27:28.327969Z",
"shell.execute_reply": "2023-07-26T19:27:28.327728Z"
}
},
"outputs": [
@@ -377,12 +373,11 @@
"id": "bcfc433f",
"metadata": {
"execution": {
"iopub.execute_input": "2023-07-26T05:16:59.886618Z",
"iopub.status.busy": "2023-07-26T05:16:59.886459Z",
"iopub.status.idle": "2023-07-26T05:17:00.662796Z",
"shell.execute_reply": "2023-07-26T05:17:00.662228Z"
},
"lines_to_next_cell": 0
"iopub.execute_input": "2023-07-26T19:27:28.329469Z",
"iopub.status.busy": "2023-07-26T19:27:28.329375Z",
"iopub.status.idle": "2023-07-26T19:27:28.889681Z",
"shell.execute_reply": "2023-07-26T19:27:28.889389Z"
}
},
"outputs": [
{
@@ -405,7 +400,7 @@
" Y,\n",
" cv=Auto.shape[0])\n",
"cv_err = np.mean(cv_results['test_score'])\n",
"cv_err\n"
"cv_err"
]
},
{
@@ -445,12 +440,11 @@
"id": "f951ffc8",
"metadata": {
"execution": {
"iopub.execute_input": "2023-07-26T05:17:00.665287Z",
"iopub.status.busy": "2023-07-26T05:17:00.665106Z",
"iopub.status.idle": "2023-07-26T05:17:01.422477Z",
"shell.execute_reply": "2023-07-26T05:17:01.422022Z"
},
"lines_to_next_cell": 0
"iopub.execute_input": "2023-07-26T19:27:28.891330Z",
"iopub.status.busy": "2023-07-26T19:27:28.891213Z",
"iopub.status.idle": "2023-07-26T19:27:29.477436Z",
"shell.execute_reply": "2023-07-26T19:27:29.477151Z"
}
},
"outputs": [
{
@@ -475,7 +469,7 @@
" Y,\n",
" cv=Auto.shape[0])\n",
" cv_error[i] = np.mean(M_CV['test_score'])\n",
"cv_error\n"
"cv_error"
]
},
{
@@ -493,7 +487,7 @@
"It has two arrays as\n",
"arguments, and then forms a larger\n",
"array where the operation is applied to each pair of elements of the\n",
"two arrays. "
"two arrays."
]
},
{
@@ -502,10 +496,10 @@
"id": "e3610b5a",
"metadata": {
"execution": {
"iopub.execute_input": "2023-07-26T05:17:01.424821Z",
"iopub.status.busy": "2023-07-26T05:17:01.424682Z",
"iopub.status.idle": "2023-07-26T05:17:01.427733Z",
"shell.execute_reply": "2023-07-26T05:17:01.427314Z"
"iopub.execute_input": "2023-07-26T19:27:29.479102Z",
"iopub.status.busy": "2023-07-26T19:27:29.478988Z",
"iopub.status.idle": "2023-07-26T19:27:29.481386Z",
"shell.execute_reply": "2023-07-26T19:27:29.481131Z"
}
},
"outputs": [
@@ -525,7 +519,7 @@
"source": [
"A = np.array([3, 5, 9])\n",
"B = np.array([2, 4])\n",
"np.add.outer(A, B)\n"
"np.add.outer(A, B)"
]
},
{
@@ -544,12 +538,11 @@
"id": "1627460d",
"metadata": {
"execution": {
"iopub.execute_input": "2023-07-26T05:17:01.429812Z",
"iopub.status.busy": "2023-07-26T05:17:01.429700Z",
"iopub.status.idle": "2023-07-26T05:17:01.457253Z",
"shell.execute_reply": "2023-07-26T05:17:01.456715Z"
},
"lines_to_next_cell": 0
"iopub.execute_input": "2023-07-26T19:27:29.482898Z",
"iopub.status.busy": "2023-07-26T19:27:29.482801Z",
"iopub.status.idle": "2023-07-26T19:27:29.504137Z",
"shell.execute_reply": "2023-07-26T19:27:29.503881Z"
}
},
"outputs": [
{
@@ -575,7 +568,7 @@
" Y,\n",
" cv=cv)\n",
" cv_error[i] = np.mean(M_CV['test_score'])\n",
"cv_error\n"
"cv_error"
]
},
{
@@ -609,12 +602,11 @@
"id": "8a636468",
"metadata": {
"execution": {
"iopub.execute_input": "2023-07-26T05:17:01.460096Z",
"iopub.status.busy": "2023-07-26T05:17:01.459902Z",
"iopub.status.idle": "2023-07-26T05:17:01.466995Z",
"shell.execute_reply": "2023-07-26T05:17:01.466500Z"
},
"lines_to_next_cell": 2
"iopub.execute_input": "2023-07-26T19:27:29.505802Z",
"iopub.status.busy": "2023-07-26T19:27:29.505691Z",
"iopub.status.idle": "2023-07-26T19:27:29.511368Z",
"shell.execute_reply": "2023-07-26T19:27:29.511053Z"
}
},
"outputs": [
{
@@ -636,7 +628,7 @@
" Auto.drop(['mpg'], axis=1),\n",
" Auto['mpg'],\n",
" cv=validation);\n",
"results['test_score']\n"
"results['test_score']"
]
},
{
@@ -653,10 +645,10 @@
"id": "746aeccd",
"metadata": {
"execution": {
"iopub.execute_input": "2023-07-26T05:17:01.468986Z",
"iopub.status.busy": "2023-07-26T05:17:01.468832Z",
"iopub.status.idle": "2023-07-26T05:17:01.495719Z",
"shell.execute_reply": "2023-07-26T05:17:01.495353Z"
"iopub.execute_input": "2023-07-26T19:27:29.512965Z",
"iopub.status.busy": "2023-07-26T19:27:29.512857Z",
"iopub.status.idle": "2023-07-26T19:27:29.534338Z",
"shell.execute_reply": "2023-07-26T19:27:29.534051Z"
}
},
"outputs": [
@@ -679,7 +671,7 @@
" Auto.drop(['mpg'], axis=1),\n",
" Auto['mpg'],\n",
" cv=validation)\n",
"results['test_score'].mean(), results['test_score'].std()\n"
"results['test_score'].mean(), results['test_score'].std()"
]
},
{
@@ -727,12 +719,11 @@
"id": "daa53d0c",
"metadata": {
"execution": {
"iopub.execute_input": "2023-07-26T05:17:01.498336Z",
"iopub.status.busy": "2023-07-26T05:17:01.498116Z",
"iopub.status.idle": "2023-07-26T05:17:01.504124Z",
"shell.execute_reply": "2023-07-26T05:17:01.503427Z"
},
"lines_to_next_cell": 0
"iopub.execute_input": "2023-07-26T19:27:29.535910Z",
"iopub.status.busy": "2023-07-26T19:27:29.535819Z",
"iopub.status.idle": "2023-07-26T19:27:29.539127Z",
"shell.execute_reply": "2023-07-26T19:27:29.538860Z"
}
},
"outputs": [],
"source": [
@@ -740,7 +731,7 @@
"def alpha_func(D, idx):\n",
" cov_ = np.cov(D[['X','Y']].loc[idx], rowvar=False)\n",
" return ((cov_[1,1] - cov_[0,1]) /\n",
" (cov_[0,0]+cov_[1,1]-2*cov_[0,1]))\n"
" (cov_[0,0]+cov_[1,1]-2*cov_[0,1]))"
]
},
{
@@ -761,10 +752,10 @@
"id": "578c9564",
"metadata": {
"execution": {
"iopub.execute_input": "2023-07-26T05:17:01.507072Z",
"iopub.status.busy": "2023-07-26T05:17:01.506919Z",
"iopub.status.idle": "2023-07-26T05:17:01.510768Z",
"shell.execute_reply": "2023-07-26T05:17:01.510184Z"
"iopub.execute_input": "2023-07-26T19:27:29.540591Z",
"iopub.status.busy": "2023-07-26T19:27:29.540502Z",
"iopub.status.idle": "2023-07-26T19:27:29.543480Z",
"shell.execute_reply": "2023-07-26T19:27:29.543192Z"
}
},
"outputs": [
@@ -800,12 +791,11 @@
"id": "5754d6d5",
"metadata": {
"execution": {
"iopub.execute_input": "2023-07-26T05:17:01.512875Z",
"iopub.status.busy": "2023-07-26T05:17:01.512759Z",
"iopub.status.idle": "2023-07-26T05:17:01.516640Z",
"shell.execute_reply": "2023-07-26T05:17:01.516258Z"
},
"lines_to_next_cell": 2
"iopub.execute_input": "2023-07-26T19:27:29.544876Z",
"iopub.status.busy": "2023-07-26T19:27:29.544785Z",
"iopub.status.idle": "2023-07-26T19:27:29.548136Z",
"shell.execute_reply": "2023-07-26T19:27:29.547873Z"
}
},
"outputs": [
{
@@ -843,12 +833,11 @@
"id": "8320a49c",
"metadata": {
"execution": {
"iopub.execute_input": "2023-07-26T05:17:01.519014Z",
"iopub.status.busy": "2023-07-26T05:17:01.518877Z",
"iopub.status.idle": "2023-07-26T05:17:01.521841Z",
"shell.execute_reply": "2023-07-26T05:17:01.521433Z"
},
"lines_to_next_cell": 0
"iopub.execute_input": "2023-07-26T19:27:29.549543Z",
"iopub.status.busy": "2023-07-26T19:27:29.549456Z",
"iopub.status.idle": "2023-07-26T19:27:29.551815Z",
"shell.execute_reply": "2023-07-26T19:27:29.551542Z"
}
},
"outputs": [],
"source": [
@@ -879,7 +868,7 @@
"unimportant and simply makes sure the loop is executed `B` times.\n",
"\n",
"Let’s use our function to evaluate the accuracy of our\n",
"estimate of $\\alpha$ using $B=1{,}000$ bootstrap replications. "
"estimate of $\\alpha$ using $B=1{,}000$ bootstrap replications."
]
},
{
@@ -888,10 +877,10 @@
"id": "e656aa1f",
"metadata": {
"execution": {
"iopub.execute_input": "2023-07-26T05:17:01.523933Z",
"iopub.status.busy": "2023-07-26T05:17:01.523801Z",
"iopub.status.idle": "2023-07-26T05:17:01.855578Z",
"shell.execute_reply": "2023-07-26T05:17:01.855121Z"
"iopub.execute_input": "2023-07-26T19:27:29.553209Z",
"iopub.status.busy": "2023-07-26T19:27:29.553118Z",
"iopub.status.idle": "2023-07-26T19:27:29.837271Z",
"shell.execute_reply": "2023-07-26T19:27:29.836983Z"
}
},
"outputs": [
@@ -911,7 +900,7 @@
" Portfolio,\n",
" B=1000,\n",
" seed=0)\n",
"alpha_SE\n"
"alpha_SE"
]
},
{
@@ -954,12 +943,11 @@
"id": "c5d14195",
"metadata": {
"execution": {
"iopub.execute_input": "2023-07-26T05:17:01.857907Z",
"iopub.status.busy": "2023-07-26T05:17:01.857723Z",
"iopub.status.idle": "2023-07-26T05:17:01.860405Z",
"shell.execute_reply": "2023-07-26T05:17:01.859990Z"
},
"lines_to_next_cell": 0
"iopub.execute_input": "2023-07-26T19:27:29.838930Z",
"iopub.status.busy": "2023-07-26T19:27:29.838793Z",
"iopub.status.idle": "2023-07-26T19:27:29.840975Z",
"shell.execute_reply": "2023-07-26T19:27:29.840683Z"
}
},
"outputs": [],
"source": [
@@ -989,16 +977,15 @@
"id": "7e0523f0",
"metadata": {
"execution": {
"iopub.execute_input": "2023-07-26T05:17:01.862645Z",
"iopub.status.busy": "2023-07-26T05:17:01.862482Z",
"iopub.status.idle": "2023-07-26T05:17:01.864654Z",
"shell.execute_reply": "2023-07-26T05:17:01.864299Z"
},
"lines_to_next_cell": 0
"iopub.execute_input": "2023-07-26T19:27:29.842453Z",
"iopub.status.busy": "2023-07-26T19:27:29.842355Z",
"iopub.status.idle": "2023-07-26T19:27:29.844134Z",
"shell.execute_reply": "2023-07-26T19:27:29.843887Z"
}
},
"outputs": [],
"source": [
"hp_func = partial(boot_OLS, MS(['horsepower']), 'mpg')\n"
"hp_func = partial(boot_OLS, MS(['horsepower']), 'mpg')"
]
},
{
@@ -1022,12 +1009,11 @@
"id": "32836e93",
"metadata": {
"execution": {
"iopub.execute_input": "2023-07-26T05:17:01.866661Z",
"iopub.status.busy": "2023-07-26T05:17:01.866518Z",
"iopub.status.idle": "2023-07-26T05:17:01.885141Z",
"shell.execute_reply": "2023-07-26T05:17:01.884669Z"
},
"lines_to_next_cell": 0
"iopub.execute_input": "2023-07-26T19:27:29.845545Z",
"iopub.status.busy": "2023-07-26T19:27:29.845443Z",
"iopub.status.idle": "2023-07-26T19:27:29.860387Z",
"shell.execute_reply": "2023-07-26T19:27:29.860140Z"
}
},
"outputs": [
{
@@ -1055,7 +1041,7 @@
"np.array([hp_func(Auto,\n",
" rng.choice(392,\n",
" 392,\n",
" replace=True)) for _ in range(10)])\n"
" replace=True)) for _ in range(10)])"
]
},
{
@@ -1073,12 +1059,11 @@
"id": "14ce3afa",
"metadata": {
"execution": {
"iopub.execute_input": "2023-07-26T05:17:01.887739Z",
"iopub.status.busy": "2023-07-26T05:17:01.887564Z",
"iopub.status.idle": "2023-07-26T05:17:03.352633Z",
"shell.execute_reply": "2023-07-26T05:17:03.352273Z"
},
"lines_to_next_cell": 2
"iopub.execute_input": "2023-07-26T19:27:29.861819Z",
"iopub.status.busy": "2023-07-26T19:27:29.861721Z",
"iopub.status.idle": "2023-07-26T19:27:31.013897Z",
"shell.execute_reply": "2023-07-26T19:27:31.013532Z"
}
},
"outputs": [
{
@@ -1099,7 +1084,7 @@
" Auto,\n",
" B=1000,\n",
" seed=10)\n",
"hp_se\n"
"hp_se"
]
},
{
@@ -1123,12 +1108,11 @@
"id": "6b1213ac",
"metadata": {
"execution": {
"iopub.execute_input": "2023-07-26T05:17:03.356355Z",
"iopub.status.busy": "2023-07-26T05:17:03.356184Z",
"iopub.status.idle": "2023-07-26T05:17:03.453023Z",
"shell.execute_reply": "2023-07-26T05:17:03.452622Z"
},
"lines_to_next_cell": 2
"iopub.execute_input": "2023-07-26T19:27:31.015545Z",
"iopub.status.busy": "2023-07-26T19:27:31.015428Z",
"iopub.status.idle": "2023-07-26T19:27:31.077742Z",
"shell.execute_reply": "2023-07-26T19:27:31.077471Z"
}
},
"outputs": [
{
@@ -1147,7 +1131,7 @@
"source": [
"hp_model.fit(Auto, Auto['mpg'])\n",
"model_se = summarize(hp_model.results_)['std err']\n",
"model_se\n"
"model_se"
]
},
{
@@ -1195,10 +1179,10 @@
"id": "af99b778",
"metadata": {
"execution": {
"iopub.execute_input": "2023-07-26T05:17:03.455469Z",
"iopub.status.busy": "2023-07-26T05:17:03.455201Z",
"iopub.status.idle": "2023-07-26T05:17:05.757186Z",
"shell.execute_reply": "2023-07-26T05:17:05.756703Z"
"iopub.execute_input": "2023-07-26T19:27:31.079381Z",
"iopub.status.busy": "2023-07-26T19:27:31.079238Z",
"iopub.status.idle": "2023-07-26T19:27:32.849869Z",
"shell.execute_reply": "2023-07-26T19:27:32.849577Z"
}
},
"outputs": [
@@ -1221,7 +1205,7 @@
"quad_func = partial(boot_OLS,\n",
" quad_model,\n",
" 'mpg')\n",
"boot_SE(quad_func, Auto, B=1000)\n"
"boot_SE(quad_func, Auto, B=1000)"
]
},
{
@@ -1238,12 +1222,11 @@
"id": "0206281e",
"metadata": {
"execution": {
"iopub.execute_input": "2023-07-26T05:17:05.759524Z",
"iopub.status.busy": "2023-07-26T05:17:05.759220Z",
"iopub.status.idle": "2023-07-26T05:17:05.769493Z",
"shell.execute_reply": "2023-07-26T05:17:05.768995Z"
},
"lines_to_next_cell": 0
"iopub.execute_input": "2023-07-26T19:27:32.851478Z",
"iopub.status.busy": "2023-07-26T19:27:32.851368Z",
"iopub.status.idle": "2023-07-26T19:27:32.860591Z",
"shell.execute_reply": "2023-07-26T19:27:32.860334Z"
}
},
"outputs": [
{
@@ -1263,24 +1246,15 @@
"source": [
"M = sm.OLS(Auto['mpg'],\n",
" quad_model.fit_transform(Auto))\n",
"summarize(M.fit())['std err']\n"
]
},
{
"cell_type": "markdown",
"id": "0c11a71f",
"metadata": {},
"source": [
"\n",
"\n"
"summarize(M.fit())['std err']"
]
}
],
"metadata": {
"jupytext": {
"cell_metadata_filter": "-all",
"main_language": "python",
"notebook_metadata_filter": "-all"
"formats": "ipynb,md:myst",
"main_language": "python"
},
"language_info": {
"codemirror_mode": {
@@ -1292,7 +1266,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.9.17"
"version": "3.11.4"
}
},
"nbformat": 4,
+3640 -3679
View File
File diff suppressed because it is too large. Load diff
+288 -348
View File
File diff suppressed because it is too large. Load diff
+213 -273
View File
@@ -5,9 +5,7 @@
"id": "7b0242c6",
"metadata": {},
"source": [
"\n",
"# Chapter 8\n",
"\n"
"# Chapter 8"
]
},
{
@@ -26,12 +24,11 @@
"id": "4cc7120f",
"metadata": {
"execution": {
"iopub.execute_input": "2023-07-26T05:17:41.271445Z",
"iopub.status.busy": "2023-07-26T05:17:41.271226Z",
"iopub.status.idle": "2023-07-26T05:17:42.756473Z",
"shell.execute_reply": "2023-07-26T05:17:42.756027Z"
},
"lines_to_next_cell": 0
"iopub.execute_input": "2023-07-26T19:30:05.371862Z",
"iopub.status.busy": "2023-07-26T19:30:05.371761Z",
"iopub.status.idle": "2023-07-26T19:30:06.605449Z",
"shell.execute_reply": "2023-07-26T19:30:06.604954Z"
}
},
"outputs": [],
"source": [
@@ -41,7 +38,7 @@
"from statsmodels.datasets import get_rdataset\n",
"import sklearn.model_selection as skm\n",
"from ISLP import load_data, confusion_table\n",
"from ISLP.models import ModelSpec as MS\n"
"from ISLP.models import ModelSpec as MS"
]
},
{
@@ -59,12 +56,11 @@
"id": "864fa15e",
"metadata": {
"execution": {
"iopub.execute_input": "2023-07-26T05:17:42.759051Z",
"iopub.status.busy": "2023-07-26T05:17:42.758860Z",
"iopub.status.idle": "2023-07-26T05:17:42.832228Z",
"shell.execute_reply": "2023-07-26T05:17:42.831597Z"
},
"lines_to_next_cell": 2
"iopub.execute_input": "2023-07-26T19:30:06.609335Z",
"iopub.status.busy": "2023-07-26T19:30:06.609115Z",
"iopub.status.idle": "2023-07-26T19:30:07.729911Z",
"shell.execute_reply": "2023-07-26T19:30:07.729621Z"
}
},
"outputs": [],
"source": [
@@ -77,7 +73,7 @@
"from sklearn.ensemble import \\\n",
" (RandomForestRegressor as RF,\n",
" GradientBoostingRegressor as GBR)\n",
"from ISLP.bart import BART\n"
"from ISLP.bart import BART"
]
},
{
@@ -107,10 +103,10 @@
"id": "bfb4c83b",
"metadata": {
"execution": {
"iopub.execute_input": "2023-07-26T05:17:42.836883Z",
"iopub.status.busy": "2023-07-26T05:17:42.836681Z",
"iopub.status.idle": "2023-07-26T05:17:42.843170Z",
"shell.execute_reply": "2023-07-26T05:17:42.842647Z"
"iopub.execute_input": "2023-07-26T19:30:07.731837Z",
"iopub.status.busy": "2023-07-26T19:30:07.731719Z",
"iopub.status.idle": "2023-07-26T19:30:07.737155Z",
"shell.execute_reply": "2023-07-26T19:30:07.736878Z"
}
},
"outputs": [],
@@ -118,7 +114,7 @@
"Carseats = load_data('Carseats')\n",
"High = np.where(Carseats.Sales > 8,\n",
" \"Yes\",\n",
" \"No\")\n"
" \"No\")"
]
},
{
@@ -129,7 +125,7 @@
"We now use `DecisionTreeClassifier()` to fit a classification tree in\n",
"order to predict `High` using all variables but `Sales`.\n",
"To do so, we must form a model matrix as we did when fitting regression\n",
"models. "
"models."
]
},
{
@@ -138,19 +134,18 @@
"id": "5d9e7a14",
"metadata": {
"execution": {
"iopub.execute_input": "2023-07-26T05:17:42.845711Z",
"iopub.status.busy": "2023-07-26T05:17:42.845521Z",
"iopub.status.idle": "2023-07-26T05:17:42.856897Z",
"shell.execute_reply": "2023-07-26T05:17:42.856518Z"
},
"lines_to_next_cell": 0
"iopub.execute_input": "2023-07-26T19:30:07.738707Z",
"iopub.status.busy": "2023-07-26T19:30:07.738605Z",
"iopub.status.idle": "2023-07-26T19:30:07.748329Z",
"shell.execute_reply": "2023-07-26T19:30:07.748075Z"
}
},
"outputs": [],
"source": [
"model = MS(Carseats.columns.drop('Sales'), intercept=False)\n",
"D = model.fit_transform(Carseats)\n",
"feature_names = list(D.columns)\n",
"X = np.asarray(D)\n"
"X = np.asarray(D)"
]
},
{
@@ -173,18 +168,17 @@
"id": "970c4515",
"metadata": {
"execution": {
"iopub.execute_input": "2023-07-26T05:17:42.859418Z",
"iopub.status.busy": "2023-07-26T05:17:42.859055Z",
"iopub.status.idle": "2023-07-26T05:17:42.866816Z",
"shell.execute_reply": "2023-07-26T05:17:42.866395Z"
},
"lines_to_next_cell": 2
"iopub.execute_input": "2023-07-26T19:30:07.749816Z",
"iopub.status.busy": "2023-07-26T19:30:07.749731Z",
"iopub.status.idle": "2023-07-26T19:30:07.755256Z",
"shell.execute_reply": "2023-07-26T19:30:07.754986Z"
}
},
"outputs": [
{
"data": {
"text/html": [
"<style>#sk-container-id-1 {color: black;background-color: white;}#sk-container-id-1 pre{padding: 0;}#sk-container-id-1 div.sk-toggleable {background-color: white;}#sk-container-id-1 label.sk-toggleable__label {cursor: pointer;display: block;width: 100%;margin-bottom: 0;padding: 0.3em;box-sizing: border-box;text-align: center;}#sk-container-id-1 label.sk-toggleable__label-arrow:before {content: \"▸\";float: left;margin-right: 0.25em;color: #696969;}#sk-container-id-1 label.sk-toggleable__label-arrow:hover:before {color: black;}#sk-container-id-1 div.sk-estimator:hover label.sk-toggleable__label-arrow:before {color: black;}#sk-container-id-1 div.sk-toggleable__content {max-height: 0;max-width: 0;overflow: hidden;text-align: left;background-color: #f0f8ff;}#sk-container-id-1 div.sk-toggleable__content pre {margin: 0.2em;color: black;border-radius: 0.25em;background-color: #f0f8ff;}#sk-container-id-1 input.sk-toggleable__control:checked~div.sk-toggleable__content {max-height: 200px;max-width: 100%;overflow: auto;}#sk-container-id-1 input.sk-toggleable__control:checked~label.sk-toggleable__label-arrow:before {content: \"▾\";}#sk-container-id-1 div.sk-estimator input.sk-toggleable__control:checked~label.sk-toggleable__label {background-color: #d4ebff;}#sk-container-id-1 div.sk-label input.sk-toggleable__control:checked~label.sk-toggleable__label {background-color: #d4ebff;}#sk-container-id-1 input.sk-hidden--visually {border: 0;clip: rect(1px 1px 1px 1px);clip: rect(1px, 1px, 1px, 1px);height: 1px;margin: -1px;overflow: hidden;padding: 0;position: absolute;width: 1px;}#sk-container-id-1 div.sk-estimator {font-family: monospace;background-color: #f0f8ff;border: 1px dotted black;border-radius: 0.25em;box-sizing: border-box;margin-bottom: 0.5em;}#sk-container-id-1 div.sk-estimator:hover {background-color: #d4ebff;}#sk-container-id-1 div.sk-parallel-item::after {content: \"\";width: 100%;border-bottom: 1px solid gray;flex-grow: 1;}#sk-container-id-1 div.sk-label:hover label.sk-toggleable__label {background-color: #d4ebff;}#sk-container-id-1 div.sk-serial::before {content: \"\";position: absolute;border-left: 1px solid gray;box-sizing: border-box;top: 0;bottom: 0;left: 50%;z-index: 0;}#sk-container-id-1 div.sk-serial {display: flex;flex-direction: column;align-items: center;background-color: white;padding-right: 0.2em;padding-left: 0.2em;position: relative;}#sk-container-id-1 div.sk-item {position: relative;z-index: 1;}#sk-container-id-1 div.sk-parallel {display: flex;align-items: stretch;justify-content: center;background-color: white;position: relative;}#sk-container-id-1 div.sk-item::before, #sk-container-id-1 div.sk-parallel-item::before {content: \"\";position: absolute;border-left: 1px solid gray;box-sizing: border-box;top: 0;bottom: 0;left: 50%;z-index: -1;}#sk-container-id-1 div.sk-parallel-item {display: flex;flex-direction: column;z-index: 1;position: relative;background-color: white;}#sk-container-id-1 div.sk-parallel-item:first-child::after {align-self: flex-end;width: 50%;}#sk-container-id-1 div.sk-parallel-item:last-child::after {align-self: flex-start;width: 50%;}#sk-container-id-1 div.sk-parallel-item:only-child::after {width: 0;}#sk-container-id-1 div.sk-dashed-wrapped {border: 1px dashed gray;margin: 0 0.4em 0.5em 0.4em;box-sizing: border-box;padding-bottom: 0.4em;background-color: white;}#sk-container-id-1 div.sk-label label {font-family: monospace;font-weight: bold;display: inline-block;line-height: 1.2em;}#sk-container-id-1 div.sk-label-container {text-align: center;}#sk-container-id-1 div.sk-container {/* jupyter's `normalize.less` sets `[hidden] { display: none; }` but bootstrap.min.css set `[hidden] { display: none !important; }` so we also need the `!important` here to be able to override the default hidden behavior on the sphinx rendered scikit-learn.org. See: https://github.com/scikit-learn/scikit-learn/issues/21755 */display: inline-block !important;position: relative;}#sk-container-id-1 div.sk-text-repr-fallback {display: none;}</style><div id=\"sk-container-id-1\" class=\"sk-top-container\"><div class=\"sk-text-repr-fallback\"><pre>DecisionTreeClassifier(criterion=&#x27;entropy&#x27;, max_depth=3, random_state=0)</pre><b>In a Jupyter environment, please rerun this cell to show the HTML representation or trust the notebook. <br />On GitHub, the HTML representation is unable to render, please try loading this page with nbviewer.org.</b></div><div class=\"sk-container\" hidden><div class=\"sk-item\"><div class=\"sk-estimator sk-toggleable\"><input class=\"sk-toggleable__control sk-hidden--visually\" id=\"sk-estimator-id-1\" type=\"checkbox\" checked><label for=\"sk-estimator-id-1\" class=\"sk-toggleable__label sk-toggleable__label-arrow\">DecisionTreeClassifier</label><div class=\"sk-toggleable__content\"><pre>DecisionTreeClassifier(criterion=&#x27;entropy&#x27;, max_depth=3, random_state=0)</pre></div></div></div></div></div>"
"<style>#sk-container-id-1 {color: black;}#sk-container-id-1 pre{padding: 0;}#sk-container-id-1 div.sk-toggleable {background-color: white;}#sk-container-id-1 label.sk-toggleable__label {cursor: pointer;display: block;width: 100%;margin-bottom: 0;padding: 0.3em;box-sizing: border-box;text-align: center;}#sk-container-id-1 label.sk-toggleable__label-arrow:before {content: \"▸\";float: left;margin-right: 0.25em;color: #696969;}#sk-container-id-1 label.sk-toggleable__label-arrow:hover:before {color: black;}#sk-container-id-1 div.sk-estimator:hover label.sk-toggleable__label-arrow:before {color: black;}#sk-container-id-1 div.sk-toggleable__content {max-height: 0;max-width: 0;overflow: hidden;text-align: left;background-color: #f0f8ff;}#sk-container-id-1 div.sk-toggleable__content pre {margin: 0.2em;color: black;border-radius: 0.25em;background-color: #f0f8ff;}#sk-container-id-1 input.sk-toggleable__control:checked~div.sk-toggleable__content {max-height: 200px;max-width: 100%;overflow: auto;}#sk-container-id-1 input.sk-toggleable__control:checked~label.sk-toggleable__label-arrow:before {content: \"▾\";}#sk-container-id-1 div.sk-estimator input.sk-toggleable__control:checked~label.sk-toggleable__label {background-color: #d4ebff;}#sk-container-id-1 div.sk-label input.sk-toggleable__control:checked~label.sk-toggleable__label {background-color: #d4ebff;}#sk-container-id-1 input.sk-hidden--visually {border: 0;clip: rect(1px 1px 1px 1px);clip: rect(1px, 1px, 1px, 1px);height: 1px;margin: -1px;overflow: hidden;padding: 0;position: absolute;width: 1px;}#sk-container-id-1 div.sk-estimator {font-family: monospace;background-color: #f0f8ff;border: 1px dotted black;border-radius: 0.25em;box-sizing: border-box;margin-bottom: 0.5em;}#sk-container-id-1 div.sk-estimator:hover {background-color: #d4ebff;}#sk-container-id-1 div.sk-parallel-item::after {content: \"\";width: 100%;border-bottom: 1px solid gray;flex-grow: 1;}#sk-container-id-1 div.sk-label:hover label.sk-toggleable__label {background-color: #d4ebff;}#sk-container-id-1 div.sk-serial::before {content: \"\";position: absolute;border-left: 1px solid gray;box-sizing: border-box;top: 0;bottom: 0;left: 50%;z-index: 0;}#sk-container-id-1 div.sk-serial {display: flex;flex-direction: column;align-items: center;background-color: white;padding-right: 0.2em;padding-left: 0.2em;position: relative;}#sk-container-id-1 div.sk-item {position: relative;z-index: 1;}#sk-container-id-1 div.sk-parallel {display: flex;align-items: stretch;justify-content: center;background-color: white;position: relative;}#sk-container-id-1 div.sk-item::before, #sk-container-id-1 div.sk-parallel-item::before {content: \"\";position: absolute;border-left: 1px solid gray;box-sizing: border-box;top: 0;bottom: 0;left: 50%;z-index: -1;}#sk-container-id-1 div.sk-parallel-item {display: flex;flex-direction: column;z-index: 1;position: relative;background-color: white;}#sk-container-id-1 div.sk-parallel-item:first-child::after {align-self: flex-end;width: 50%;}#sk-container-id-1 div.sk-parallel-item:last-child::after {align-self: flex-start;width: 50%;}#sk-container-id-1 div.sk-parallel-item:only-child::after {width: 0;}#sk-container-id-1 div.sk-dashed-wrapped {border: 1px dashed gray;margin: 0 0.4em 0.5em 0.4em;box-sizing: border-box;padding-bottom: 0.4em;background-color: white;}#sk-container-id-1 div.sk-label label {font-family: monospace;font-weight: bold;display: inline-block;line-height: 1.2em;}#sk-container-id-1 div.sk-label-container {text-align: center;}#sk-container-id-1 div.sk-container {/* jupyter's `normalize.less` sets `[hidden] { display: none; }` but bootstrap.min.css set `[hidden] { display: none !important; }` so we also need the `!important` here to be able to override the default hidden behavior on the sphinx rendered scikit-learn.org. See: https://github.com/scikit-learn/scikit-learn/issues/21755 */display: inline-block !important;position: relative;}#sk-container-id-1 div.sk-text-repr-fallback {display: none;}</style><div id=\"sk-container-id-1\" class=\"sk-top-container\"><div class=\"sk-text-repr-fallback\"><pre>DecisionTreeClassifier(criterion=&#x27;entropy&#x27;, max_depth=3, random_state=0)</pre><b>In a Jupyter environment, please rerun this cell to show the HTML representation or trust the notebook. <br />On GitHub, the HTML representation is unable to render, please try loading this page with nbviewer.org.</b></div><div class=\"sk-container\" hidden><div class=\"sk-item\"><div class=\"sk-estimator sk-toggleable\"><input class=\"sk-toggleable__control sk-hidden--visually\" id=\"sk-estimator-id-1\" type=\"checkbox\" checked><label for=\"sk-estimator-id-1\" class=\"sk-toggleable__label sk-toggleable__label-arrow\">DecisionTreeClassifier</label><div class=\"sk-toggleable__content\"><pre>DecisionTreeClassifier(criterion=&#x27;entropy&#x27;, max_depth=3, random_state=0)</pre></div></div></div></div></div>"
],
"text/plain": [
"DecisionTreeClassifier(criterion='entropy', max_depth=3, random_state=0)"
@@ -199,7 +193,7 @@
"clf = DTC(criterion='entropy',\n",
" max_depth=3,\n",
" random_state=0) \n",
"clf.fit(X, High)\n"
"clf.fit(X, High)"
]
},
{
@@ -225,12 +219,11 @@
"id": "2d9a51dc",
"metadata": {
"execution": {
"iopub.execute_input": "2023-07-26T05:17:42.868805Z",
"iopub.status.busy": "2023-07-26T05:17:42.868636Z",
"iopub.status.idle": "2023-07-26T05:17:42.872257Z",
"shell.execute_reply": "2023-07-26T05:17:42.871848Z"
},
"lines_to_next_cell": 2
"iopub.execute_input": "2023-07-26T19:30:07.756809Z",
"iopub.status.busy": "2023-07-26T19:30:07.756708Z",
"iopub.status.idle": "2023-07-26T19:30:07.759541Z",
"shell.execute_reply": "2023-07-26T19:30:07.759278Z"
}
},
"outputs": [
{
@@ -245,7 +238,7 @@
}
],
"source": [
"accuracy_score(High, clf.predict(X))\n"
"accuracy_score(High, clf.predict(X))"
]
},
{
@@ -272,10 +265,10 @@
"id": "cbc04b67",
"metadata": {
"execution": {
"iopub.execute_input": "2023-07-26T05:17:42.874181Z",
"iopub.status.busy": "2023-07-26T05:17:42.874073Z",
"iopub.status.idle": "2023-07-26T05:17:42.878254Z",
"shell.execute_reply": "2023-07-26T05:17:42.877678Z"
"iopub.execute_input": "2023-07-26T19:30:07.760932Z",
"iopub.status.busy": "2023-07-26T19:30:07.760834Z",
"iopub.status.idle": "2023-07-26T19:30:07.763865Z",
"shell.execute_reply": "2023-07-26T19:30:07.763631Z"
}
},
"outputs": [
@@ -292,7 +285,7 @@
],
"source": [
"resid_dev = np.sum(log_loss(High, clf.predict_proba(X)))\n",
"resid_dev\n"
"resid_dev"
]
},
{
@@ -315,12 +308,11 @@
"id": "809830c7",
"metadata": {
"execution": {
"iopub.execute_input": "2023-07-26T05:17:42.880423Z",
"iopub.status.busy": "2023-07-26T05:17:42.880256Z",
"iopub.status.idle": "2023-07-26T05:17:43.233297Z",
"shell.execute_reply": "2023-07-26T05:17:43.232754Z"
},
"lines_to_next_cell": 0
"iopub.execute_input": "2023-07-26T19:30:07.765342Z",
"iopub.status.busy": "2023-07-26T19:30:07.765257Z",
"iopub.status.idle": "2023-07-26T19:30:08.091241Z",
"shell.execute_reply": "2023-07-26T19:30:08.090308Z"
}
},
"outputs": [
{
@@ -338,7 +330,7 @@
"ax = subplots(figsize=(12,12))[1]\n",
"plot_tree(clf,\n",
" feature_names=feature_names,\n",
" ax=ax);\n"
" ax=ax);"
]
},
{
@@ -363,10 +355,10 @@
"id": "abe8c7fc",
"metadata": {
"execution": {
"iopub.execute_input": "2023-07-26T05:17:43.235787Z",
"iopub.status.busy": "2023-07-26T05:17:43.235629Z",
"iopub.status.idle": "2023-07-26T05:17:43.238645Z",
"shell.execute_reply": "2023-07-26T05:17:43.238197Z"
"iopub.execute_input": "2023-07-26T19:30:08.097796Z",
"iopub.status.busy": "2023-07-26T19:30:08.094873Z",
"iopub.status.idle": "2023-07-26T19:30:08.105509Z",
"shell.execute_reply": "2023-07-26T19:30:08.103339Z"
}
},
"outputs": [
@@ -403,7 +395,7 @@
"source": [
"print(export_text(clf,\n",
" feature_names=feature_names,\n",
" show_weights=True))\n"
" show_weights=True))"
]
},
{
@@ -428,12 +420,11 @@
"id": "f7a1f736",
"metadata": {
"execution": {
"iopub.execute_input": "2023-07-26T05:17:43.241246Z",
"iopub.status.busy": "2023-07-26T05:17:43.241128Z",
"iopub.status.idle": "2023-07-26T05:17:43.248339Z",
"shell.execute_reply": "2023-07-26T05:17:43.247882Z"
},
"lines_to_next_cell": 0
"iopub.execute_input": "2023-07-26T19:30:08.109547Z",
"iopub.status.busy": "2023-07-26T19:30:08.109034Z",
"iopub.status.idle": "2023-07-26T19:30:08.130343Z",
"shell.execute_reply": "2023-07-26T19:30:08.122380Z"
}
},
"outputs": [
{
@@ -455,15 +446,7 @@
" D,\n",
" High,\n",
" cv=validation)\n",
"results['test_score']\n"
]
},
{
"cell_type": "markdown",
"id": "257f1382",
"metadata": {},
"source": [
" "
"results['test_score']"
]
},
{
@@ -484,12 +467,11 @@
"id": "c663a623",
"metadata": {
"execution": {
"iopub.execute_input": "2023-07-26T05:17:43.250854Z",
"iopub.status.busy": "2023-07-26T05:17:43.250675Z",
"iopub.status.idle": "2023-07-26T05:17:43.253625Z",
"shell.execute_reply": "2023-07-26T05:17:43.253117Z"
},
"lines_to_next_cell": 0
"iopub.execute_input": "2023-07-26T19:30:08.134846Z",
"iopub.status.busy": "2023-07-26T19:30:08.134383Z",
"iopub.status.idle": "2023-07-26T19:30:08.139441Z",
"shell.execute_reply": "2023-07-26T19:30:08.138407Z"
}
},
"outputs": [],
"source": [
@@ -508,7 +490,7 @@
"id": "9e618049",
"metadata": {},
"source": [
"We first refit the full tree on the training set; here we do not set a `max_depth` parameter, since we will learn that through cross-validation.\n"
"We first refit the full tree on the training set; here we do not set a `max_depth` parameter, since we will learn that through cross-validation."
]
},
{
@@ -517,12 +499,11 @@
"id": "c2f2a403",
"metadata": {
"execution": {
"iopub.execute_input": "2023-07-26T05:17:43.256072Z",
"iopub.status.busy": "2023-07-26T05:17:43.255891Z",
"iopub.status.idle": "2023-07-26T05:17:43.261392Z",
"shell.execute_reply": "2023-07-26T05:17:43.260822Z"
},
"lines_to_next_cell": 0
"iopub.execute_input": "2023-07-26T19:30:08.142863Z",
"iopub.status.busy": "2023-07-26T19:30:08.142428Z",
"iopub.status.idle": "2023-07-26T19:30:08.151177Z",
"shell.execute_reply": "2023-07-26T19:30:08.150610Z"
}
},
"outputs": [
{
@@ -539,7 +520,7 @@
"source": [
"clf = DTC(criterion='entropy', random_state=0)\n",
"clf.fit(X_train, High_train)\n",
"accuracy_score(High_test, clf.predict(X_test))\n"
"accuracy_score(High_test, clf.predict(X_test))"
]
},
{
@@ -548,7 +529,7 @@
"metadata": {},
"source": [
"Next we use the `cost_complexity_pruning_path()` method of\n",
"`clf` to extract cost-complexity values. "
"`clf` to extract cost-complexity values."
]
},
{
@@ -557,19 +538,18 @@
"id": "b2505658",
"metadata": {
"execution": {
"iopub.execute_input": "2023-07-26T05:17:43.264289Z",
"iopub.status.busy": "2023-07-26T05:17:43.264075Z",
"iopub.status.idle": "2023-07-26T05:17:43.268404Z",
"shell.execute_reply": "2023-07-26T05:17:43.267912Z"
},
"lines_to_next_cell": 0
"iopub.execute_input": "2023-07-26T19:30:08.154527Z",
"iopub.status.busy": "2023-07-26T19:30:08.154214Z",
"iopub.status.idle": "2023-07-26T19:30:08.162522Z",
"shell.execute_reply": "2023-07-26T19:30:08.161407Z"
}
},
"outputs": [],
"source": [
"ccp_path = clf.cost_complexity_pruning_path(X_train, High_train)\n",
"kfold = skm.KFold(10,\n",
" random_state=1,\n",
" shuffle=True)\n"
" shuffle=True)"
]
},
{
@@ -587,12 +567,11 @@
"id": "09a7bd33",
"metadata": {
"execution": {
"iopub.execute_input": "2023-07-26T05:17:43.270876Z",
"iopub.status.busy": "2023-07-26T05:17:43.270706Z",
"iopub.status.idle": "2023-07-26T05:17:43.553527Z",
"shell.execute_reply": "2023-07-26T05:17:43.553080Z"
},
"lines_to_next_cell": 0
"iopub.execute_input": "2023-07-26T19:30:08.166296Z",
"iopub.status.busy": "2023-07-26T19:30:08.166071Z",
"iopub.status.idle": "2023-07-26T19:30:08.436619Z",
"shell.execute_reply": "2023-07-26T19:30:08.436306Z"
}
},
"outputs": [
{
@@ -613,7 +592,7 @@
" cv=kfold,\n",
" scoring='accuracy')\n",
"grid.fit(X_train, High_train)\n",
"grid.best_score_\n"
"grid.best_score_"
]
},
{
@@ -630,12 +609,11 @@
"id": "a75dea32",
"metadata": {
"execution": {
"iopub.execute_input": "2023-07-26T05:17:43.556004Z",
"iopub.status.busy": "2023-07-26T05:17:43.555851Z",
"iopub.status.idle": "2023-07-26T05:17:44.479893Z",
"shell.execute_reply": "2023-07-26T05:17:44.479062Z"
},
"lines_to_next_cell": 0
"iopub.execute_input": "2023-07-26T19:30:08.438243Z",
"iopub.status.busy": "2023-07-26T19:30:08.438132Z",
"iopub.status.idle": "2023-07-26T19:30:09.201634Z",
"shell.execute_reply": "2023-07-26T19:30:09.201311Z"
}
},
"outputs": [
{
@@ -654,7 +632,7 @@
"best_ = grid.best_estimator_\n",
"plot_tree(best_,\n",
" feature_names=feature_names,\n",
" ax=ax);\n"
" ax=ax);"
]
},
{
@@ -672,12 +650,11 @@
"id": "3f1e3d19",
"metadata": {
"execution": {
"iopub.execute_input": "2023-07-26T05:17:44.483391Z",
"iopub.status.busy": "2023-07-26T05:17:44.483211Z",
"iopub.status.idle": "2023-07-26T05:17:44.486537Z",
"shell.execute_reply": "2023-07-26T05:17:44.486111Z"
},
"lines_to_next_cell": 0
"iopub.execute_input": "2023-07-26T19:30:09.203364Z",
"iopub.status.busy": "2023-07-26T19:30:09.203236Z",
"iopub.status.idle": "2023-07-26T19:30:09.205780Z",
"shell.execute_reply": "2023-07-26T19:30:09.205471Z"
}
},
"outputs": [
{
@@ -692,7 +669,7 @@
}
],
"source": [
"best_.tree_.n_leaves\n"
"best_.tree_.n_leaves"
]
},
{
@@ -712,12 +689,11 @@
"id": "30f5c2f9",
"metadata": {
"execution": {
"iopub.execute_input": "2023-07-26T05:17:44.489160Z",
"iopub.status.busy": "2023-07-26T05:17:44.489048Z",
"iopub.status.idle": "2023-07-26T05:17:44.498333Z",
"shell.execute_reply": "2023-07-26T05:17:44.497705Z"
},
"lines_to_next_cell": 2
"iopub.execute_input": "2023-07-26T19:30:09.207457Z",
"iopub.status.busy": "2023-07-26T19:30:09.207344Z",
"iopub.status.idle": "2023-07-26T19:30:09.214183Z",
"shell.execute_reply": "2023-07-26T19:30:09.213886Z"
}
},
"outputs": [
{
@@ -789,7 +765,7 @@
" best_.predict(X_test)))\n",
"confusion = confusion_table(best_.predict(X_test),\n",
" High_test)\n",
"confusion\n"
"confusion"
]
},
{
@@ -797,9 +773,7 @@
"id": "adbe5709",
"metadata": {},
"source": [
"Now 72.0% of the test observations are correctly classified, which is slightly worse than the error for the full tree (with 35 leaves). So cross-validation has not helped us much here; it only pruned off 5 leaves, at a cost of a slightly worse error. These results would change if we were to change the random number seeds above; even though cross-validation gives an unbiased approach to model selection, it does have variance.\n",
"\n",
" "
"Now 72.0% of the test observations are correctly classified, which is slightly worse than the error for the full tree (with 35 leaves). So cross-validation has not helped us much here; it only pruned off 5 leaves, at a cost of a slightly worse error. These results would change if we were to change the random number seeds above; even though cross-validation gives an unbiased approach to model selection, it does have variance."
]
},
{
@@ -818,10 +792,10 @@
"id": "1ca6bc7a",
"metadata": {
"execution": {
"iopub.execute_input": "2023-07-26T05:17:44.500404Z",
"iopub.status.busy": "2023-07-26T05:17:44.500198Z",
"iopub.status.idle": "2023-07-26T05:17:44.510037Z",
"shell.execute_reply": "2023-07-26T05:17:44.509664Z"
"iopub.execute_input": "2023-07-26T19:30:09.215731Z",
"iopub.status.busy": "2023-07-26T19:30:09.215628Z",
"iopub.status.idle": "2023-07-26T19:30:09.223241Z",
"shell.execute_reply": "2023-07-26T19:30:09.222984Z"
}
},
"outputs": [],
@@ -830,7 +804,7 @@
"model = MS(Boston.columns.drop('medv'), intercept=False)\n",
"D = model.fit_transform(Boston)\n",
"feature_names = list(D.columns)\n",
"X = np.asarray(D)\n"
"X = np.asarray(D)"
]
},
{
@@ -839,7 +813,7 @@
"metadata": {},
"source": [
"First, we split the data into training and test sets, and fit the tree\n",
"to the training data. Here we use 30% of the data for the test set.\n"
"to the training data. Here we use 30% of the data for the test set."
]
},
{
@@ -848,10 +822,10 @@
"id": "15cfb553",
"metadata": {
"execution": {
"iopub.execute_input": "2023-07-26T05:17:44.512140Z",
"iopub.status.busy": "2023-07-26T05:17:44.511989Z",
"iopub.status.idle": "2023-07-26T05:17:44.515238Z",
"shell.execute_reply": "2023-07-26T05:17:44.514701Z"
"iopub.execute_input": "2023-07-26T19:30:09.224763Z",
"iopub.status.busy": "2023-07-26T19:30:09.224672Z",
"iopub.status.idle": "2023-07-26T19:30:09.227079Z",
"shell.execute_reply": "2023-07-26T19:30:09.226826Z"
}
},
"outputs": [],
@@ -862,7 +836,7 @@
" y_test) = skm.train_test_split(X,\n",
" Boston['medv'],\n",
" test_size=0.3,\n",
" random_state=0)\n"
" random_state=0)"
]
},
{
@@ -879,16 +853,16 @@
"id": "d18820a3",
"metadata": {
"execution": {
"iopub.execute_input": "2023-07-26T05:17:44.517521Z",
"iopub.status.busy": "2023-07-26T05:17:44.517330Z",
"iopub.status.idle": "2023-07-26T05:17:44.858666Z",
"shell.execute_reply": "2023-07-26T05:17:44.858062Z"
"iopub.execute_input": "2023-07-26T19:30:09.228509Z",
"iopub.status.busy": "2023-07-26T19:30:09.228432Z",
"iopub.status.idle": "2023-07-26T19:30:09.502930Z",
"shell.execute_reply": "2023-07-26T19:30:09.502524Z"
}
},
"outputs": [
{
"data": {
"image/png": "iVBORw0KGgoAAAANSUhEUgAAA7YAAAOwCAYAAAAKo+iFAAAAOXRFWHRTb2Z0d2FyZQBNYXRwbG90bGliIHZlcnNpb24zLjcuMiwgaHR0cHM6Ly9tYXRwbG90bGliLm9yZy8pXeV/AAAACXBIWXMAAA9hAAAPYQGoP6dpAADzq0lEQVR4nOzdd3zN9//+8eskSMRendRK7bbEJjgZxN57V6maRe2Z+qiiLW2tUluM2psYSYyiVpUaMVNF1YpVIiHn94dfzldqNEjyPuNxv916a5xz3udcSRzPX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C/8dObMGWXOnPmpj7du3TpVrFhRadKksV4W9yJRt2/fVoMGDVSyZEnrdUFBQVqyZMlzPwcAABwRxRYAgBdgMpnk7e0tb29vxcTEaP369fr777+VNWvWBO/Y+vn5aePGjTKbzYqOjra+4vGGDRt05coV66nHc+fOVceOHeMd27dvX+3du1cpUqTQqFGjlDJlSknS4cOH5eHhobx58ybiZwsAgH0wWSwWi9EhAADO58CBAypevLj279/P+9g6AL6fAAAj8arIAAAAAAC7RrEFAAAAANg1ii0AAAAAwK5RbAEA+JfAwEAFBQUZHSNBIiMjVaVKFVWqVEnlypXTr7/+Gu/6oUOHytPT84njoqOjra+wbDab5e7ursOHD0uSfvvtN1WtWlW+vr768MMPJT16/99MmTJZb79q1aqk/+QAAEggXhUZAOA0Hj58+MTb/ST148S9RuN/vZXQy2abN2+eypcvr2HDhmnHjh0aMWKEli5dKkm6cOGCTp48+dTjUqVKpbCwMEnS+fPnVbVqVb333nuKjo5W7969tWTJknjv9ys9es/fzZs3v3BGAACSGju2AACbEBERofLly8vHx0dms1mRkZH6+++/5efnpypVqqhz587y9/eXJLVt21Y7duyQJIWFhal9+/aSpO+++06+vr4qUaKEBg8ebL3vnDlzqkuXLqpSpYpu3rypxo0by9fXVz4+Pjpx4oQkafny5SpatKhq166t/fv3PzNnTEyMOnToIF9fX3l7e2vXrl3WTJ06dVKtWrUUHBwsT09PDRo0SH5+fjp//ryaNm2qSpUqqXz58tb7//cxL6NgwYK6deuWJOn69et67bXXrNcFBgbG+zo8S1BQkFq0aCFJ2r17t9KlS6fWrVvLbDbHew/e3377TRUqVFDLli115cqVl8oLAEBSYMcWAGATQkJCVLlyZQUGBkp6tNPZs2dPtWvXTi1atNCMGTOsJfRZ2rdvr08//VQWi0XlypVThw4dlDNnTl28eFF9+vRRrly51L9/f9WvX19NmzbVkSNH1LdvXy1btkz9+/fXnj17lC5dOvn6+j7zMaZPn668efPqxx9/1JUrV1S7dm1ruc2ePbsmT54sSercubOqV6+uL774Qt99950KFCighQ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evNYdTulR+Tp37pwkae/evdbLhwwZouPHj8vNzU3ly5e3lt7Hf3e1cOHCKlu2rOrVqyfp0Ysoubq66u+//9atW7eULl067dmzR0WKFHlqzsKFC8vT01M9e/a0Hh/n8ccxmUzWAl6gQAFt375d/v7+Cg8PV5YsWZ56zOMSumMrSdmyZbP+P65onz592nqK9l9//aUuXbpo4sSJTxw7d+5ctWrVyvrnMmXKaNCgQYqJiZHFYtGxY8eUM2dO3bx501r8Q0NDlS9fvqfmBgDACBRbAIBNWLNmjcaPHy9XV1e5ubnJ29tbJUqUUPPmzTVz5sx4RbN9+/Zq3ry55s+fr9y5c1svr1+/vsqXL68CBQoobdq0T32cQYMG6ZNPPtH48eMlSQEBAerXr5++/PJLVaxYUTly5FDmzJmfmbNDhw7q2rWrfHx8JEnFihX7z93LDh06qG3btqpYsaIePHhgfeznSeiObbdu3dSqVSvNnDlT9+7d0+jRoyXJ+grHkuTp6WkttaNGjVKNGjX03nvv6cGDB1qxYoWGDx9uvW2GDBnUu3dv+fj4KDo6Wt27d1eWLFmst0uXLp3c3Nw0derUBOUDACA5mCyPn8MFAEAyOXDggIoXL679+/fLy8vrP28fERGh9u3b86q8NupFv58AACQmdmwBAHiG1q1bW095lh6dAr1s2TIDEwEAgKeh2AIA7EKuXLmSfbd2zpw5yfp4AADg5fA+tgAAvAJPT89keZwZM2bI29tbFStWVK1atazvXdu2bVsVK1ZMZrNZ9evXj3dMdHS0PD09NWLEiGTJCACLine truncated
"text/plain": [
"<Figure size 1200x1200 with 1 Axes>"
]
@@ -903,7 +877,7 @@
"ax = subplots(figsize=(12,12))[1]\n",
"plot_tree(reg,\n",
" feature_names=feature_names,\n",
" ax=ax);\n"
" ax=ax);"
]
},
{
@@ -933,10 +907,10 @@
"id": "619f8d94",
"metadata": {
"execution": {
"iopub.execute_input": "2023-07-26T05:17:44.861023Z",
"iopub.status.busy": "2023-07-26T05:17:44.860905Z",
"iopub.status.idle": "2023-07-26T05:17:44.914455Z",
"shell.execute_reply": "2023-07-26T05:17:44.913988Z"
"iopub.execute_input": "2023-07-26T19:30:09.510607Z",
"iopub.status.busy": "2023-07-26T19:30:09.510320Z",
"iopub.status.idle": "2023-07-26T19:30:09.559075Z",
"shell.execute_reply": "2023-07-26T19:30:09.558768Z"
}
},
"outputs": [],
@@ -950,7 +924,7 @@
" refit=True,\n",
" cv=kfold,\n",
" scoring='neg_mean_squared_error')\n",
"G = grid.fit(X_train, y_train)\n"
"G = grid.fit(X_train, y_train)"
]
},
{
@@ -968,12 +942,11 @@
"id": "779a14b6",
"metadata": {
"execution": {
"iopub.execute_input": "2023-07-26T05:17:44.917435Z",
"iopub.status.busy": "2023-07-26T05:17:44.917262Z",
"iopub.status.idle": "2023-07-26T05:17:44.920852Z",
"shell.execute_reply": "2023-07-26T05:17:44.920436Z"
},
"lines_to_next_cell": 2
"iopub.execute_input": "2023-07-26T19:30:09.560903Z",
"iopub.status.busy": "2023-07-26T19:30:09.560807Z",
"iopub.status.idle": "2023-07-26T19:30:09.563685Z",
"shell.execute_reply": "2023-07-26T19:30:09.563424Z"
}
},
"outputs": [
{
@@ -989,7 +962,7 @@
],
"source": [
"best_ = grid.best_estimator_\n",
"np.mean((y_test - best_.predict(X_test))**2)\n"
"np.mean((y_test - best_.predict(X_test))**2)"
]
},
{
@@ -1014,17 +987,16 @@
"id": "2b04030b",
"metadata": {
"execution": {
"iopub.execute_input": "2023-07-26T05:17:44.923340Z",
"iopub.status.busy": "2023-07-26T05:17:44.923189Z",
"iopub.status.idle": "2023-07-26T05:17:45.244796Z",
"shell.execute_reply": "2023-07-26T05:17:45.244381Z"
},
"lines_to_next_cell": 0
"iopub.execute_input": "2023-07-26T19:30:09.565313Z",
"iopub.status.busy": "2023-07-26T19:30:09.565190Z",
"iopub.status.idle": "2023-07-26T19:30:09.845669Z",
"shell.execute_reply": "2023-07-26T19:30:09.845356Z"
}
},
"outputs": [
{
"data": {
"image/png": "iVBORw0KGgoAAAANSUhEUgAAA7YAAAOwCAYAAAAK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EAFBQUZHSNBIiMjVaVKFVWqVEnlypXTr7/+Gu/6oUOHytPT84njoqOjra+wbDab5e7ursOHD0uSfvvtN1WtWlW+vr768MMPJT16/99MmTJZb79q1aqk/+QAAEggXhUZAOA0Hj58+MTb/ST148S9RuN/vZXQy2abN2+eypcvr2HDhmnHjh0aMWKEli5dKkm6cOGCTp48+dTjUqVKpbCwMEnS+fPnVbVqVb333nuKjo5W7969tWTJknjv9ys9es/fzZs3v3BGAACSGju2AACbEBERofLly8vHx0dms1mRkZH6+++/5efnpypVqqhz587y9/eXJLVt21Y7duyQJIWFhal9+/aSpO+++06+vr4qUaKEBg8ebL3vnDlzqkuXLqpSpYpu3rypxo0by9fXVz4+Pjpx4oQkafny5SpatKhq166t/fv3PzNnTEyMOnToIF9fX3l7e2vXrl3WTJ06dVKtWrUUHBwsT09PDRo0SH5+fjp//ryaNm2qSpUqqXz58tb7//cxL6NgwYK6deuWJOn69et67bXXrNcFBgbG+zo8S1BQkFq0aCFJ2r17t9KlS6fWrVvLbDbHew/e3377TRUqVFDLli115cqVl8oLAEBSYMcWAGATQkJCVLlyZQUGBkp6tNPZs2dPtWvXTi1atNCMGTOsJfRZ2rdvr08//VQWi0XlypVThw4dlDNnTl28eFF9+vRRrly51L9/f9WvX19NmzbVkSNH1LdvXy1btkz9+/fXnj17lC5dOvn6+j7zMaZPn668efPqxx9/1JUrV1S7dm1ruc2ePbsmT54sSercubOqV6+uL774Qt99950KFCighQsXKjw8XG3atNHu3bufOOZxnTt31tGjR+NdljZt2nhFU5K8vLw0ZMgQFSlSRDdu3NC2bdskSYcOHZIkFS5c+LlfM+nRru/atWslPdrlPXDggA4ePCiLxaLy5curYsWKevPNN3XmzBmlS5dOM2bMUO/evTV79uz/vG8AAJIDxRYAYBMaN26skSNHqkWLFsqZM6cCAwMVHh6ubt26SZLKlSun+fPnS4p/Wu/jb8e+dOlSTZs2TSaTSWfPntX58+eVM2dOZc+eXbly5ZIkHT58WFu3btUPP/xgva8rV67otddes556W6ZMmWfmPHz4sHbu3KkNGzZIkm7cuGG9ztvb2/qxq6urypUrJ0k6fvy4GjRoIEnKnz+/rl279tRjHjdp0qTnfLX+z5gxY1S/fn317t1bu3fvVpcuXbR+/XoNHTpUEyZM+M/j9+/fr6xZs+qdd96RJGXOnFllypRRxowZJUnvv/++Tp06JS8vL7m5uUmSWrRoobFjxyYoHwAAyYFiCwCwCS4uLho5cqQkqV27dgoODla+fPn0yy+/KG/evNYdTulR+Tp37pwkae/evdbLhwwZouPHj8vNzU3ly5e3lt7Hf3e1cOHCKlu2rOrVqyfp0Ysoubq66u+//9atW7eULl067dmzR0WKFHlqzsKFC8vT01M9e/a0Hh/n8ccxmUzWAl6gQAFt375d/v7+Cg8PV5YsWZ56zOMSumMrSdmyZbP+P65onz592nqK9l9//aUuXbpo4sSJTxw7d+5ctWrVyvrnMmXKaNCgQYqJiZHFYtGxY8eUM2dO3bx501r8Q0NDlS9fvqfmBgDACBRbAIBNWLNmjcaPHy9XV1e5ubnJ29tbJUqUUPPmzTVz5sx4RbN9+/Zq3ry55s+fr9y5c1svr1+/vsqXL68CBQoobdq0T32cQYMG6ZNPPtH48eMlSQEBAerXr5++/PJLVaxYUTly5FDmzJmfmbNDhw7q2rWrfHx8JEnFihX7z93LDh06qG3btqpYsaIePHhgfeznSeiObbdu3dSqVSvNnDlT9+7d0+jRoyXJ+grHkuTp6WkttaNGjVKNGjX03nvv6cGDB1qxYoWGDx9uvW2GDBnUu3dv+fj4KDo6Wt27d1eWLFmst0uXLp3c3Nw0derUBOUDACA5mCyPn8MFAEAyOXDggIoXL679+/fLy8vrP28fERGh9u3b86q8NupFv58AACQmdmwBAHiG1q1bW095lh6dAr1s2TIDEwEAgKeh2AIA7EKuXLmSfbd2zpw5yfp4AADg5fA+tgAAvAJPT89keZwZM2bI29tbFStWVK1atazvXdu2bVsVK1ZMZrNZ9evXj3dMdHS0PD09NWLEiGTJCACLine truncated
"text/plain": [
"<Figure size 1200x1200 with 1 Axes>"
]
@@ -1037,16 +1009,7 @@
"ax = subplots(figsize=(12,12))[1]\n",
"plot_tree(G.best_estimator_,\n",
" feature_names=feature_names,\n",
" ax=ax);\n"
]
},
{
"cell_type": "markdown",
"id": "45f99d7e",
"metadata": {},
"source": [
" \n",
" "
" ax=ax);"
]
},
{
@@ -1075,18 +1038,17 @@
"id": "7dedce31",
"metadata": {
"execution": {
"iopub.execute_input": "2023-07-26T05:17:45.248119Z",
"iopub.status.busy": "2023-07-26T05:17:45.247930Z",
"iopub.status.idle": "2023-07-26T05:17:45.416858Z",
"shell.execute_reply": "2023-07-26T05:17:45.416407Z"
},
"lines_to_next_cell": 2
"iopub.execute_input": "2023-07-26T19:30:09.847475Z",
"iopub.status.busy": "2023-07-26T19:30:09.847356Z",
"iopub.status.idle": "2023-07-26T19:30:10.008824Z",
"shell.execute_reply": "2023-07-26T19:30:10.008479Z"
}
},
"outputs": [
{
"data": {
"text/html": [
"<style>#sk-container-id-2 {color: black;background-color: white;}#sk-container-id-2 pre{padding: 0;}#sk-container-id-2 div.sk-toggleable {background-color: white;}#sk-container-id-2 label.sk-toggleable__label {cursor: pointer;display: block;width: 100%;margin-bottom: 0;padding: 0.3em;box-sizing: border-box;text-align: center;}#sk-container-id-2 label.sk-toggleable__label-arrow:before {content: \"▸\";float: left;margin-right: 0.25em;color: #696969;}#sk-container-id-2 label.sk-toggleable__label-arrow:hover:before {color: black;}#sk-container-id-2 div.sk-estimator:hover label.sk-toggleable__label-arrow:before {color: black;}#sk-container-id-2 div.sk-toggleable__content {max-height: 0;max-width: 0;overflow: hidden;text-align: left;background-color: #f0f8ff;}#sk-container-id-2 div.sk-toggleable__content pre {margin: 0.2em;color: black;border-radius: 0.25em;background-color: #f0f8ff;}#sk-container-id-2 input.sk-toggleable__control:checked~div.sk-toggleable__content {max-height: 200px;max-width: 100%;overflow: auto;}#sk-container-id-2 input.sk-toggleable__control:checked~label.sk-toggleable__label-arrow:before {content: \"▾\";}#sk-container-id-2 div.sk-estimator input.sk-toggleable__control:checked~label.sk-toggleable__label {background-color: #d4ebff;}#sk-container-id-2 div.sk-label input.sk-toggleable__control:checked~label.sk-toggleable__label {background-color: #d4ebff;}#sk-container-id-2 input.sk-hidden--visually {border: 0;clip: rect(1px 1px 1px 1px);clip: rect(1px, 1px, 1px, 1px);height: 1px;margin: -1px;overflow: hidden;padding: 0;position: absolute;width: 1px;}#sk-container-id-2 div.sk-estimator {font-family: monospace;background-color: #f0f8ff;border: 1px dotted black;border-radius: 0.25em;box-sizing: border-box;margin-bottom: 0.5em;}#sk-container-id-2 div.sk-estimator:hover {background-color: #d4ebff;}#sk-container-id-2 div.sk-parallel-item::after {content: \"\";width: 100%;border-bottom: 1px solid gray;flex-grow: 1;}#sk-container-id-2 div.sk-label:hover label.sk-toggleable__label {background-color: #d4ebff;}#sk-container-id-2 div.sk-serial::before {content: \"\";position: absolute;border-left: 1px solid gray;box-sizing: border-box;top: 0;bottom: 0;left: 50%;z-index: 0;}#sk-container-id-2 div.sk-serial {display: flex;flex-direction: column;align-items: center;background-color: white;padding-right: 0.2em;padding-left: 0.2em;position: relative;}#sk-container-id-2 div.sk-item {position: relative;z-index: 1;}#sk-container-id-2 div.sk-parallel {display: flex;align-items: stretch;justify-content: center;background-color: white;position: relative;}#sk-container-id-2 div.sk-item::before, #sk-container-id-2 div.sk-parallel-item::before {content: \"\";position: absolute;border-left: 1px solid gray;box-sizing: border-box;top: 0;bottom: 0;left: 50%;z-index: -1;}#sk-container-id-2 div.sk-parallel-item {display: flex;flex-direction: column;z-index: 1;position: relative;background-color: white;}#sk-container-id-2 div.sk-parallel-item:first-child::after {align-self: flex-end;width: 50%;}#sk-container-id-2 div.sk-parallel-item:last-child::after {align-self: flex-start;width: 50%;}#sk-container-id-2 div.sk-parallel-item:only-child::after {width: 0;}#sk-container-id-2 div.sk-dashed-wrapped {border: 1px dashed gray;margin: 0 0.4em 0.5em 0.4em;box-sizing: border-box;padding-bottom: 0.4em;background-color: white;}#sk-container-id-2 div.sk-label label {font-family: monospace;font-weight: bold;display: inline-block;line-height: 1.2em;}#sk-container-id-2 div.sk-label-container {text-align: center;}#sk-container-id-2 div.sk-container {/* jupyter's `normalize.less` sets `[hidden] { display: none; }` but bootstrap.min.css set `[hidden] { display: none !important; }` so we also need the `!important` here to be able to override the default hidden behavior on the sphinx rendered scikit-learn.org. See: https://github.com/scikit-learn/scikit-learn/issues/21755 */display: inline-block !important;position: relative;}#sk-container-id-2 div.sk-text-repr-fallback {display: none;}</style><div id=\"sk-container-id-2\" class=\"sk-top-container\"><div class=\"sk-text-repr-fallback\"><pre>RandomForestRegressor(max_features=12, random_state=0)</pre><b>In a Jupyter environment, please rerun this cell to show the HTML representation or trust the notebook. <br />On GitHub, the HTML representation is unable to render, please try loading this page with nbviewer.org.</b></div><div class=\"sk-container\" hidden><div class=\"sk-item\"><div class=\"sk-estimator sk-toggleable\"><input class=\"sk-toggleable__control sk-hidden--visually\" id=\"sk-estimator-id-2\" type=\"checkbox\" checked><label for=\"sk-estimator-id-2\" class=\"sk-toggleable__label sk-toggleable__label-arrow\">RandomForestRegressor</label><div class=\"sk-toggleable__content\"><pre>RandomForestRegressor(max_features=12, random_state=0)</pre></div></div></div></div></div>"
"<style>#sk-container-id-2 {color: black;}#sk-container-id-2 pre{padding: 0;}#sk-container-id-2 div.sk-toggleable {background-color: white;}#sk-container-id-2 label.sk-toggleable__label {cursor: pointer;display: block;width: 100%;margin-bottom: 0;padding: 0.3em;box-sizing: border-box;text-align: center;}#sk-container-id-2 label.sk-toggleable__label-arrow:before {content: \"▸\";float: left;margin-right: 0.25em;color: #696969;}#sk-container-id-2 label.sk-toggleable__label-arrow:hover:before {color: black;}#sk-container-id-2 div.sk-estimator:hover label.sk-toggleable__label-arrow:before {color: black;}#sk-container-id-2 div.sk-toggleable__content {max-height: 0;max-width: 0;overflow: hidden;text-align: left;background-color: #f0f8ff;}#sk-container-id-2 div.sk-toggleable__content pre {margin: 0.2em;color: black;border-radius: 0.25em;background-color: #f0f8ff;}#sk-container-id-2 input.sk-toggleable__control:checked~div.sk-toggleable__content {max-height: 200px;max-width: 100%;overflow: auto;}#sk-container-id-2 input.sk-toggleable__control:checked~label.sk-toggleable__label-arrow:before {content: \"▾\";}#sk-container-id-2 div.sk-estimator input.sk-toggleable__control:checked~label.sk-toggleable__label {background-color: #d4ebff;}#sk-container-id-2 div.sk-label input.sk-toggleable__control:checked~label.sk-toggleable__label {background-color: #d4ebff;}#sk-container-id-2 input.sk-hidden--visually {border: 0;clip: rect(1px 1px 1px 1px);clip: rect(1px, 1px, 1px, 1px);height: 1px;margin: -1px;overflow: hidden;padding: 0;position: absolute;width: 1px;}#sk-container-id-2 div.sk-estimator {font-family: monospace;background-color: #f0f8ff;border: 1px dotted black;border-radius: 0.25em;box-sizing: border-box;margin-bottom: 0.5em;}#sk-container-id-2 div.sk-estimator:hover {background-color: #d4ebff;}#sk-container-id-2 div.sk-parallel-item::after {content: \"\";width: 100%;border-bottom: 1px solid gray;flex-grow: 1;}#sk-container-id-2 div.sk-label:hover label.sk-toggleable__label {background-color: #d4ebff;}#sk-container-id-2 div.sk-serial::before {content: \"\";position: absolute;border-left: 1px solid gray;box-sizing: border-box;top: 0;bottom: 0;left: 50%;z-index: 0;}#sk-container-id-2 div.sk-serial {display: flex;flex-direction: column;align-items: center;background-color: white;padding-right: 0.2em;padding-left: 0.2em;position: relative;}#sk-container-id-2 div.sk-item {position: relative;z-index: 1;}#sk-container-id-2 div.sk-parallel {display: flex;align-items: stretch;justify-content: center;background-color: white;position: relative;}#sk-container-id-2 div.sk-item::before, #sk-container-id-2 div.sk-parallel-item::before {content: \"\";position: absolute;border-left: 1px solid gray;box-sizing: border-box;top: 0;bottom: 0;left: 50%;z-index: -1;}#sk-container-id-2 div.sk-parallel-item {display: flex;flex-direction: column;z-index: 1;position: relative;background-color: white;}#sk-container-id-2 div.sk-parallel-item:first-child::after {align-self: flex-end;width: 50%;}#sk-container-id-2 div.sk-parallel-item:last-child::after {align-self: flex-start;width: 50%;}#sk-container-id-2 div.sk-parallel-item:only-child::after {width: 0;}#sk-container-id-2 div.sk-dashed-wrapped {border: 1px dashed gray;margin: 0 0.4em 0.5em 0.4em;box-sizing: border-box;padding-bottom: 0.4em;background-color: white;}#sk-container-id-2 div.sk-label label {font-family: monospace;font-weight: bold;display: inline-block;line-height: 1.2em;}#sk-container-id-2 div.sk-label-container {text-align: center;}#sk-container-id-2 div.sk-container {/* jupyter's `normalize.less` sets `[hidden] { display: none; }` but bootstrap.min.css set `[hidden] { display: none !important; }` so we also need the `!important` here to be able to override the default hidden behavior on the sphinx rendered scikit-learn.org. See: https://github.com/scikit-learn/scikit-learn/issues/21755 */display: inline-block !important;position: relative;}#sk-container-id-2 div.sk-text-repr-fallback {display: none;}</style><div id=\"sk-container-id-2\" class=\"sk-top-container\"><div class=\"sk-text-repr-fallback\"><pre>RandomForestRegressor(max_features=12, random_state=0)</pre><b>In a Jupyter environment, please rerun this cell to show the HTML representation or trust the notebook. <br />On GitHub, the HTML representation is unable to render, please try loading this page with nbviewer.org.</b></div><div class=\"sk-container\" hidden><div class=\"sk-item\"><div class=\"sk-estimator sk-toggleable\"><input class=\"sk-toggleable__control sk-hidden--visually\" id=\"sk-estimator-id-2\" type=\"checkbox\" checked><label for=\"sk-estimator-id-2\" class=\"sk-toggleable__label sk-toggleable__label-arrow\">RandomForestRegressor</label><div class=\"sk-toggleable__content\"><pre>RandomForestRegressor(max_features=12, random_state=0)</pre></div></div></div></div></div>"
],
"text/plain": [
"RandomForestRegressor(max_features=12, random_state=0)"
@@ -1099,7 +1061,7 @@
],
"source": [
"bag_boston = RF(max_features=X_train.shape[1], random_state=0)\n",
"bag_boston.fit(X_train, y_train)\n"
"bag_boston.fit(X_train, y_train)"
]
},
{
@@ -1119,10 +1081,10 @@
"id": "1f2c7336",
"metadata": {
"execution": {
"iopub.execute_input": "2023-07-26T05:17:45.418831Z",
"iopub.status.busy": "2023-07-26T05:17:45.418689Z",
"iopub.status.idle": "2023-07-26T05:17:45.525786Z",
"shell.execute_reply": "2023-07-26T05:17:45.525224Z"
"iopub.execute_input": "2023-07-26T19:30:10.010662Z",
"iopub.status.busy": "2023-07-26T19:30:10.010525Z",
"iopub.status.idle": "2023-07-26T19:30:10.105797Z",
"shell.execute_reply": "2023-07-26T19:30:10.105500Z"
}
},
"outputs": [
@@ -1151,7 +1113,7 @@
"ax = subplots(figsize=(8,8))[1]\n",
"y_hat_bag = bag_boston.predict(X_test)\n",
"ax.scatter(y_hat_bag, y_test)\n",
"np.mean((y_test - y_hat_bag)**2)\n"
"np.mean((y_test - y_hat_bag)**2)"
]
},
{
@@ -1172,12 +1134,11 @@
"id": "0bba2439",
"metadata": {
"execution": {
"iopub.execute_input": "2023-07-26T05:17:45.528244Z",
"iopub.status.busy": "2023-07-26T05:17:45.528120Z",
"iopub.status.idle": "2023-07-26T05:17:46.372586Z",
"shell.execute_reply": "2023-07-26T05:17:46.372196Z"
},
"lines_to_next_cell": 0
"iopub.execute_input": "2023-07-26T19:30:10.107534Z",
"iopub.status.busy": "2023-07-26T19:30:10.107407Z",
"iopub.status.idle": "2023-07-26T19:30:10.910541Z",
"shell.execute_reply": "2023-07-26T19:30:10.910243Z"
}
},
"outputs": [
{
@@ -1221,12 +1182,11 @@
"id": "90457fbe",
"metadata": {
"execution": {
"iopub.execute_input": "2023-07-26T05:17:46.375077Z",
"iopub.status.busy": "2023-07-26T05:17:46.374893Z",
"iopub.status.idle": "2023-07-26T05:17:46.498984Z",
"shell.execute_reply": "2023-07-26T05:17:46.498519Z"
},
"lines_to_next_cell": 2
"iopub.execute_input": "2023-07-26T19:30:10.912250Z",
"iopub.status.busy": "2023-07-26T19:30:10.912128Z",
"iopub.status.idle": "2023-07-26T19:30:11.021774Z",
"shell.execute_reply": "2023-07-26T19:30:11.021451Z"
}
},
"outputs": [
{
@@ -1244,7 +1204,7 @@
"RF_boston = RF(max_features=6,\n",
" random_state=0).fit(X_train, y_train)\n",
"y_hat_RF = RF_boston.predict(X_test)\n",
"np.mean((y_test - y_hat_RF)**2)\n"
"np.mean((y_test - y_hat_RF)**2)"
]
},
{
@@ -1264,12 +1224,11 @@
"id": "8aae1857",
"metadata": {
"execution": {
"iopub.execute_input": "2023-07-26T05:17:46.501498Z",
"iopub.status.busy": "2023-07-26T05:17:46.501332Z",
"iopub.status.idle": "2023-07-26T05:17:46.511203Z",
"shell.execute_reply": "2023-07-26T05:17:46.510809Z"
},
"lines_to_next_cell": 0
"iopub.execute_input": "2023-07-26T19:30:11.023526Z",
"iopub.status.busy": "2023-07-26T19:30:11.023400Z",
"iopub.status.idle": "2023-07-26T19:30:11.029781Z",
"shell.execute_reply": "2023-07-26T19:30:11.029457Z"
}
},
"outputs": [
{
@@ -1388,9 +1347,7 @@
"\n",
"The results indicate that across all of the trees considered in the\n",
"random forest, the wealth level of the community (`lstat`) and the\n",
"house size (`rm`) are by far the two most important variables.\n",
"\n",
" "
"house size (`rm`) are by far the two most important variables."
]
},
{
@@ -1422,17 +1379,17 @@
"id": "887b4fa9",
"metadata": {
"execution": {
"iopub.execute_input": "2023-07-26T05:17:46.513662Z",
"iopub.status.busy": "2023-07-26T05:17:46.513485Z",
"iopub.status.idle": "2023-07-26T05:17:50.160797Z",
"shell.execute_reply": "2023-07-26T05:17:50.160288Z"
"iopub.execute_input": "2023-07-26T19:30:11.031499Z",
"iopub.status.busy": "2023-07-26T19:30:11.031393Z",
"iopub.status.idle": "2023-07-26T19:30:14.692497Z",
"shell.execute_reply": "2023-07-26T19:30:14.692170Z"
}
},
"outputs": [
{
"data": {
"text/html": [
"<style>#sk-container-id-3 {color: black;background-color: white;}#sk-container-id-3 pre{padding: 0;}#sk-container-id-3 div.sk-toggleable {background-color: white;}#sk-container-id-3 label.sk-toggleable__label {cursor: pointer;display: block;width: 100%;margin-bottom: 0;padding: 0.3em;box-sizing: border-box;text-align: center;}#sk-container-id-3 label.sk-toggleable__label-arrow:before {content: \"▸\";float: left;margin-right: 0.25em;color: #696969;}#sk-container-id-3 label.sk-toggleable__label-arrow:hover:before {color: black;}#sk-container-id-3 div.sk-estimator:hover label.sk-toggleable__label-arrow:before {color: black;}#sk-container-id-3 div.sk-toggleable__content {max-height: 0;max-width: 0;overflow: hidden;text-align: left;background-color: #f0f8ff;}#sk-container-id-3 div.sk-toggleable__content pre {margin: 0.2em;color: black;border-radius: 0.25em;background-color: #f0f8ff;}#sk-container-id-3 input.sk-toggleable__control:checked~div.sk-toggleable__content {max-height: 200px;max-width: 100%;overflow: auto;}#sk-container-id-3 input.sk-toggleable__control:checked~label.sk-toggleable__label-arrow:before {content: \"▾\";}#sk-container-id-3 div.sk-estimator input.sk-toggleable__control:checked~label.sk-toggleable__label {background-color: #d4ebff;}#sk-container-id-3 div.sk-label input.sk-toggleable__control:checked~label.sk-toggleable__label {background-color: #d4ebff;}#sk-container-id-3 input.sk-hidden--visually {border: 0;clip: rect(1px 1px 1px 1px);clip: rect(1px, 1px, 1px, 1px);height: 1px;margin: -1px;overflow: hidden;padding: 0;position: absolute;width: 1px;}#sk-container-id-3 div.sk-estimator {font-family: monospace;background-color: #f0f8ff;border: 1px dotted black;border-radius: 0.25em;box-sizing: border-box;margin-bottom: 0.5em;}#sk-container-id-3 div.sk-estimator:hover {background-color: #d4ebff;}#sk-container-id-3 div.sk-parallel-item::after {content: \"\";width: 100%;border-bottom: 1px solid gray;flex-grow: 1;}#sk-container-id-3 div.sk-label:hover label.sk-toggleable__label {background-color: #d4ebff;}#sk-container-id-3 div.sk-serial::before {content: \"\";position: absolute;border-left: 1px solid gray;box-sizing: border-box;top: 0;bottom: 0;left: 50%;z-index: 0;}#sk-container-id-3 div.sk-serial {display: flex;flex-direction: column;align-items: center;background-color: white;padding-right: 0.2em;padding-left: 0.2em;position: relative;}#sk-container-id-3 div.sk-item {position: relative;z-index: 1;}#sk-container-id-3 div.sk-parallel {display: flex;align-items: stretch;justify-content: center;background-color: white;position: relative;}#sk-container-id-3 div.sk-item::before, #sk-container-id-3 div.sk-parallel-item::before {content: \"\";position: absolute;border-left: 1px solid gray;box-sizing: border-box;top: 0;bottom: 0;left: 50%;z-index: -1;}#sk-container-id-3 div.sk-parallel-item {display: flex;flex-direction: column;z-index: 1;position: relative;background-color: white;}#sk-container-id-3 div.sk-parallel-item:first-child::after {align-self: flex-end;width: 50%;}#sk-container-id-3 div.sk-parallel-item:last-child::after {align-self: flex-start;width: 50%;}#sk-container-id-3 div.sk-parallel-item:only-child::after {width: 0;}#sk-container-id-3 div.sk-dashed-wrapped {border: 1px dashed gray;margin: 0 0.4em 0.5em 0.4em;box-sizing: border-box;padding-bottom: 0.4em;background-color: white;}#sk-container-id-3 div.sk-label label {font-family: monospace;font-weight: bold;display: inline-block;line-height: 1.2em;}#sk-container-id-3 div.sk-label-container {text-align: center;}#sk-container-id-3 div.sk-container {/* jupyter's `normalize.less` sets `[hidden] { display: none; }` but bootstrap.min.css set `[hidden] { display: none !important; }` so we also need the `!important` here to be able to override the default hidden behavior on the sphinx rendered scikit-learn.org. See: https://github.com/scikit-learn/scikit-learn/issues/21755 */display: inline-block !important;position: relative;}#sk-container-id-3 div.sk-text-repr-fallback {display: none;}</style><div id=\"sk-container-id-3\" class=\"sk-top-container\"><div class=\"sk-text-repr-fallback\"><pre>GradientBoostingRegressor(learning_rate=0.001, n_estimators=5000,\n",
"<style>#sk-container-id-3 {color: black;}#sk-container-id-3 pre{padding: 0;}#sk-container-id-3 div.sk-toggleable {background-color: white;}#sk-container-id-3 label.sk-toggleable__label {cursor: pointer;display: block;width: 100%;margin-bottom: 0;padding: 0.3em;box-sizing: border-box;text-align: center;}#sk-container-id-3 label.sk-toggleable__label-arrow:before {content: \"▸\";float: left;margin-right: 0.25em;color: #696969;}#sk-container-id-3 label.sk-toggleable__label-arrow:hover:before {color: black;}#sk-container-id-3 div.sk-estimator:hover label.sk-toggleable__label-arrow:before {color: black;}#sk-container-id-3 div.sk-toggleable__content {max-height: 0;max-width: 0;overflow: hidden;text-align: left;background-color: #f0f8ff;}#sk-container-id-3 div.sk-toggleable__content pre {margin: 0.2em;color: black;border-radius: 0.25em;background-color: #f0f8ff;}#sk-container-id-3 input.sk-toggleable__control:checked~div.sk-toggleable__content {max-height: 200px;max-width: 100%;overflow: auto;}#sk-container-id-3 input.sk-toggleable__control:checked~label.sk-toggleable__label-arrow:before {content: \"▾\";}#sk-container-id-3 div.sk-estimator input.sk-toggleable__control:checked~label.sk-toggleable__label {background-color: #d4ebff;}#sk-container-id-3 div.sk-label input.sk-toggleable__control:checked~label.sk-toggleable__label {background-color: #d4ebff;}#sk-container-id-3 input.sk-hidden--visually {border: 0;clip: rect(1px 1px 1px 1px);clip: rect(1px, 1px, 1px, 1px);height: 1px;margin: -1px;overflow: hidden;padding: 0;position: absolute;width: 1px;}#sk-container-id-3 div.sk-estimator {font-family: monospace;background-color: #f0f8ff;border: 1px dotted black;border-radius: 0.25em;box-sizing: border-box;margin-bottom: 0.5em;}#sk-container-id-3 div.sk-estimator:hover {background-color: #d4ebff;}#sk-container-id-3 div.sk-parallel-item::after {content: \"\";width: 100%;border-bottom: 1px solid gray;flex-grow: 1;}#sk-container-id-3 div.sk-label:hover label.sk-toggleable__label {background-color: #d4ebff;}#sk-container-id-3 div.sk-serial::before {content: \"\";position: absolute;border-left: 1px solid gray;box-sizing: border-box;top: 0;bottom: 0;left: 50%;z-index: 0;}#sk-container-id-3 div.sk-serial {display: flex;flex-direction: column;align-items: center;background-color: white;padding-right: 0.2em;padding-left: 0.2em;position: relative;}#sk-container-id-3 div.sk-item {position: relative;z-index: 1;}#sk-container-id-3 div.sk-parallel {display: flex;align-items: stretch;justify-content: center;background-color: white;position: relative;}#sk-container-id-3 div.sk-item::before, #sk-container-id-3 div.sk-parallel-item::before {content: \"\";position: absolute;border-left: 1px solid gray;box-sizing: border-box;top: 0;bottom: 0;left: 50%;z-index: -1;}#sk-container-id-3 div.sk-parallel-item {display: flex;flex-direction: column;z-index: 1;position: relative;background-color: white;}#sk-container-id-3 div.sk-parallel-item:first-child::after {align-self: flex-end;width: 50%;}#sk-container-id-3 div.sk-parallel-item:last-child::after {align-self: flex-start;width: 50%;}#sk-container-id-3 div.sk-parallel-item:only-child::after {width: 0;}#sk-container-id-3 div.sk-dashed-wrapped {border: 1px dashed gray;margin: 0 0.4em 0.5em 0.4em;box-sizing: border-box;padding-bottom: 0.4em;background-color: white;}#sk-container-id-3 div.sk-label label {font-family: monospace;font-weight: bold;display: inline-block;line-height: 1.2em;}#sk-container-id-3 div.sk-label-container {text-align: center;}#sk-container-id-3 div.sk-container {/* jupyter's `normalize.less` sets `[hidden] { display: none; }` but bootstrap.min.css set `[hidden] { display: none !important; }` so we also need the `!important` here to be able to override the default hidden behavior on the sphinx rendered scikit-learn.org. See: https://github.com/scikit-learn/scikit-learn/issues/21755 */display: inline-block !important;position: relative;}#sk-container-id-3 div.sk-text-repr-fallback {display: none;}</style><div id=\"sk-container-id-3\" class=\"sk-top-container\"><div class=\"sk-text-repr-fallback\"><pre>GradientBoostingRegressor(learning_rate=0.001, n_estimators=5000,\n",
" random_state=0)</pre><b>In a Jupyter environment, please rerun this cell to show the HTML representation or trust the notebook. <br />On GitHub, the HTML representation is unable to render, please try loading this page with nbviewer.org.</b></div><div class=\"sk-container\" hidden><div class=\"sk-item\"><div class=\"sk-estimator sk-toggleable\"><input class=\"sk-toggleable__control sk-hidden--visually\" id=\"sk-estimator-id-3\" type=\"checkbox\" checked><label for=\"sk-estimator-id-3\" class=\"sk-toggleable__label sk-toggleable__label-arrow\">GradientBoostingRegressor</label><div class=\"sk-toggleable__content\"><pre>GradientBoostingRegressor(learning_rate=0.001, n_estimators=5000,\n",
" random_state=0)</pre></div></div></div></div></div>"
],
@@ -1451,7 +1408,7 @@
" learning_rate=0.001,\n",
" max_depth=3,\n",
" random_state=0)\n",
"boost_boston.fit(X_train, y_train)\n"
"boost_boston.fit(X_train, y_train)"
]
},
{
@@ -1470,10 +1427,10 @@
"id": "6c56696c",
"metadata": {
"execution": {
"iopub.execute_input": "2023-07-26T05:17:50.163556Z",
"iopub.status.busy": "2023-07-26T05:17:50.163389Z",
"iopub.status.idle": "2023-07-26T05:17:50.751622Z",
"shell.execute_reply": "2023-07-26T05:17:50.751113Z"
"iopub.execute_input": "2023-07-26T19:30:14.694174Z",
"iopub.status.busy": "2023-07-26T19:30:14.694070Z",
"iopub.status.idle": "2023-07-26T19:30:15.152622Z",
"shell.execute_reply": "2023-07-26T19:30:15.152291Z"
}
},
"outputs": [
@@ -1503,7 +1460,7 @@
" test_error,\n",
" 'r',\n",
" label='Test')\n",
"ax.legend();\n"
"ax.legend();"
]
},
{
@@ -1520,10 +1477,10 @@
"id": "8a636f63",
"metadata": {
"execution": {
"iopub.execute_input": "2023-07-26T05:17:50.753880Z",
"iopub.status.busy": "2023-07-26T05:17:50.753719Z",
"iopub.status.idle": "2023-07-26T05:17:50.765303Z",
"shell.execute_reply": "2023-07-26T05:17:50.764814Z"
"iopub.execute_input": "2023-07-26T19:30:15.154541Z",
"iopub.status.busy": "2023-07-26T19:30:15.154425Z",
"iopub.status.idle": "2023-07-26T19:30:15.166138Z",
"shell.execute_reply": "2023-07-26T19:30:15.165843Z"
}
},
"outputs": [
@@ -1540,7 +1497,7 @@
],
"source": [
"y_hat_boost = boost_boston.predict(X_test);\n",
"np.mean((y_test - y_hat_boost)**2)\n"
"np.mean((y_test - y_hat_boost)**2)"
]
},
{
@@ -1561,12 +1518,11 @@
"id": "4e2ab3c7",
"metadata": {
"execution": {
"iopub.execute_input": "2023-07-26T05:17:50.767698Z",
"iopub.status.busy": "2023-07-26T05:17:50.767534Z",
"iopub.status.idle": "2023-07-26T05:17:53.090781Z",
"shell.execute_reply": "2023-07-26T05:17:53.090355Z"
},
"lines_to_next_cell": 2
"iopub.execute_input": "2023-07-26T19:30:15.167842Z",
"iopub.status.busy": "2023-07-26T19:30:15.167727Z",
"iopub.status.idle": "2023-07-26T19:30:17.555235Z",
"shell.execute_reply": "2023-07-26T19:30:17.554938Z"
}
},
"outputs": [
{
@@ -1588,7 +1544,7 @@
"boost_boston.fit(X_train,\n",
" y_train)\n",
"y_hat_boost = boost_boston.predict(X_test);\n",
"np.mean((y_test - y_hat_boost)**2)\n"
"np.mean((y_test - y_hat_boost)**2)"
]
},
{
@@ -1597,9 +1553,7 @@
"metadata": {},
"source": [
"In this case, using $\\lambda=0.2$ leads to a almost the same test MSE\n",
"as $\\lambda=0.001$.\n",
"\n",
" "
"as $\\lambda=0.001$."
]
},
{
@@ -1628,18 +1582,17 @@
"id": "b0b41c04",
"metadata": {
"execution": {
"iopub.execute_input": "2023-07-26T05:17:53.093602Z",
"iopub.status.busy": "2023-07-26T05:17:53.093377Z",
"iopub.status.idle": "2023-07-26T05:17:54.986360Z",
"shell.execute_reply": "2023-07-26T05:17:54.985944Z"
},
"lines_to_next_cell": 2
"iopub.execute_input": "2023-07-26T19:30:17.557027Z",
"iopub.status.busy": "2023-07-26T19:30:17.556909Z",
"iopub.status.idle": "2023-07-26T19:30:18.997116Z",
"shell.execute_reply": "2023-07-26T19:30:18.996840Z"
}
},
"outputs": [
{
"data": {
"text/html": [
"<style>#sk-container-id-4 {color: black;background-color: white;}#sk-container-id-4 pre{padding: 0;}#sk-container-id-4 div.sk-toggleable {background-color: white;}#sk-container-id-4 label.sk-toggleable__label {cursor: pointer;display: block;width: 100%;margin-bottom: 0;padding: 0.3em;box-sizing: border-box;text-align: center;}#sk-container-id-4 label.sk-toggleable__label-arrow:before {content: \"▸\";float: left;margin-right: 0.25em;color: #696969;}#sk-container-id-4 label.sk-toggleable__label-arrow:hover:before {color: black;}#sk-container-id-4 div.sk-estimator:hover label.sk-toggleable__label-arrow:before {color: black;}#sk-container-id-4 div.sk-toggleable__content {max-height: 0;max-width: 0;overflow: hidden;text-align: left;background-color: #f0f8ff;}#sk-container-id-4 div.sk-toggleable__content pre {margin: 0.2em;color: black;border-radius: 0.25em;background-color: #f0f8ff;}#sk-container-id-4 input.sk-toggleable__control:checked~div.sk-toggleable__content {max-height: 200px;max-width: 100%;overflow: auto;}#sk-container-id-4 input.sk-toggleable__control:checked~label.sk-toggleable__label-arrow:before {content: \"▾\";}#sk-container-id-4 div.sk-estimator input.sk-toggleable__control:checked~label.sk-toggleable__label {background-color: #d4ebff;}#sk-container-id-4 div.sk-label input.sk-toggleable__control:checked~label.sk-toggleable__label {background-color: #d4ebff;}#sk-container-id-4 input.sk-hidden--visually {border: 0;clip: rect(1px 1px 1px 1px);clip: rect(1px, 1px, 1px, 1px);height: 1px;margin: -1px;overflow: hidden;padding: 0;position: absolute;width: 1px;}#sk-container-id-4 div.sk-estimator {font-family: monospace;background-color: #f0f8ff;border: 1px dotted black;border-radius: 0.25em;box-sizing: border-box;margin-bottom: 0.5em;}#sk-container-id-4 div.sk-estimator:hover {background-color: #d4ebff;}#sk-container-id-4 div.sk-parallel-item::after {content: \"\";width: 100%;border-bottom: 1px solid gray;flex-grow: 1;}#sk-container-id-4 div.sk-label:hover label.sk-toggleable__label {background-color: #d4ebff;}#sk-container-id-4 div.sk-serial::before {content: \"\";position: absolute;border-left: 1px solid gray;box-sizing: border-box;top: 0;bottom: 0;left: 50%;z-index: 0;}#sk-container-id-4 div.sk-serial {display: flex;flex-direction: column;align-items: center;background-color: white;padding-right: 0.2em;padding-left: 0.2em;position: relative;}#sk-container-id-4 div.sk-item {position: relative;z-index: 1;}#sk-container-id-4 div.sk-parallel {display: flex;align-items: stretch;justify-content: center;background-color: white;position: relative;}#sk-container-id-4 div.sk-item::before, #sk-container-id-4 div.sk-parallel-item::before {content: \"\";position: absolute;border-left: 1px solid gray;box-sizing: border-box;top: 0;bottom: 0;left: 50%;z-index: -1;}#sk-container-id-4 div.sk-parallel-item {display: flex;flex-direction: column;z-index: 1;position: relative;background-color: white;}#sk-container-id-4 div.sk-parallel-item:first-child::after {align-self: flex-end;width: 50%;}#sk-container-id-4 div.sk-parallel-item:last-child::after {align-self: flex-start;width: 50%;}#sk-container-id-4 div.sk-parallel-item:only-child::after {width: 0;}#sk-container-id-4 div.sk-dashed-wrapped {border: 1px dashed gray;margin: 0 0.4em 0.5em 0.4em;box-sizing: border-box;padding-bottom: 0.4em;background-color: white;}#sk-container-id-4 div.sk-label label {font-family: monospace;font-weight: bold;display: inline-block;line-height: 1.2em;}#sk-container-id-4 div.sk-label-container {text-align: center;}#sk-container-id-4 div.sk-container {/* jupyter's `normalize.less` sets `[hidden] { display: none; }` but bootstrap.min.css set `[hidden] { display: none !important; }` so we also need the `!important` here to be able to override the default hidden behavior on the sphinx rendered scikit-learn.org. See: https://github.com/scikit-learn/scikit-learn/issues/21755 */display: inline-block !important;position: relative;}#sk-container-id-4 div.sk-text-repr-fallback {display: none;}</style><div id=\"sk-container-id-4\" class=\"sk-top-container\"><div class=\"sk-text-repr-fallback\"><pre>BART(burnin=5, ndraw=15, random_state=0)</pre><b>In a Jupyter environment, please rerun this cell to show the HTML representation or trust the notebook. <br />On GitHub, the HTML representation is unable to render, please try loading this page with nbviewer.org.</b></div><div class=\"sk-container\" hidden><div class=\"sk-item\"><div class=\"sk-estimator sk-toggleable\"><input class=\"sk-toggleable__control sk-hidden--visually\" id=\"sk-estimator-id-4\" type=\"checkbox\" checked><label for=\"sk-estimator-id-4\" class=\"sk-toggleable__label sk-toggleable__label-arrow\">BART</label><div class=\"sk-toggleable__content\"><pre>BART(burnin=5, ndraw=15, random_state=0)</pre></div></div></div></div></div>"
"<style>#sk-container-id-4 {color: black;}#sk-container-id-4 pre{padding: 0;}#sk-container-id-4 div.sk-toggleable {background-color: white;}#sk-container-id-4 label.sk-toggleable__label {cursor: pointer;display: block;width: 100%;margin-bottom: 0;padding: 0.3em;box-sizing: border-box;text-align: center;}#sk-container-id-4 label.sk-toggleable__label-arrow:before {content: \"▸\";float: left;margin-right: 0.25em;color: #696969;}#sk-container-id-4 label.sk-toggleable__label-arrow:hover:before {color: black;}#sk-container-id-4 div.sk-estimator:hover label.sk-toggleable__label-arrow:before {color: black;}#sk-container-id-4 div.sk-toggleable__content {max-height: 0;max-width: 0;overflow: hidden;text-align: left;background-color: #f0f8ff;}#sk-container-id-4 div.sk-toggleable__content pre {margin: 0.2em;color: black;border-radius: 0.25em;background-color: #f0f8ff;}#sk-container-id-4 input.sk-toggleable__control:checked~div.sk-toggleable__content {max-height: 200px;max-width: 100%;overflow: auto;}#sk-container-id-4 input.sk-toggleable__control:checked~label.sk-toggleable__label-arrow:before {content: \"▾\";}#sk-container-id-4 div.sk-estimator input.sk-toggleable__control:checked~label.sk-toggleable__label {background-color: #d4ebff;}#sk-container-id-4 div.sk-label input.sk-toggleable__control:checked~label.sk-toggleable__label {background-color: #d4ebff;}#sk-container-id-4 input.sk-hidden--visually {border: 0;clip: rect(1px 1px 1px 1px);clip: rect(1px, 1px, 1px, 1px);height: 1px;margin: -1px;overflow: hidden;padding: 0;position: absolute;width: 1px;}#sk-container-id-4 div.sk-estimator {font-family: monospace;background-color: #f0f8ff;border: 1px dotted black;border-radius: 0.25em;box-sizing: border-box;margin-bottom: 0.5em;}#sk-container-id-4 div.sk-estimator:hover {background-color: #d4ebff;}#sk-container-id-4 div.sk-parallel-item::after {content: \"\";width: 100%;border-bottom: 1px solid gray;flex-grow: 1;}#sk-container-id-4 div.sk-label:hover label.sk-toggleable__label {background-color: #d4ebff;}#sk-container-id-4 div.sk-serial::before {content: \"\";position: absolute;border-left: 1px solid gray;box-sizing: border-box;top: 0;bottom: 0;left: 50%;z-index: 0;}#sk-container-id-4 div.sk-serial {display: flex;flex-direction: column;align-items: center;background-color: white;padding-right: 0.2em;padding-left: 0.2em;position: relative;}#sk-container-id-4 div.sk-item {position: relative;z-index: 1;}#sk-container-id-4 div.sk-parallel {display: flex;align-items: stretch;justify-content: center;background-color: white;position: relative;}#sk-container-id-4 div.sk-item::before, #sk-container-id-4 div.sk-parallel-item::before {content: \"\";position: absolute;border-left: 1px solid gray;box-sizing: border-box;top: 0;bottom: 0;left: 50%;z-index: -1;}#sk-container-id-4 div.sk-parallel-item {display: flex;flex-direction: column;z-index: 1;position: relative;background-color: white;}#sk-container-id-4 div.sk-parallel-item:first-child::after {align-self: flex-end;width: 50%;}#sk-container-id-4 div.sk-parallel-item:last-child::after {align-self: flex-start;width: 50%;}#sk-container-id-4 div.sk-parallel-item:only-child::after {width: 0;}#sk-container-id-4 div.sk-dashed-wrapped {border: 1px dashed gray;margin: 0 0.4em 0.5em 0.4em;box-sizing: border-box;padding-bottom: 0.4em;background-color: white;}#sk-container-id-4 div.sk-label label {font-family: monospace;font-weight: bold;display: inline-block;line-height: 1.2em;}#sk-container-id-4 div.sk-label-container {text-align: center;}#sk-container-id-4 div.sk-container {/* jupyter's `normalize.less` sets `[hidden] { display: none; }` but bootstrap.min.css set `[hidden] { display: none !important; }` so we also need the `!important` here to be able to override the default hidden behavior on the sphinx rendered scikit-learn.org. See: https://github.com/scikit-learn/scikit-learn/issues/21755 */display: inline-block !important;position: relative;}#sk-container-id-4 div.sk-text-repr-fallback {display: none;}</style><div id=\"sk-container-id-4\" class=\"sk-top-container\"><div class=\"sk-text-repr-fallback\"><pre>BART(burnin=5, ndraw=15, random_state=0)</pre><b>In a Jupyter environment, please rerun this cell to show the HTML representation or trust the notebook. <br />On GitHub, the HTML representation is unable to render, please try loading this page with nbviewer.org.</b></div><div class=\"sk-container\" hidden><div class=\"sk-item\"><div class=\"sk-estimator sk-toggleable\"><input class=\"sk-toggleable__control sk-hidden--visually\" id=\"sk-estimator-id-4\" type=\"checkbox\" checked><label for=\"sk-estimator-id-4\" class=\"sk-toggleable__label sk-toggleable__label-arrow\">BART</label><div class=\"sk-toggleable__content\"><pre>BART(burnin=5, ndraw=15, random_state=0)</pre></div></div></div></div></div>"
],
"text/plain": [
"BART(burnin=5, ndraw=15, random_state=0)"
@@ -1652,7 +1605,7 @@
],
"source": [
"bart_boston = BART(random_state=0, burnin=5, ndraw=15)\n",
"bart_boston.fit(X_train, y_train)\n"
"bart_boston.fit(X_train, y_train)"
]
},
{
@@ -1669,12 +1622,11 @@
"id": "fda8fffc",
"metadata": {
"execution": {
"iopub.execute_input": "2023-07-26T05:17:54.988616Z",
"iopub.status.busy": "2023-07-26T05:17:54.988463Z",
"iopub.status.idle": "2023-07-26T05:17:55.919353Z",
"shell.execute_reply": "2023-07-26T05:17:55.918371Z"
},
"lines_to_next_cell": 2
"iopub.execute_input": "2023-07-26T19:30:18.998761Z",
"iopub.status.busy": "2023-07-26T19:30:18.998658Z",
"iopub.status.idle": "2023-07-26T19:30:19.293073Z",
"shell.execute_reply": "2023-07-26T19:30:19.292790Z"
}
},
"outputs": [
{
@@ -1690,7 +1642,7 @@
],
"source": [
"yhat_test = bart_boston.predict(X_test.astype(np.float32))\n",
"np.mean((y_test - yhat_test)**2)\n"
"np.mean((y_test - yhat_test)**2)"
]
},
{
@@ -1708,12 +1660,11 @@
"id": "be77f0e4",
"metadata": {
"execution": {
"iopub.execute_input": "2023-07-26T05:17:55.922114Z",
"iopub.status.busy": "2023-07-26T05:17:55.921834Z",
"iopub.status.idle": "2023-07-26T05:17:55.926261Z",
"shell.execute_reply": "2023-07-26T05:17:55.925458Z"
},
"lines_to_next_cell": 0
"iopub.execute_input": "2023-07-26T19:30:19.294666Z",
"iopub.status.busy": "2023-07-26T19:30:19.294560Z",
"iopub.status.idle": "2023-07-26T19:30:19.297309Z",
"shell.execute_reply": "2023-07-26T19:30:19.297024Z"
}
},
"outputs": [
{
@@ -1742,26 +1693,15 @@
"source": [
"var_inclusion = pd.Series(bart_boston.variable_inclusion_.mean(0),\n",
" index=D.columns)\n",
"var_inclusion\n"
]
},
{
"cell_type": "markdown",
"id": "cf40b6ac",
"metadata": {},
"source": [
" \n",
" \n",
" \n",
"\n"
"var_inclusion"
]
}
],
"metadata": {
"jupytext": {
"cell_metadata_filter": "-all",
"main_language": "python",
"notebook_metadata_filter": "-all"
"formats": "ipynb,md:myst",
"main_language": "python"
},
"language_info": {
"codemirror_mode": {
@@ -1773,7 +1713,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.9.17"
"version": "3.11.4"
}
},
"nbformat": 4,
+193 -208
View File
@@ -5,9 +5,7 @@
"id": "d45c6d2b",
"metadata": {},
"source": [
"\n",
"# Chapter 9\n",
"\n"
"# Chapter 9"
]
},
{
@@ -28,19 +26,18 @@
"id": "eeaa5be0",
"metadata": {
"execution": {
"iopub.execute_input": "2023-07-26T05:17:57.286672Z",
"iopub.status.busy": "2023-07-26T05:17:57.286340Z",
"iopub.status.idle": "2023-07-26T05:17:58.454461Z",
"shell.execute_reply": "2023-07-26T05:17:58.453915Z"
},
"lines_to_next_cell": 0
"iopub.execute_input": "2023-07-26T19:30:20.613956Z",
"iopub.status.busy": "2023-07-26T19:30:20.613862Z",
"iopub.status.idle": "2023-07-26T19:30:21.610751Z",
"shell.execute_reply": "2023-07-26T19:30:21.610246Z"
}
},
"outputs": [],
"source": [
"import numpy as np\n",
"from matplotlib.pyplot import subplots, cm\n",
"import sklearn.model_selection as skm\n",
"from ISLP import load_data, confusion_table\n"
"from ISLP import load_data, confusion_table"
]
},
{
@@ -58,17 +55,17 @@
"id": "41a59634",
"metadata": {
"execution": {
"iopub.execute_input": "2023-07-26T05:17:58.457424Z",
"iopub.status.busy": "2023-07-26T05:17:58.457095Z",
"iopub.status.idle": "2023-07-26T05:17:58.490405Z",
"shell.execute_reply": "2023-07-26T05:17:58.490061Z"
"iopub.execute_input": "2023-07-26T19:30:21.613062Z",
"iopub.status.busy": "2023-07-26T19:30:21.612758Z",
"iopub.status.idle": "2023-07-26T19:30:21.648403Z",
"shell.execute_reply": "2023-07-26T19:30:21.648111Z"
}
},
"outputs": [],
"source": [
"from sklearn.svm import SVC\n",
"from ISLP.svm import plot as plot_svm\n",
"from sklearn.metrics import RocCurveDisplay\n"
"from sklearn.metrics import RocCurveDisplay"
]
},
{
@@ -86,15 +83,15 @@
"id": "c9a175d7",
"metadata": {
"execution": {
"iopub.execute_input": "2023-07-26T05:17:58.493151Z",
"iopub.status.busy": "2023-07-26T05:17:58.492879Z",
"iopub.status.idle": "2023-07-26T05:17:58.496409Z",
"shell.execute_reply": "2023-07-26T05:17:58.495164Z"
"iopub.execute_input": "2023-07-26T19:30:21.650168Z",
"iopub.status.busy": "2023-07-26T19:30:21.650058Z",
"iopub.status.idle": "2023-07-26T19:30:21.651930Z",
"shell.execute_reply": "2023-07-26T19:30:21.651629Z"
}
},
"outputs": [],
"source": [
"roc_curve = RocCurveDisplay.from_estimator # shorthand\n"
"roc_curve = RocCurveDisplay.from_estimator # shorthand"
]
},
{
@@ -126,12 +123,11 @@
"id": "a7216b47",
"metadata": {
"execution": {
"iopub.execute_input": "2023-07-26T05:17:58.499025Z",
"iopub.status.busy": "2023-07-26T05:17:58.498850Z",
"iopub.status.idle": "2023-07-26T05:17:58.613732Z",
"shell.execute_reply": "2023-07-26T05:17:58.613136Z"
},
"lines_to_next_cell": 0
"iopub.execute_input": "2023-07-26T19:30:21.653381Z",
"iopub.status.busy": "2023-07-26T19:30:21.653281Z",
"iopub.status.idle": "2023-07-26T19:30:21.771451Z",
"shell.execute_reply": "2023-07-26T19:30:21.769306Z"
}
},
"outputs": [
{
@@ -154,7 +150,7 @@
"ax.scatter(X[:,0],\n",
" X[:,1],\n",
" c=y,\n",
" cmap=cm.coolwarm);\n"
" cmap=cm.coolwarm);"
]
},
{
@@ -171,18 +167,17 @@
"id": "ed329198",
"metadata": {
"execution": {
"iopub.execute_input": "2023-07-26T05:17:58.616777Z",
"iopub.status.busy": "2023-07-26T05:17:58.616601Z",
"iopub.status.idle": "2023-07-26T05:17:58.621468Z",
"shell.execute_reply": "2023-07-26T05:17:58.621124Z"
},
"lines_to_next_cell": 2
"iopub.execute_input": "2023-07-26T19:30:21.776220Z",
"iopub.status.busy": "2023-07-26T19:30:21.775574Z",
"iopub.status.idle": "2023-07-26T19:30:21.791582Z",
"shell.execute_reply": "2023-07-26T19:30:21.790533Z"
}
},
"outputs": [
{
"data": {
"text/html": [
"<style>#sk-container-id-1 {color: black;background-color: white;}#sk-container-id-1 pre{padding: 0;}#sk-container-id-1 div.sk-toggleable {background-color: white;}#sk-container-id-1 label.sk-toggleable__label {cursor: pointer;display: block;width: 100%;margin-bottom: 0;padding: 0.3em;box-sizing: border-box;text-align: center;}#sk-container-id-1 label.sk-toggleable__label-arrow:before {content: \"▸\";float: left;margin-right: 0.25em;color: #696969;}#sk-container-id-1 label.sk-toggleable__label-arrow:hover:before {color: black;}#sk-container-id-1 div.sk-estimator:hover label.sk-toggleable__label-arrow:before {color: black;}#sk-container-id-1 div.sk-toggleable__content {max-height: 0;max-width: 0;overflow: hidden;text-align: left;background-color: #f0f8ff;}#sk-container-id-1 div.sk-toggleable__content pre {margin: 0.2em;color: black;border-radius: 0.25em;background-color: #f0f8ff;}#sk-container-id-1 input.sk-toggleable__control:checked~div.sk-toggleable__content {max-height: 200px;max-width: 100%;overflow: auto;}#sk-container-id-1 input.sk-toggleable__control:checked~label.sk-toggleable__label-arrow:before {content: \"▾\";}#sk-container-id-1 div.sk-estimator input.sk-toggleable__control:checked~label.sk-toggleable__label {background-color: #d4ebff;}#sk-container-id-1 div.sk-label input.sk-toggleable__control:checked~label.sk-toggleable__label {background-color: #d4ebff;}#sk-container-id-1 input.sk-hidden--visually {border: 0;clip: rect(1px 1px 1px 1px);clip: rect(1px, 1px, 1px, 1px);height: 1px;margin: -1px;overflow: hidden;padding: 0;position: absolute;width: 1px;}#sk-container-id-1 div.sk-estimator {font-family: monospace;background-color: #f0f8ff;border: 1px dotted black;border-radius: 0.25em;box-sizing: border-box;margin-bottom: 0.5em;}#sk-container-id-1 div.sk-estimator:hover {background-color: #d4ebff;}#sk-container-id-1 div.sk-parallel-item::after {content: \"\";width: 100%;border-bottom: 1px solid gray;flex-grow: 1;}#sk-container-id-1 div.sk-label:hover label.sk-toggleable__label {background-color: #d4ebff;}#sk-container-id-1 div.sk-serial::before {content: \"\";position: absolute;border-left: 1px solid gray;box-sizing: border-box;top: 0;bottom: 0;left: 50%;z-index: 0;}#sk-container-id-1 div.sk-serial {display: flex;flex-direction: column;align-items: center;background-color: white;padding-right: 0.2em;padding-left: 0.2em;position: relative;}#sk-container-id-1 div.sk-item {position: relative;z-index: 1;}#sk-container-id-1 div.sk-parallel {display: flex;align-items: stretch;justify-content: center;background-color: white;position: relative;}#sk-container-id-1 div.sk-item::before, #sk-container-id-1 div.sk-parallel-item::before {content: \"\";position: absolute;border-left: 1px solid gray;box-sizing: border-box;top: 0;bottom: 0;left: 50%;z-index: -1;}#sk-container-id-1 div.sk-parallel-item {display: flex;flex-direction: column;z-index: 1;position: relative;background-color: white;}#sk-container-id-1 div.sk-parallel-item:first-child::after {align-self: flex-end;width: 50%;}#sk-container-id-1 div.sk-parallel-item:last-child::after {align-self: flex-start;width: 50%;}#sk-container-id-1 div.sk-parallel-item:only-child::after {width: 0;}#sk-container-id-1 div.sk-dashed-wrapped {border: 1px dashed gray;margin: 0 0.4em 0.5em 0.4em;box-sizing: border-box;padding-bottom: 0.4em;background-color: white;}#sk-container-id-1 div.sk-label label {font-family: monospace;font-weight: bold;display: inline-block;line-height: 1.2em;}#sk-container-id-1 div.sk-label-container {text-align: center;}#sk-container-id-1 div.sk-container {/* jupyter's `normalize.less` sets `[hidden] { display: none; }` but bootstrap.min.css set `[hidden] { display: none !important; }` so we also need the `!important` here to be able to override the default hidden behavior on the sphinx rendered scikit-learn.org. See: https://github.com/scikit-learn/scikit-learn/issues/21755 */display: inline-block !important;position: relative;}#sk-container-id-1 div.sk-text-repr-fallback {display: none;}</style><div id=\"sk-container-id-1\" class=\"sk-top-container\"><div class=\"sk-text-repr-fallback\"><pre>SVC(C=10, kernel=&#x27;linear&#x27;)</pre><b>In a Jupyter environment, please rerun this cell to show the HTML representation or trust the notebook. <br />On GitHub, the HTML representation is unable to render, please try loading this page with nbviewer.org.</b></div><div class=\"sk-container\" hidden><div class=\"sk-item\"><div class=\"sk-estimator sk-toggleable\"><input class=\"sk-toggleable__control sk-hidden--visually\" id=\"sk-estimator-id-1\" type=\"checkbox\" checked><label for=\"sk-estimator-id-1\" class=\"sk-toggleable__label sk-toggleable__label-arrow\">SVC</label><div class=\"sk-toggleable__content\"><pre>SVC(C=10, kernel=&#x27;linear&#x27;)</pre></div></div></div></div></div>"
"<style>#sk-container-id-1 {color: black;}#sk-container-id-1 pre{padding: 0;}#sk-container-id-1 div.sk-toggleable {background-color: white;}#sk-container-id-1 label.sk-toggleable__label {cursor: pointer;display: block;width: 100%;margin-bottom: 0;padding: 0.3em;box-sizing: border-box;text-align: center;}#sk-container-id-1 label.sk-toggleable__label-arrow:before {content: \"▸\";float: left;margin-right: 0.25em;color: #696969;}#sk-container-id-1 label.sk-toggleable__label-arrow:hover:before {color: black;}#sk-container-id-1 div.sk-estimator:hover label.sk-toggleable__label-arrow:before {color: black;}#sk-container-id-1 div.sk-toggleable__content {max-height: 0;max-width: 0;overflow: hidden;text-align: left;background-color: #f0f8ff;}#sk-container-id-1 div.sk-toggleable__content pre {margin: 0.2em;color: black;border-radius: 0.25em;background-color: #f0f8ff;}#sk-container-id-1 input.sk-toggleable__control:checked~div.sk-toggleable__content {max-height: 200px;max-width: 100%;overflow: auto;}#sk-container-id-1 input.sk-toggleable__control:checked~label.sk-toggleable__label-arrow:before {content: \"▾\";}#sk-container-id-1 div.sk-estimator input.sk-toggleable__control:checked~label.sk-toggleable__label {background-color: #d4ebff;}#sk-container-id-1 div.sk-label input.sk-toggleable__control:checked~label.sk-toggleable__label {background-color: #d4ebff;}#sk-container-id-1 input.sk-hidden--visually {border: 0;clip: rect(1px 1px 1px 1px);clip: rect(1px, 1px, 1px, 1px);height: 1px;margin: -1px;overflow: hidden;padding: 0;position: absolute;width: 1px;}#sk-container-id-1 div.sk-estimator {font-family: monospace;background-color: #f0f8ff;border: 1px dotted black;border-radius: 0.25em;box-sizing: border-box;margin-bottom: 0.5em;}#sk-container-id-1 div.sk-estimator:hover {background-color: #d4ebff;}#sk-container-id-1 div.sk-parallel-item::after {content: \"\";width: 100%;border-bottom: 1px solid gray;flex-grow: 1;}#sk-container-id-1 div.sk-label:hover label.sk-toggleable__label {background-color: #d4ebff;}#sk-container-id-1 div.sk-serial::before {content: \"\";position: absolute;border-left: 1px solid gray;box-sizing: border-box;top: 0;bottom: 0;left: 50%;z-index: 0;}#sk-container-id-1 div.sk-serial {display: flex;flex-direction: column;align-items: center;background-color: white;padding-right: 0.2em;padding-left: 0.2em;position: relative;}#sk-container-id-1 div.sk-item {position: relative;z-index: 1;}#sk-container-id-1 div.sk-parallel {display: flex;align-items: stretch;justify-content: center;background-color: white;position: relative;}#sk-container-id-1 div.sk-item::before, #sk-container-id-1 div.sk-parallel-item::before {content: \"\";position: absolute;border-left: 1px solid gray;box-sizing: border-box;top: 0;bottom: 0;left: 50%;z-index: -1;}#sk-container-id-1 div.sk-parallel-item {display: flex;flex-direction: column;z-index: 1;position: relative;background-color: white;}#sk-container-id-1 div.sk-parallel-item:first-child::after {align-self: flex-end;width: 50%;}#sk-container-id-1 div.sk-parallel-item:last-child::after {align-self: flex-start;width: 50%;}#sk-container-id-1 div.sk-parallel-item:only-child::after {width: 0;}#sk-container-id-1 div.sk-dashed-wrapped {border: 1px dashed gray;margin: 0 0.4em 0.5em 0.4em;box-sizing: border-box;padding-bottom: 0.4em;background-color: white;}#sk-container-id-1 div.sk-label label {font-family: monospace;font-weight: bold;display: inline-block;line-height: 1.2em;}#sk-container-id-1 div.sk-label-container {text-align: center;}#sk-container-id-1 div.sk-container {/* jupyter's `normalize.less` sets `[hidden] { display: none; }` but bootstrap.min.css set `[hidden] { display: none !important; }` so we also need the `!important` here to be able to override the default hidden behavior on the sphinx rendered scikit-learn.org. See: https://github.com/scikit-learn/scikit-learn/issues/21755 */display: inline-block !important;position: relative;}#sk-container-id-1 div.sk-text-repr-fallback {display: none;}</style><div id=\"sk-container-id-1\" class=\"sk-top-container\"><div class=\"sk-text-repr-fallback\"><pre>SVC(C=10, kernel=&#x27;linear&#x27;)</pre><b>In a Jupyter environment, please rerun this cell to show the HTML representation or trust the notebook. <br />On GitHub, the HTML representation is unable to render, please try loading this page with nbviewer.org.</b></div><div class=\"sk-container\" hidden><div class=\"sk-item\"><div class=\"sk-estimator sk-toggleable\"><input class=\"sk-toggleable__control sk-hidden--visually\" id=\"sk-estimator-id-1\" type=\"checkbox\" checked><label for=\"sk-estimator-id-1\" class=\"sk-toggleable__label sk-toggleable__label-arrow\">SVC</label><div class=\"sk-toggleable__content\"><pre>SVC(C=10, kernel=&#x27;linear&#x27;)</pre></div></div></div></div></div>"
],
"text/plain": [
"SVC(C=10, kernel='linear')"
@@ -195,7 +190,7 @@
],
"source": [
"svm_linear = SVC(C=10, kernel='linear')\n",
"svm_linear.fit(X, y)\n"
"svm_linear.fit(X, y)"
]
},
{
@@ -215,10 +210,10 @@
"id": "95494b8b",
"metadata": {
"execution": {
"iopub.execute_input": "2023-07-26T05:17:58.623538Z",
"iopub.status.busy": "2023-07-26T05:17:58.623369Z",
"iopub.status.idle": "2023-07-26T05:17:58.810058Z",
"shell.execute_reply": "2023-07-26T05:17:58.809447Z"
"iopub.execute_input": "2023-07-26T19:30:21.798277Z",
"iopub.status.busy": "2023-07-26T19:30:21.797873Z",
"iopub.status.idle": "2023-07-26T19:30:22.041587Z",
"shell.execute_reply": "2023-07-26T19:30:22.041253Z"
}
},
"outputs": [
@@ -238,7 +233,7 @@
"plot_svm(X,\n",
" y,\n",
" svm_linear,\n",
" ax=ax)\n"
" ax=ax)"
]
},
{
@@ -260,12 +255,11 @@
"id": "98c2236f",
"metadata": {
"execution": {
"iopub.execute_input": "2023-07-26T05:17:58.812870Z",
"iopub.status.busy": "2023-07-26T05:17:58.812658Z",
"iopub.status.idle": "2023-07-26T05:17:58.967044Z",
"shell.execute_reply": "2023-07-26T05:17:58.966462Z"
},
"lines_to_next_cell": 0
"iopub.execute_input": "2023-07-26T19:30:22.043302Z",
"iopub.status.busy": "2023-07-26T19:30:22.043193Z",
"iopub.status.idle": "2023-07-26T19:30:22.185489Z",
"shell.execute_reply": "2023-07-26T19:30:22.185015Z"
}
},
"outputs": [
{
@@ -286,7 +280,7 @@
"plot_svm(X,\n",
" y,\n",
" svm_linear_small,\n",
" ax=ax)\n"
" ax=ax)"
]
},
{
@@ -306,12 +300,11 @@
"id": "b498f594",
"metadata": {
"execution": {
"iopub.execute_input": "2023-07-26T05:17:58.969920Z",
"iopub.status.busy": "2023-07-26T05:17:58.969735Z",
"iopub.status.idle": "2023-07-26T05:17:58.973409Z",
"shell.execute_reply": "2023-07-26T05:17:58.972682Z"
},
"lines_to_next_cell": 2
"iopub.execute_input": "2023-07-26T19:30:22.187546Z",
"iopub.status.busy": "2023-07-26T19:30:22.187386Z",
"iopub.status.idle": "2023-07-26T19:30:22.190140Z",
"shell.execute_reply": "2023-07-26T19:30:22.189804Z"
}
},
"outputs": [
{
@@ -326,7 +319,7 @@
}
],
"source": [
"svm_linear.coef_\n"
"svm_linear.coef_"
]
},
{
@@ -344,12 +337,11 @@
"id": "b65e80d6",
"metadata": {
"execution": {
"iopub.execute_input": "2023-07-26T05:17:58.975865Z",
"iopub.status.busy": "2023-07-26T05:17:58.975747Z",
"iopub.status.idle": "2023-07-26T05:17:59.006899Z",
"shell.execute_reply": "2023-07-26T05:17:59.006545Z"
},
"lines_to_next_cell": 2
"iopub.execute_input": "2023-07-26T19:30:22.192137Z",
"iopub.status.busy": "2023-07-26T19:30:22.191917Z",
"iopub.status.idle": "2023-07-26T19:30:22.221281Z",
"shell.execute_reply": "2023-07-26T19:30:22.220919Z"
}
},
"outputs": [
{
@@ -373,7 +365,7 @@
" cv=kfold,\n",
" scoring='accuracy')\n",
"grid.fit(X, y)\n",
"grid.best_params_\n"
"grid.best_params_"
]
},
{
@@ -392,12 +384,11 @@
"id": "bba8fad7",
"metadata": {
"execution": {
"iopub.execute_input": "2023-07-26T05:17:59.010681Z",
"iopub.status.busy": "2023-07-26T05:17:59.010231Z",
"iopub.status.idle": "2023-07-26T05:17:59.014165Z",
"shell.execute_reply": "2023-07-26T05:17:59.013759Z"
},
"lines_to_next_cell": 0
"iopub.execute_input": "2023-07-26T19:30:22.223145Z",
"iopub.status.busy": "2023-07-26T19:30:22.222994Z",
"iopub.status.idle": "2023-07-26T19:30:22.225490Z",
"shell.execute_reply": "2023-07-26T19:30:22.225195Z"
}
},
"outputs": [
{
@@ -412,7 +403,7 @@
}
],
"source": [
"grid.cv_results_[('mean_test_score')]\n"
"grid.cv_results_[('mean_test_score')]"
]
},
{
@@ -433,17 +424,17 @@
"id": "ad64269d",
"metadata": {
"execution": {
"iopub.execute_input": "2023-07-26T05:17:59.017638Z",
"iopub.status.busy": "2023-07-26T05:17:59.017453Z",
"iopub.status.idle": "2023-07-26T05:17:59.020397Z",
"shell.execute_reply": "2023-07-26T05:17:59.019642Z"
"iopub.execute_input": "2023-07-26T19:30:22.227113Z",
"iopub.status.busy": "2023-07-26T19:30:22.227004Z",
"iopub.status.idle": "2023-07-26T19:30:22.229099Z",
"shell.execute_reply": "2023-07-26T19:30:22.228833Z"
}
},
"outputs": [],
"source": [
"X_test = rng.standard_normal((20, 2))\n",
"y_test = np.array([-1]*10+[1]*10)\n",
"X_test[y_test==1] += 1\n"
"X_test[y_test==1] += 1"
]
},
{
@@ -462,10 +453,10 @@
"id": "5107fca1",
"metadata": {
"execution": {
"iopub.execute_input": "2023-07-26T05:17:59.026576Z",
"iopub.status.busy": "2023-07-26T05:17:59.026365Z",
"iopub.status.idle": "2023-07-26T05:17:59.033664Z",
"shell.execute_reply": "2023-07-26T05:17:59.033173Z"
"iopub.execute_input": "2023-07-26T19:30:22.230650Z",
"iopub.status.busy": "2023-07-26T19:30:22.230546Z",
"iopub.status.idle": "2023-07-26T19:30:22.236572Z",
"shell.execute_reply": "2023-07-26T19:30:22.236281Z"
}
},
"outputs": [
@@ -529,7 +520,7 @@
"source": [
"best_ = grid.best_estimator_\n",
"y_test_hat = best_.predict(X_test)\n",
"confusion_table(y_test_hat, y_test)\n"
"confusion_table(y_test_hat, y_test)"
]
},
{
@@ -549,10 +540,10 @@
"id": "0320d9e0",
"metadata": {
"execution": {
"iopub.execute_input": "2023-07-26T05:17:59.035936Z",
"iopub.status.busy": "2023-07-26T05:17:59.035645Z",
"iopub.status.idle": "2023-07-26T05:17:59.041475Z",
"shell.execute_reply": "2023-07-26T05:17:59.041054Z"
"iopub.execute_input": "2023-07-26T19:30:22.238263Z",
"iopub.status.busy": "2023-07-26T19:30:22.238141Z",
"iopub.status.idle": "2023-07-26T19:30:22.242738Z",
"shell.execute_reply": "2023-07-26T19:30:22.242453Z"
}
},
"outputs": [
@@ -617,7 +608,7 @@
"svm_ = SVC(C=0.001,\n",
" kernel='linear').fit(X, y)\n",
"y_test_hat = svm_.predict(X_test)\n",
"confusion_table(y_test_hat, y_test)\n"
"confusion_table(y_test_hat, y_test)"
]
},
{
@@ -640,10 +631,10 @@
"id": "84d7e778",
"metadata": {
"execution": {
"iopub.execute_input": "2023-07-26T05:17:59.043762Z",
"iopub.status.busy": "2023-07-26T05:17:59.043557Z",
"iopub.status.idle": "2023-07-26T05:17:59.144334Z",
"shell.execute_reply": "2023-07-26T05:17:59.143881Z"
"iopub.execute_input": "2023-07-26T19:30:22.244328Z",
"iopub.status.busy": "2023-07-26T19:30:22.244224Z",
"iopub.status.idle": "2023-07-26T19:30:22.371782Z",
"shell.execute_reply": "2023-07-26T19:30:22.371427Z"
}
},
"outputs": [
@@ -661,7 +652,7 @@
"source": [
"X[y==1] += 1.9;\n",
"fig, ax = subplots(figsize=(8,8))\n",
"ax.scatter(X[:,0], X[:,1], c=y, cmap=cm.coolwarm);\n"
"ax.scatter(X[:,0], X[:,1], c=y, cmap=cm.coolwarm);"
]
},
{
@@ -678,10 +669,10 @@
"id": "abb1f8be",
"metadata": {
"execution": {
"iopub.execute_input": "2023-07-26T05:17:59.147029Z",
"iopub.status.busy": "2023-07-26T05:17:59.146868Z",
"iopub.status.idle": "2023-07-26T05:17:59.154787Z",
"shell.execute_reply": "2023-07-26T05:17:59.153508Z"
"iopub.execute_input": "2023-07-26T19:30:22.380382Z",
"iopub.status.busy": "2023-07-26T19:30:22.380213Z",
"iopub.status.idle": "2023-07-26T19:30:22.385861Z",
"shell.execute_reply": "2023-07-26T19:30:22.385389Z"
}
},
"outputs": [
@@ -745,7 +736,7 @@
"source": [
"svm_ = SVC(C=1e5, kernel='linear').fit(X, y)\n",
"y_hat = svm_.predict(X)\n",
"confusion_table(y_hat, y)\n"
"confusion_table(y_hat, y)"
]
},
{
@@ -756,7 +747,7 @@
"We fit the\n",
"support vector classifier and plot the resulting hyperplane, using a\n",
"very large value of `C` so that no observations are\n",
"misclassified. "
"misclassified."
]
},
{
@@ -765,12 +756,11 @@
"id": "2e4ed2f5",
"metadata": {
"execution": {
"iopub.execute_input": "2023-07-26T05:17:59.157293Z",
"iopub.status.busy": "2023-07-26T05:17:59.157100Z",
"iopub.status.idle": "2023-07-26T05:17:59.287805Z",
"shell.execute_reply": "2023-07-26T05:17:59.287264Z"
},
"lines_to_next_cell": 0
"iopub.execute_input": "2023-07-26T19:30:22.387842Z",
"iopub.status.busy": "2023-07-26T19:30:22.387704Z",
"iopub.status.idle": "2023-07-26T19:30:22.507545Z",
"shell.execute_reply": "2023-07-26T19:30:22.507157Z"
}
},
"outputs": [
{
@@ -789,7 +779,7 @@
"plot_svm(X,\n",
" y,\n",
" svm_,\n",
" ax=ax)\n"
" ax=ax)"
]
},
{
@@ -810,10 +800,10 @@
"id": "164a611c",
"metadata": {
"execution": {
"iopub.execute_input": "2023-07-26T05:17:59.291112Z",
"iopub.status.busy": "2023-07-26T05:17:59.290933Z",
"iopub.status.idle": "2023-07-26T05:17:59.296989Z",
"shell.execute_reply": "2023-07-26T05:17:59.296618Z"
"iopub.execute_input": "2023-07-26T19:30:22.509336Z",
"iopub.status.busy": "2023-07-26T19:30:22.509220Z",
"iopub.status.idle": "2023-07-26T19:30:22.514501Z",
"shell.execute_reply": "2023-07-26T19:30:22.513847Z"
}
},
"outputs": [
@@ -877,7 +867,7 @@
"source": [
"svm_ = SVC(C=0.1, kernel='linear').fit(X, y)\n",
"y_hat = svm_.predict(X)\n",
"confusion_table(y_hat, y)\n"
"confusion_table(y_hat, y)"
]
},
{
@@ -897,12 +887,11 @@
"id": "c67591a1",
"metadata": {
"execution": {
"iopub.execute_input": "2023-07-26T05:17:59.299723Z",
"iopub.status.busy": "2023-07-26T05:17:59.299515Z",
"iopub.status.idle": "2023-07-26T05:17:59.442236Z",
"shell.execute_reply": "2023-07-26T05:17:59.441618Z"
},
"lines_to_next_cell": 2
"iopub.execute_input": "2023-07-26T19:30:22.516223Z",
"iopub.status.busy": "2023-07-26T19:30:22.516110Z",
"iopub.status.idle": "2023-07-26T19:30:22.643367Z",
"shell.execute_reply": "2023-07-26T19:30:22.643066Z"
}
},
"outputs": [
{
@@ -921,7 +910,7 @@
"plot_svm(X,\n",
" y,\n",
" svm_,\n",
" ax=ax)\n"
" ax=ax)"
]
},
{
@@ -950,10 +939,10 @@
"id": "322be574",
"metadata": {
"execution": {
"iopub.execute_input": "2023-07-26T05:17:59.445260Z",
"iopub.status.busy": "2023-07-26T05:17:59.445043Z",
"iopub.status.idle": "2023-07-26T05:17:59.448424Z",
"shell.execute_reply": "2023-07-26T05:17:59.447969Z"
"iopub.execute_input": "2023-07-26T19:30:22.645070Z",
"iopub.status.busy": "2023-07-26T19:30:22.644945Z",
"iopub.status.idle": "2023-07-26T19:30:22.647237Z",
"shell.execute_reply": "2023-07-26T19:30:22.646934Z"
}
},
"outputs": [],
@@ -961,7 +950,7 @@
"X = rng.standard_normal((200, 2))\n",
"X[:100] += 2\n",
"X[100:150] -= 2\n",
"y = np.array([1]*150+[2]*50)\n"
"y = np.array([1]*150+[2]*50)"
]
},
{
@@ -978,18 +967,17 @@
"id": "04fda182",
"metadata": {
"execution": {
"iopub.execute_input": "2023-07-26T05:17:59.451843Z",
"iopub.status.busy": "2023-07-26T05:17:59.451105Z",
"iopub.status.idle": "2023-07-26T05:17:59.552259Z",
"shell.execute_reply": "2023-07-26T05:17:59.551787Z"
},
"lines_to_next_cell": 2
"iopub.execute_input": "2023-07-26T19:30:22.648795Z",
"iopub.status.busy": "2023-07-26T19:30:22.648693Z",
"iopub.status.idle": "2023-07-26T19:30:22.737682Z",
"shell.execute_reply": "2023-07-26T19:30:22.737352Z"
}
},
"outputs": [
{
"data": {
"text/plain": [
"<matplotlib.collections.PathCollection at 0x17641f9d0>"
"<matplotlib.collections.PathCollection at 0x157b6e810>"
]
},
"execution_count": 20,
@@ -1012,7 +1000,7 @@
"ax.scatter(X[:,0],\n",
" X[:,1],\n",
" c=y,\n",
" cmap=cm.coolwarm)\n"
" cmap=cm.coolwarm)"
]
},
{
@@ -1031,17 +1019,17 @@
"id": "0c2690d1",
"metadata": {
"execution": {
"iopub.execute_input": "2023-07-26T05:17:59.554419Z",
"iopub.status.busy": "2023-07-26T05:17:59.554263Z",
"iopub.status.idle": "2023-07-26T05:17:59.559300Z",
"shell.execute_reply": "2023-07-26T05:17:59.558839Z"
"iopub.execute_input": "2023-07-26T19:30:22.739293Z",
"iopub.status.busy": "2023-07-26T19:30:22.739179Z",
"iopub.status.idle": "2023-07-26T19:30:22.743290Z",
"shell.execute_reply": "2023-07-26T19:30:22.743048Z"
}
},
"outputs": [
{
"data": {
"text/html": [
"<style>#sk-container-id-2 {color: black;background-color: white;}#sk-container-id-2 pre{padding: 0;}#sk-container-id-2 div.sk-toggleable {background-color: white;}#sk-container-id-2 label.sk-toggleable__label {cursor: pointer;display: block;width: 100%;margin-bottom: 0;padding: 0.3em;box-sizing: border-box;text-align: center;}#sk-container-id-2 label.sk-toggleable__label-arrow:before {content: \"▸\";float: left;margin-right: 0.25em;color: #696969;}#sk-container-id-2 label.sk-toggleable__label-arrow:hover:before {color: black;}#sk-container-id-2 div.sk-estimator:hover label.sk-toggleable__label-arrow:before {color: black;}#sk-container-id-2 div.sk-toggleable__content {max-height: 0;max-width: 0;overflow: hidden;text-align: left;background-color: #f0f8ff;}#sk-container-id-2 div.sk-toggleable__content pre {margin: 0.2em;color: black;border-radius: 0.25em;background-color: #f0f8ff;}#sk-container-id-2 input.sk-toggleable__control:checked~div.sk-toggleable__content {max-height: 200px;max-width: 100%;overflow: auto;}#sk-container-id-2 input.sk-toggleable__control:checked~label.sk-toggleable__label-arrow:before {content: \"▾\";}#sk-container-id-2 div.sk-estimator input.sk-toggleable__control:checked~label.sk-toggleable__label {background-color: #d4ebff;}#sk-container-id-2 div.sk-label input.sk-toggleable__control:checked~label.sk-toggleable__label {background-color: #d4ebff;}#sk-container-id-2 input.sk-hidden--visually {border: 0;clip: rect(1px 1px 1px 1px);clip: rect(1px, 1px, 1px, 1px);height: 1px;margin: -1px;overflow: hidden;padding: 0;position: absolute;width: 1px;}#sk-container-id-2 div.sk-estimator {font-family: monospace;background-color: #f0f8ff;border: 1px dotted black;border-radius: 0.25em;box-sizing: border-box;margin-bottom: 0.5em;}#sk-container-id-2 div.sk-estimator:hover {background-color: #d4ebff;}#sk-container-id-2 div.sk-parallel-item::after {content: \"\";width: 100%;border-bottom: 1px solid gray;flex-grow: 1;}#sk-container-id-2 div.sk-label:hover label.sk-toggleable__label {background-color: #d4ebff;}#sk-container-id-2 div.sk-serial::before {content: \"\";position: absolute;border-left: 1px solid gray;box-sizing: border-box;top: 0;bottom: 0;left: 50%;z-index: 0;}#sk-container-id-2 div.sk-serial {display: flex;flex-direction: column;align-items: center;background-color: white;padding-right: 0.2em;padding-left: 0.2em;position: relative;}#sk-container-id-2 div.sk-item {position: relative;z-index: 1;}#sk-container-id-2 div.sk-parallel {display: flex;align-items: stretch;justify-content: center;background-color: white;position: relative;}#sk-container-id-2 div.sk-item::before, #sk-container-id-2 div.sk-parallel-item::before {content: \"\";position: absolute;border-left: 1px solid gray;box-sizing: border-box;top: 0;bottom: 0;left: 50%;z-index: -1;}#sk-container-id-2 div.sk-parallel-item {display: flex;flex-direction: column;z-index: 1;position: relative;background-color: white;}#sk-container-id-2 div.sk-parallel-item:first-child::after {align-self: flex-end;width: 50%;}#sk-container-id-2 div.sk-parallel-item:last-child::after {align-self: flex-start;width: 50%;}#sk-container-id-2 div.sk-parallel-item:only-child::after {width: 0;}#sk-container-id-2 div.sk-dashed-wrapped {border: 1px dashed gray;margin: 0 0.4em 0.5em 0.4em;box-sizing: border-box;padding-bottom: 0.4em;background-color: white;}#sk-container-id-2 div.sk-label label {font-family: monospace;font-weight: bold;display: inline-block;line-height: 1.2em;}#sk-container-id-2 div.sk-label-container {text-align: center;}#sk-container-id-2 div.sk-container {/* jupyter's `normalize.less` sets `[hidden] { display: none; }` but bootstrap.min.css set `[hidden] { display: none !important; }` so we also need the `!important` here to be able to override the default hidden behavior on the sphinx rendered scikit-learn.org. See: https://github.com/scikit-learn/scikit-learn/issues/21755 */display: inline-block !important;position: relative;}#sk-container-id-2 div.sk-text-repr-fallback {display: none;}</style><div id=\"sk-container-id-2\" class=\"sk-top-container\"><div class=\"sk-text-repr-fallback\"><pre>SVC(C=1, gamma=1)</pre><b>In a Jupyter environment, please rerun this cell to show the HTML representation or trust the notebook. <br />On GitHub, the HTML representation is unable to render, please try loading this page with nbviewer.org.</b></div><div class=\"sk-container\" hidden><div class=\"sk-item\"><div class=\"sk-estimator sk-toggleable\"><input class=\"sk-toggleable__control sk-hidden--visually\" id=\"sk-estimator-id-2\" type=\"checkbox\" checked><label for=\"sk-estimator-id-2\" class=\"sk-toggleable__label sk-toggleable__label-arrow\">SVC</label><div class=\"sk-toggleable__content\"><pre>SVC(C=1, gamma=1)</pre></div></div></div></div></div>"
"<style>#sk-container-id-2 {color: black;}#sk-container-id-2 pre{padding: 0;}#sk-container-id-2 div.sk-toggleable {background-color: white;}#sk-container-id-2 label.sk-toggleable__label {cursor: pointer;display: block;width: 100%;margin-bottom: 0;padding: 0.3em;box-sizing: border-box;text-align: center;}#sk-container-id-2 label.sk-toggleable__label-arrow:before {content: \"▸\";float: left;margin-right: 0.25em;color: #696969;}#sk-container-id-2 label.sk-toggleable__label-arrow:hover:before {color: black;}#sk-container-id-2 div.sk-estimator:hover label.sk-toggleable__label-arrow:before {color: black;}#sk-container-id-2 div.sk-toggleable__content {max-height: 0;max-width: 0;overflow: hidden;text-align: left;background-color: #f0f8ff;}#sk-container-id-2 div.sk-toggleable__content pre {margin: 0.2em;color: black;border-radius: 0.25em;background-color: #f0f8ff;}#sk-container-id-2 input.sk-toggleable__control:checked~div.sk-toggleable__content {max-height: 200px;max-width: 100%;overflow: auto;}#sk-container-id-2 input.sk-toggleable__control:checked~label.sk-toggleable__label-arrow:before {content: \"▾\";}#sk-container-id-2 div.sk-estimator input.sk-toggleable__control:checked~label.sk-toggleable__label {background-color: #d4ebff;}#sk-container-id-2 div.sk-label input.sk-toggleable__control:checked~label.sk-toggleable__label {background-color: #d4ebff;}#sk-container-id-2 input.sk-hidden--visually {border: 0;clip: rect(1px 1px 1px 1px);clip: rect(1px, 1px, 1px, 1px);height: 1px;margin: -1px;overflow: hidden;padding: 0;position: absolute;width: 1px;}#sk-container-id-2 div.sk-estimator {font-family: monospace;background-color: #f0f8ff;border: 1px dotted black;border-radius: 0.25em;box-sizing: border-box;margin-bottom: 0.5em;}#sk-container-id-2 div.sk-estimator:hover {background-color: #d4ebff;}#sk-container-id-2 div.sk-parallel-item::after {content: \"\";width: 100%;border-bottom: 1px solid gray;flex-grow: 1;}#sk-container-id-2 div.sk-label:hover label.sk-toggleable__label {background-color: #d4ebff;}#sk-container-id-2 div.sk-serial::before {content: \"\";position: absolute;border-left: 1px solid gray;box-sizing: border-box;top: 0;bottom: 0;left: 50%;z-index: 0;}#sk-container-id-2 div.sk-serial {display: flex;flex-direction: column;align-items: center;background-color: white;padding-right: 0.2em;padding-left: 0.2em;position: relative;}#sk-container-id-2 div.sk-item {position: relative;z-index: 1;}#sk-container-id-2 div.sk-parallel {display: flex;align-items: stretch;justify-content: center;background-color: white;position: relative;}#sk-container-id-2 div.sk-item::before, #sk-container-id-2 div.sk-parallel-item::before {content: \"\";position: absolute;border-left: 1px solid gray;box-sizing: border-box;top: 0;bottom: 0;left: 50%;z-index: -1;}#sk-container-id-2 div.sk-parallel-item {display: flex;flex-direction: column;z-index: 1;position: relative;background-color: white;}#sk-container-id-2 div.sk-parallel-item:first-child::after {align-self: flex-end;width: 50%;}#sk-container-id-2 div.sk-parallel-item:last-child::after {align-self: flex-start;width: 50%;}#sk-container-id-2 div.sk-parallel-item:only-child::after {width: 0;}#sk-container-id-2 div.sk-dashed-wrapped {border: 1px dashed gray;margin: 0 0.4em 0.5em 0.4em;box-sizing: border-box;padding-bottom: 0.4em;background-color: white;}#sk-container-id-2 div.sk-label label {font-family: monospace;font-weight: bold;display: inline-block;line-height: 1.2em;}#sk-container-id-2 div.sk-label-container {text-align: center;}#sk-container-id-2 div.sk-container {/* jupyter's `normalize.less` sets `[hidden] { display: none; }` but bootstrap.min.css set `[hidden] { display: none !important; }` so we also need the `!important` here to be able to override the default hidden behavior on the sphinx rendered scikit-learn.org. See: https://github.com/scikit-learn/scikit-learn/issues/21755 */display: inline-block !important;position: relative;}#sk-container-id-2 div.sk-text-repr-fallback {display: none;}</style><div id=\"sk-container-id-2\" class=\"sk-top-container\"><div class=\"sk-text-repr-fallback\"><pre>SVC(C=1, gamma=1)</pre><b>In a Jupyter environment, please rerun this cell to show the HTML representation or trust the notebook. <br />On GitHub, the HTML representation is unable to render, please try loading this page with nbviewer.org.</b></div><div class=\"sk-container\" hidden><div class=\"sk-item\"><div class=\"sk-estimator sk-toggleable\"><input class=\"sk-toggleable__control sk-hidden--visually\" id=\"sk-estimator-id-2\" type=\"checkbox\" checked><label for=\"sk-estimator-id-2\" class=\"sk-toggleable__label sk-toggleable__label-arrow\">SVC</label><div class=\"sk-toggleable__content\"><pre>SVC(C=1, gamma=1)</pre></div></div></div></div></div>"
],
"text/plain": [
"SVC(C=1, gamma=1)"
@@ -1061,7 +1049,7 @@
" test_size=0.5,\n",
" random_state=0)\n",
"svm_rbf = SVC(kernel=\"rbf\", gamma=1, C=1)\n",
"svm_rbf.fit(X_train, y_train)\n"
"svm_rbf.fit(X_train, y_train)"
]
},
{
@@ -1070,7 +1058,7 @@
"metadata": {},
"source": [
"The plot shows that the resulting SVM has a decidedly non-linear\n",
"boundary. "
"boundary."
]
},
{
@@ -1079,10 +1067,10 @@
"id": "3eb171e8",
"metadata": {
"execution": {
"iopub.execute_input": "2023-07-26T05:17:59.561548Z",
"iopub.status.busy": "2023-07-26T05:17:59.561354Z",
"iopub.status.idle": "2023-07-26T05:17:59.836831Z",
"shell.execute_reply": "2023-07-26T05:17:59.836408Z"
"iopub.execute_input": "2023-07-26T19:30:22.744866Z",
"iopub.status.busy": "2023-07-26T19:30:22.744774Z",
"iopub.status.idle": "2023-07-26T19:30:22.999527Z",
"shell.execute_reply": "2023-07-26T19:30:22.999240Z"
}
},
"outputs": [
@@ -1102,7 +1090,7 @@
"plot_svm(X_train,\n",
" y_train,\n",
" svm_rbf,\n",
" ax=ax)\n"
" ax=ax)"
]
},
{
@@ -1123,10 +1111,10 @@
"id": "9a6b905b",
"metadata": {
"execution": {
"iopub.execute_input": "2023-07-26T05:17:59.839191Z",
"iopub.status.busy": "2023-07-26T05:17:59.838970Z",
"iopub.status.idle": "2023-07-26T05:18:00.004302Z",
"shell.execute_reply": "2023-07-26T05:18:00.003731Z"
"iopub.execute_input": "2023-07-26T19:30:23.001234Z",
"iopub.status.busy": "2023-07-26T19:30:23.001125Z",
"iopub.status.idle": "2023-07-26T19:30:23.153325Z",
"shell.execute_reply": "2023-07-26T19:30:23.152993Z"
}
},
"outputs": [
@@ -1148,7 +1136,7 @@
"plot_svm(X_train,\n",
" y_train,\n",
" svm_rbf,\n",
" ax=ax)\n"
" ax=ax)"
]
},
{
@@ -1167,10 +1155,10 @@
"id": "5ab01d6c",
"metadata": {
"execution": {
"iopub.execute_input": "2023-07-26T05:18:00.007020Z",
"iopub.status.busy": "2023-07-26T05:18:00.006845Z",
"iopub.status.idle": "2023-07-26T05:18:00.113455Z",
"shell.execute_reply": "2023-07-26T05:18:00.112946Z"
"iopub.execute_input": "2023-07-26T19:30:23.155062Z",
"iopub.status.busy": "2023-07-26T19:30:23.154942Z",
"iopub.status.idle": "2023-07-26T19:30:23.246256Z",
"shell.execute_reply": "2023-07-26T19:30:23.245948Z"
}
},
"outputs": [
@@ -1196,7 +1184,7 @@
" cv=kfold,\n",
" scoring='accuracy');\n",
"grid.fit(X_train, y_train)\n",
"grid.best_params_\n"
"grid.best_params_"
]
},
{
@@ -1215,10 +1203,10 @@
"id": "166a6acb",
"metadata": {
"execution": {
"iopub.execute_input": "2023-07-26T05:18:00.116122Z",
"iopub.status.busy": "2023-07-26T05:18:00.115942Z",
"iopub.status.idle": "2023-07-26T05:18:00.360989Z",
"shell.execute_reply": "2023-07-26T05:18:00.360361Z"
"iopub.execute_input": "2023-07-26T19:30:23.247818Z",
"iopub.status.busy": "2023-07-26T19:30:23.247730Z",
"iopub.status.idle": "2023-07-26T19:30:23.480058Z",
"shell.execute_reply": "2023-07-26T19:30:23.479735Z"
}
},
"outputs": [
@@ -1298,7 +1286,7 @@
" ax=ax)\n",
"\n",
"y_hat_test = best_svm.predict(X_test)\n",
"confusion_table(y_hat_test, y_test)\n"
"confusion_table(y_hat_test, y_test)"
]
},
{
@@ -1349,12 +1337,11 @@
"id": "0607fc41",
"metadata": {
"execution": {
"iopub.execute_input": "2023-07-26T05:18:00.363471Z",
"iopub.status.busy": "2023-07-26T05:18:00.363318Z",
"iopub.status.idle": "2023-07-26T05:18:00.469265Z",
"shell.execute_reply": "2023-07-26T05:18:00.468690Z"
},
"lines_to_next_cell": 0
"iopub.execute_input": "2023-07-26T19:30:23.481797Z",
"iopub.status.busy": "2023-07-26T19:30:23.481689Z",
"iopub.status.idle": "2023-07-26T19:30:23.570996Z",
"shell.execute_reply": "2023-07-26T19:30:23.570713Z"
}
},
"outputs": [
{
@@ -1375,7 +1362,7 @@
" y_train,\n",
" name='Training',\n",
" color='r',\n",
" ax=ax);\n"
" ax=ax);"
]
},
{
@@ -1394,10 +1381,10 @@
"id": "5211a882",
"metadata": {
"execution": {
"iopub.execute_input": "2023-07-26T05:18:00.471742Z",
"iopub.status.busy": "2023-07-26T05:18:00.471575Z",
"iopub.status.idle": "2023-07-26T05:18:00.629647Z",
"shell.execute_reply": "2023-07-26T05:18:00.629119Z"
"iopub.execute_input": "2023-07-26T19:30:23.572826Z",
"iopub.status.busy": "2023-07-26T19:30:23.572704Z",
"iopub.status.idle": "2023-07-26T19:30:23.710067Z",
"shell.execute_reply": "2023-07-26T19:30:23.709718Z"
}
},
"outputs": [
@@ -1423,7 +1410,7 @@
" y_train,\n",
" name='Training $\\gamma=50$',\n",
" color='r',\n",
" ax=ax);\n"
" ax=ax);"
]
},
{
@@ -1443,10 +1430,10 @@
"id": "12acc4ff",
"metadata": {
"execution": {
"iopub.execute_input": "2023-07-26T05:18:00.632175Z",
"iopub.status.busy": "2023-07-26T05:18:00.631994Z",
"iopub.status.idle": "2023-07-26T05:18:00.636710Z",
"shell.execute_reply": "2023-07-26T05:18:00.636238Z"
"iopub.execute_input": "2023-07-26T19:30:23.711836Z",
"iopub.status.busy": "2023-07-26T19:30:23.711704Z",
"iopub.status.idle": "2023-07-26T19:30:23.715844Z",
"shell.execute_reply": "2023-07-26T19:30:23.715547Z"
}
},
"outputs": [],
@@ -1457,7 +1444,7 @@
" name='Test $\\gamma=50$',\n",
" color='b',\n",
" ax=ax)\n",
"fig;\n"
"fig;"
]
},
{
@@ -1474,10 +1461,10 @@
"id": "21c81913",
"metadata": {
"execution": {
"iopub.execute_input": "2023-07-26T05:18:00.639004Z",
"iopub.status.busy": "2023-07-26T05:18:00.638813Z",
"iopub.status.idle": "2023-07-26T05:18:00.753454Z",
"shell.execute_reply": "2023-07-26T05:18:00.752986Z"
"iopub.execute_input": "2023-07-26T19:30:23.717442Z",
"iopub.status.busy": "2023-07-26T19:30:23.717349Z",
"iopub.status.idle": "2023-07-26T19:30:23.813301Z",
"shell.execute_reply": "2023-07-26T19:30:23.812976Z"
}
},
"outputs": [
@@ -1505,7 +1492,7 @@
" y_,\n",
" name=name,\n",
" ax=ax,\n",
" color=c)\n"
" color=c)"
]
},
{
@@ -1529,10 +1516,10 @@
"id": "2fff4fa8",
"metadata": {
"execution": {
"iopub.execute_input": "2023-07-26T05:18:00.756116Z",
"iopub.status.busy": "2023-07-26T05:18:00.755939Z",
"iopub.status.idle": "2023-07-26T05:18:00.855998Z",
"shell.execute_reply": "2023-07-26T05:18:00.855206Z"
"iopub.execute_input": "2023-07-26T19:30:23.815030Z",
"iopub.status.busy": "2023-07-26T19:30:23.814911Z",
"iopub.status.idle": "2023-07-26T19:30:23.901789Z",
"shell.execute_reply": "2023-07-26T19:30:23.901472Z"
}
},
"outputs": [
@@ -1553,7 +1540,7 @@
"y = np.hstack([y, [0]*50])\n",
"X[y==0,1] += 2\n",
"fig, ax = subplots(figsize=(8,8))\n",
"ax.scatter(X[:,0], X[:,1], c=y, cmap=cm.coolwarm);\n"
"ax.scatter(X[:,0], X[:,1], c=y, cmap=cm.coolwarm);"
]
},
{
@@ -1570,12 +1557,11 @@
"id": "5396f2df",
"metadata": {
"execution": {
"iopub.execute_input": "2023-07-26T05:18:00.861579Z",
"iopub.status.busy": "2023-07-26T05:18:00.861401Z",
"iopub.status.idle": "2023-07-26T05:18:01.455936Z",
"shell.execute_reply": "2023-07-26T05:18:01.455227Z"
},
"lines_to_next_cell": 0
"iopub.execute_input": "2023-07-26T19:30:23.903488Z",
"iopub.status.busy": "2023-07-26T19:30:23.903367Z",
"iopub.status.idle": "2023-07-26T19:30:24.478035Z",
"shell.execute_reply": "2023-07-26T19:30:24.477752Z"
}
},
"outputs": [
{
@@ -1600,7 +1586,7 @@
" y,\n",
" svm_rbf_3,\n",
" scatter_cmap=cm.tab10,\n",
" ax=ax)\n"
" ax=ax)"
]
},
{
@@ -1634,10 +1620,10 @@
"id": "f63c575e",
"metadata": {
"execution": {
"iopub.execute_input": "2023-07-26T05:18:01.458214Z",
"iopub.status.busy": "2023-07-26T05:18:01.458015Z",
"iopub.status.idle": "2023-07-26T05:18:01.539063Z",
"shell.execute_reply": "2023-07-26T05:18:01.538275Z"
"iopub.execute_input": "2023-07-26T19:30:24.479854Z",
"iopub.status.busy": "2023-07-26T19:30:24.479740Z",
"iopub.status.idle": "2023-07-26T19:30:24.553046Z",
"shell.execute_reply": "2023-07-26T19:30:24.552768Z"
}
},
"outputs": [
@@ -1654,7 +1640,7 @@
],
"source": [
"Khan = load_data('Khan')\n",
"Khan['xtrain'].shape, Khan['xtest'].shape\n"
"Khan['xtrain'].shape, Khan['xtest'].shape"
]
},
{
@@ -1671,7 +1657,7 @@
"large number of features relative to the number of observations. This\n",
"suggests that we should use a linear kernel, because the additional\n",
"flexibility that will result from using a polynomial or radial kernel \n",
"is unnecessary. "
"is unnecessary."
]
},
{
@@ -1680,10 +1666,10 @@
"id": "32091338",
"metadata": {
"execution": {
"iopub.execute_input": "2023-07-26T05:18:01.541953Z",
"iopub.status.busy": "2023-07-26T05:18:01.541758Z",
"iopub.status.idle": "2023-07-26T05:18:01.578259Z",
"shell.execute_reply": "2023-07-26T05:18:01.577863Z"
"iopub.execute_input": "2023-07-26T19:30:24.554699Z",
"iopub.status.busy": "2023-07-26T19:30:24.554597Z",
"iopub.status.idle": "2023-07-26T19:30:24.583168Z",
"shell.execute_reply": "2023-07-26T19:30:24.582899Z"
}
},
"outputs": [
@@ -1772,7 +1758,7 @@
"khan_linear = SVC(kernel='linear', C=10)\n",
"khan_linear.fit(Khan['xtrain'], Khan['ytrain'])\n",
"confusion_table(khan_linear.predict(Khan['xtrain']),\n",
" Khan['ytrain'])\n"
" Khan['ytrain'])"
]
},
{
@@ -1794,10 +1780,10 @@
"id": "d9058023",
"metadata": {
"execution": {
"iopub.execute_input": "2023-07-26T05:18:01.582842Z",
"iopub.status.busy": "2023-07-26T05:18:01.582631Z",
"iopub.status.idle": "2023-07-26T05:18:01.598298Z",
"shell.execute_reply": "2023-07-26T05:18:01.597510Z"
"iopub.execute_input": "2023-07-26T19:30:24.584794Z",
"iopub.status.busy": "2023-07-26T19:30:24.584676Z",
"iopub.status.idle": "2023-07-26T19:30:24.595404Z",
"shell.execute_reply": "2023-07-26T19:30:24.595053Z"
}
},
"outputs": [
@@ -1884,7 +1870,7 @@
],
"source": [
"confusion_table(khan_linear.predict(Khan['xtest']),\n",
" Khan['ytest'])\n"
" Khan['ytest'])"
]
},
{
@@ -1892,16 +1878,15 @@
"id": "d0d5aba4",
"metadata": {},
"source": [
"We see that using `C=10` yields two test set errors on these data.\n",
"\n"
"We see that using `C=10` yields two test set errors on these data."
]
}
],
"metadata": {
"jupytext": {
"cell_metadata_filter": "-all",
"main_language": "python",
"notebook_metadata_filter": "-all"
"formats": "ipynb,md:myst",
"main_language": "python"
},
"language_info": {
"codemirror_mode": {
@@ -1913,7 +1898,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.9.17"
"version": "3.11.4"
}
},
"nbformat": 4,
+9 -9
View File
@@ -1,11 +1,11 @@
numpy==1.21.6
scipy==1.10.1
pandas==1.4.1
lxml==4.8.0
scikit-learn==1.2.2
joblib==1.2.0
statsmodels==0.13.2
lifelines==0.27.6
pygam==0.8.0
numpy==1.24.2
scipy==1.11.1
pandas==1.5.3
lxml==4.9.3
scikit-learn==1.3.0
joblib==1.3.1
statsmodels==0.14.0
lifelines==0.27.7
pygam==0.9.0
l0bnb==1.0.0
+5 -5
View File
@@ -1,5 +1,5 @@
torch==2.0.0
torchvision==0.15.1
pytorch_lightning==1.7.7
torchinfo==1.7.2
torchmetrics==0.9.3
torch==2.0.1
torchvision==0.15.2
pytorch-lightning==2.0.6
torchinfo==1.8.0
torchmetrics==1.0.1