first edit to v2
This commit is contained in:
File diff suppressed because one or more lines are too long
@@ -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,
|
||||
|
||||
File diff suppressed because one or more lines are too long
@@ -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,
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
File diff suppressed because one or more lines are too long
File diff suppressed because it is too large
Load Diff
@@ -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,
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
@@ -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='linear')</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='linear')</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='linear')</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='linear')</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,
|
||||
|
||||
@@ -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
|
||||
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user