erjonb commited on
Commit
9b14991
·
1 Parent(s): 639981e

Upload P2 - Secom Notebook2 - Mercury.ipynb

Browse files
Files changed (1) hide show
  1. P2 - Secom Notebook2 - Mercury.ipynb +1571 -0
P2 - Secom Notebook2 - Mercury.ipynb ADDED
@@ -0,0 +1,1571 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 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
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "cells": [
3
+ {
4
+ "attachments": {},
5
+ "cell_type": "markdown",
6
+ "metadata": {
7
+ "slideshow": {
8
+ "slide_type": "skip"
9
+ }
10
+ },
11
+ "source": [
12
+ "# **Classifying products in Semiconductor Industry**"
13
+ ]
14
+ },
15
+ {
16
+ "attachments": {},
17
+ "cell_type": "markdown",
18
+ "metadata": {
19
+ "slideshow": {
20
+ "slide_type": "skip"
21
+ }
22
+ },
23
+ "source": [
24
+ "#### **Import the data**"
25
+ ]
26
+ },
27
+ {
28
+ "cell_type": "code",
29
+ "execution_count": 85,
30
+ "metadata": {},
31
+ "outputs": [],
32
+ "source": [
33
+ "# import pandas for data manipulation\n",
34
+ "# import numpy for numerical computation\n",
35
+ "# import seaborn for data visualization\n",
36
+ "# import matplotlib for data visualization\n",
37
+ "# import stats for statistical analysis\n",
38
+ "# import train_test_split for splitting data into training and testing sets\n",
39
+ "\n",
40
+ "import mercury as mr\n",
41
+ "import pandas as pd\n",
42
+ "import numpy as np\n",
43
+ "import seaborn as sns\n",
44
+ "import matplotlib.pyplot as plt\n",
45
+ "from scipy import stats\n",
46
+ "from sklearn.model_selection import train_test_split\n",
47
+ "import warnings\n",
48
+ "warnings.filterwarnings('ignore')\n",
49
+ "from mlxtend.plotting import plot_confusion_matrix\n",
50
+ "from sklearn.metrics import confusion_matrix, accuracy_score, precision_score, recall_score, f1_score\n",
51
+ "from mlxtend.plotting import plot_confusion_matrix"
52
+ ]
53
+ },
54
+ {
55
+ "cell_type": "code",
56
+ "execution_count": 86,
57
+ "metadata": {},
58
+ "outputs": [
59
+ {
60
+ "data": {
61
+ "application/mercury+json": {
62
+ "allow_download": true,
63
+ "code_uid": "App.0.40.24.1-rand8c10e2d9",
64
+ "continuous_update": false,
65
+ "description": "Recumpute everything dynamically",
66
+ "full_screen": true,
67
+ "model_id": "mercury-app",
68
+ "notify": "{}",
69
+ "output": "app",
70
+ "schedule": "",
71
+ "show_code": false,
72
+ "show_prompt": false,
73
+ "show_sidebar": true,
74
+ "static_notebook": false,
75
+ "title": "Secom Web App Demo",
76
+ "widget": "App"
77
+ },
78
+ "text/html": [
79
+ "<h3>Mercury Application</h3><small>This output won't appear in the web app.</small>"
80
+ ],
81
+ "text/plain": [
82
+ "mercury.App"
83
+ ]
84
+ },
85
+ "metadata": {},
86
+ "output_type": "display_data"
87
+ }
88
+ ],
89
+ "source": [
90
+ "app = mr.App(title=\"Secom Web App Demo\", description=\"Recumpute everything dynamically\", continuous_update=False)"
91
+ ]
92
+ },
93
+ {
94
+ "cell_type": "code",
95
+ "execution_count": 87,
96
+ "metadata": {},
97
+ "outputs": [],
98
+ "source": [
99
+ "# Read the features data from the the url of csv into pandas dataframes and rename the columns to F1, F2, F3, etc.\n",
100
+ "# Read the labels data from the url of csv into pandas dataframes and rename the columns to pass/fail and date/time\n",
101
+ "\n",
102
+ "#url_data = 'https://archive.ics.uci.edu/ml/machine-learning-databases/secom/secom.data'\n",
103
+ "#url_labels = 'https://archive.ics.uci.edu/ml/machine-learning-databases/secom/secom_labels.data'\n",
104
+ "\n",
105
+ "url_data = 'secom_data.csv'\n",
106
+ "url_labels = 'secom_labels.csv'\n",
107
+ "\n",
108
+ "features = pd.read_csv(url_data, delimiter=' ', header=None)\n",
109
+ "labels = pd.read_csv(url_labels, delimiter=' ', names=['pass/fail', 'date_time'])\n",
110
+ "\n",
111
+ "prefix = 'F'\n",
112
+ "new_column_names = [prefix + str(i) for i in range(1, len(features.columns)+1)]\n",
113
+ "features.columns = new_column_names\n",
114
+ "\n",
115
+ "labels['pass/fail'] = labels['pass/fail'].replace({-1: 0, 1: 1})\n"
116
+ ]
117
+ },
118
+ {
119
+ "attachments": {},
120
+ "cell_type": "markdown",
121
+ "metadata": {
122
+ "slideshow": {
123
+ "slide_type": "skip"
124
+ }
125
+ },
126
+ "source": [
127
+ "#### **Split the data**"
128
+ ]
129
+ },
130
+ {
131
+ "cell_type": "code",
132
+ "execution_count": 88,
133
+ "metadata": {},
134
+ "outputs": [
135
+ {
136
+ "data": {
137
+ "application/mercury+json": {
138
+ "code_uid": "Text.0.40.15.11-rand39f89858",
139
+ "disabled": false,
140
+ "hidden": false,
141
+ "label": "Test Size Ratio",
142
+ "model_id": "271115d337014695a05d7e83307b4cc4",
143
+ "rows": 1,
144
+ "url_key": "",
145
+ "value": "0.25",
146
+ "widget": "Text"
147
+ },
148
+ "application/vnd.jupyter.widget-view+json": {
149
+ "model_id": "271115d337014695a05d7e83307b4cc4",
150
+ "version_major": 2,
151
+ "version_minor": 0
152
+ },
153
+ "text/plain": [
154
+ "mercury.Text"
155
+ ]
156
+ },
157
+ "metadata": {},
158
+ "output_type": "display_data"
159
+ },
160
+ {
161
+ "data": {
162
+ "application/mercury+json": {
163
+ "code_uid": "Text.0.40.15.14-randf159337c",
164
+ "disabled": false,
165
+ "hidden": false,
166
+ "label": "Random State Integer",
167
+ "model_id": "87a237754fa24e11a17700de955552a8",
168
+ "rows": 1,
169
+ "url_key": "",
170
+ "value": "13",
171
+ "widget": "Text"
172
+ },
173
+ "application/vnd.jupyter.widget-view+json": {
174
+ "model_id": "87a237754fa24e11a17700de955552a8",
175
+ "version_major": 2,
176
+ "version_minor": 0
177
+ },
178
+ "text/plain": [
179
+ "mercury.Text"
180
+ ]
181
+ },
182
+ "metadata": {},
183
+ "output_type": "display_data"
184
+ }
185
+ ],
186
+ "source": [
187
+ "# if there is a date/time column, drop it from the features and labels dataframes, else continue\n",
188
+ "\n",
189
+ "if 'date_time' in labels.columns:\n",
190
+ " labels = labels.drop(['date_time'], axis=1)\n",
191
+ "\n",
192
+ "\n",
193
+ "# Split the dataset and the labels into training and testing sets\n",
194
+ "# use stratify to ensure that the training and testing sets have the same percentage of pass and fail labels\n",
195
+ "# use random_state to ensure that the same random split is generated each time the code is run\n",
196
+ "\n",
197
+ "test_size_num = mr.Text(label=\"Test Size Ratio\", value='0.25') # \n",
198
+ "test_size_num = float(test_size_num.value)\n",
199
+ "\n",
200
+ "random_state_num = mr.Text(label=\"Random State Integer\", value='13') # \n",
201
+ "random_state_num = int(random_state_num.value)\n",
202
+ "\n",
203
+ "\n",
204
+ "X_train, X_test, y_train, y_test = train_test_split(\n",
205
+ " features, labels, test_size = test_size_num, stratify=labels, random_state=random_state_num)\n",
206
+ "\n"
207
+ ]
208
+ },
209
+ {
210
+ "attachments": {},
211
+ "cell_type": "markdown",
212
+ "metadata": {
213
+ "slideshow": {
214
+ "slide_type": "skip"
215
+ }
216
+ },
217
+ "source": [
218
+ "#### **Feature Removal**"
219
+ ]
220
+ },
221
+ {
222
+ "cell_type": "code",
223
+ "execution_count": 89,
224
+ "metadata": {},
225
+ "outputs": [],
226
+ "source": [
227
+ "def columns_to_drop(df,drop_duplicates='yes', missing_values_threshold=100, variance_threshold=0, \n",
228
+ " correlation_threshold=1.1):\n",
229
+ " \n",
230
+ " print('------------------------------------------')\n",
231
+ " print('FEATURE REMOVAL')\n",
232
+ " \n",
233
+ " print('Shape of the dataframe is: ', df.shape)\n",
234
+ "\n",
235
+ " # Drop duplicated columns\n",
236
+ " if drop_duplicates == 'yes':\n",
237
+ " new_column_names = df.columns\n",
238
+ " df = df.T.drop_duplicates().T\n",
239
+ " print('the number of columns dropped due to duplications is: ', len(new_column_names) - len(df.columns))\n",
240
+ " drop_duplicated = list(set(new_column_names) - set(df.columns))\n",
241
+ "\n",
242
+ " elif drop_duplicates == 'no':\n",
243
+ " df = df.T.T\n",
244
+ " print('No columns were dropped due to duplications') \n",
245
+ "\n",
246
+ " # Print the percentage of columns in df with missing values more than or equal to threshold\n",
247
+ " print('the number of columns dropped due to missing values is: ', len(df.isnull().mean()[df.isnull().mean() > missing_values_threshold/100].index))\n",
248
+ " \n",
249
+ " # Print into a list the columns to be dropped due to missing values\n",
250
+ " drop_missing = list(df.isnull().mean()[df.isnull().mean() > missing_values_threshold/100].index)\n",
251
+ "\n",
252
+ " # Drop columns with more than or equal to threshold missing values from df\n",
253
+ " df.drop(drop_missing, axis=1, inplace=True)\n",
254
+ " \n",
255
+ " # Print the number of columns in df with variance less than threshold\n",
256
+ " print('the number of columns dropped due to low variance is: ', len(df.var()[df.var() <= variance_threshold].index))\n",
257
+ "\n",
258
+ " # Print into a list the columns to be dropped due to low variance\n",
259
+ " drop_variance = list(df.var()[df.var() <= variance_threshold].index)\n",
260
+ "\n",
261
+ " # Drop columns with more than or equal to threshold variance from df\n",
262
+ " df.drop(drop_variance, axis=1, inplace=True)\n",
263
+ "\n",
264
+ " # Print the number of columns in df with more than or equal to threshold correlation\n",
265
+ " \n",
266
+ " # Create correlation matrix and round it to 4 decimal places\n",
267
+ " corr_matrix = df.corr().abs().round(4)\n",
268
+ " upper = corr_matrix.where(np.triu(np.ones(corr_matrix.shape), k=1).astype(bool))\n",
269
+ " to_drop = [column for column in upper.columns if any(upper[column] >= correlation_threshold)]\n",
270
+ " print('the number of columns dropped due to high correlation is: ', len(to_drop))\n",
271
+ "\n",
272
+ " # Print into a list the columns to be dropped due to high correlation\n",
273
+ " drop_correlation = [column for column in upper.columns if any(upper[column] >= correlation_threshold)]\n",
274
+ "\n",
275
+ " # Drop columns with more than or equal to threshold correlation from df\n",
276
+ " df.drop(to_drop, axis=1, inplace=True)\n",
277
+ " \n",
278
+ " if drop_duplicates == 'yes':\n",
279
+ " dropped = (drop_duplicated+drop_missing+drop_variance+drop_correlation)\n",
280
+ "\n",
281
+ " elif drop_duplicates =='no':\n",
282
+ " dropped = (drop_missing+drop_variance+drop_correlation)\n",
283
+ " \n",
284
+ " print('Total number of columns to be dropped is: ', len(dropped))\n",
285
+ " print('New shape of the dataframe is: ', df.shape)\n",
286
+ "\n",
287
+ " global drop_duplicates_var\n",
288
+ " drop_duplicates_var = drop_duplicates\n",
289
+ " \n",
290
+ " global missing_values_threshold_var\n",
291
+ " missing_values_threshold_var = missing_values_threshold\n",
292
+ "\n",
293
+ " global variance_threshold_var\n",
294
+ " variance_threshold_var = variance_threshold\n",
295
+ "\n",
296
+ " global correlation_threshold_var\n",
297
+ " correlation_threshold_var = correlation_threshold\n",
298
+ " \n",
299
+ " print(type(dropped))\n",
300
+ " return dropped"
301
+ ]
302
+ },
303
+ {
304
+ "attachments": {},
305
+ "cell_type": "markdown",
306
+ "metadata": {
307
+ "slideshow": {
308
+ "slide_type": "skip"
309
+ }
310
+ },
311
+ "source": [
312
+ "#### **Outlier Removal**"
313
+ ]
314
+ },
315
+ {
316
+ "cell_type": "code",
317
+ "execution_count": 90,
318
+ "metadata": {},
319
+ "outputs": [],
320
+ "source": [
321
+ "def outlier_removal(z_df, z_threshold=4):\n",
322
+ " \n",
323
+ " global outlier_var\n",
324
+ "\n",
325
+ " print('------------------------------------------')\n",
326
+ " print('OUTLIER REMOVAL')\n",
327
+ "\n",
328
+ " if z_threshold == 'none':\n",
329
+ " print('No outliers were removed')\n",
330
+ " outlier_var = 'none'\n",
331
+ " return z_df\n",
332
+ " \n",
333
+ " else:\n",
334
+ " print('The z-score threshold is:', z_threshold)\n",
335
+ "\n",
336
+ " z_df_copy = z_df.copy()\n",
337
+ "\n",
338
+ " z_scores = np.abs(stats.zscore(z_df_copy))\n",
339
+ "\n",
340
+ " # Identify the outliers in the dataset using the z-score method\n",
341
+ " outliers_mask = z_scores > z_threshold\n",
342
+ " z_df_copy[outliers_mask] = np.nan\n",
343
+ "\n",
344
+ " outliers_count = np.count_nonzero(outliers_mask)\n",
345
+ " print('The number of outliers removed from the dataset is:', outliers_count)\n",
346
+ "\n",
347
+ " outlier_var = z_threshold\n",
348
+ "\n",
349
+ " print(type(z_df_copy))\n",
350
+ " return z_df_copy"
351
+ ]
352
+ },
353
+ {
354
+ "attachments": {},
355
+ "cell_type": "markdown",
356
+ "metadata": {
357
+ "slideshow": {
358
+ "slide_type": "skip"
359
+ }
360
+ },
361
+ "source": [
362
+ "#### **Scaling Methods**"
363
+ ]
364
+ },
365
+ {
366
+ "cell_type": "code",
367
+ "execution_count": 91,
368
+ "metadata": {},
369
+ "outputs": [],
370
+ "source": [
371
+ "# define a function to scale the dataframe using different scaling models\n",
372
+ "\n",
373
+ "def scale_dataframe(scale_model,df_fit, df_transform):\n",
374
+ " \n",
375
+ " global scale_model_var\n",
376
+ "\n",
377
+ " print('------------------------------------------')\n",
378
+ " print('SCALING THE DATAFRAME')\n",
379
+ "\n",
380
+ " if scale_model == 'robust':\n",
381
+ " from sklearn.preprocessing import RobustScaler\n",
382
+ " scaler = RobustScaler()\n",
383
+ " scaler.fit(df_fit)\n",
384
+ " df_scaled = scaler.transform(df_transform)\n",
385
+ " df_scaled = pd.DataFrame(df_scaled, columns=df_transform.columns)\n",
386
+ " print('The dataframe has been scaled using the robust scaling model')\n",
387
+ " scale_model_var = 'robust'\n",
388
+ " return df_scaled\n",
389
+ " \n",
390
+ " elif scale_model == 'standard':\n",
391
+ " from sklearn.preprocessing import StandardScaler\n",
392
+ " scaler = StandardScaler()\n",
393
+ " scaler.fit(df_fit)\n",
394
+ " df_scaled = scaler.transform(df_transform)\n",
395
+ " df_scaled = pd.DataFrame(df_scaled, columns=df_transform.columns)\n",
396
+ " print('The dataframe has been scaled using the standard scaling model')\n",
397
+ " scale_model_var = 'standard'\n",
398
+ " return df_scaled\n",
399
+ " \n",
400
+ " elif scale_model == 'normal':\n",
401
+ " from sklearn.preprocessing import Normalizer\n",
402
+ " scaler = Normalizer()\n",
403
+ " scaler.fit(df_fit)\n",
404
+ " df_scaled = scaler.transform(df_transform)\n",
405
+ " df_scaled = pd.DataFrame(df_scaled, columns=df_transform.columns)\n",
406
+ " print('The dataframe has been scaled using the normal scaling model')\n",
407
+ " scale_model_var = 'normal'\n",
408
+ " return df_scaled\n",
409
+ " \n",
410
+ " elif scale_model == 'minmax':\n",
411
+ " from sklearn.preprocessing import MinMaxScaler\n",
412
+ " scaler = MinMaxScaler()\n",
413
+ " scaler.fit(df_fit)\n",
414
+ " df_scaled = scaler.transform(df_transform)\n",
415
+ " df_scaled = pd.DataFrame(df_scaled, columns=df_transform.columns)\n",
416
+ " print('The dataframe has been scaled using the minmax scaling model')\n",
417
+ " scale_model_var = 'minmax'\n",
418
+ " return df_scaled\n",
419
+ " \n",
420
+ " elif scale_model == 'none':\n",
421
+ " print('The dataframe has not been scaled')\n",
422
+ " scale_model_var = 'none'\n",
423
+ " return df_transform\n",
424
+ " \n",
425
+ " else:\n",
426
+ " print('Please choose a valid scaling model: robust, standard, normal, or minmax')\n",
427
+ " return None"
428
+ ]
429
+ },
430
+ {
431
+ "attachments": {},
432
+ "cell_type": "markdown",
433
+ "metadata": {
434
+ "slideshow": {
435
+ "slide_type": "skip"
436
+ }
437
+ },
438
+ "source": [
439
+ "#### **Missing Value Imputation**"
440
+ ]
441
+ },
442
+ {
443
+ "cell_type": "code",
444
+ "execution_count": 92,
445
+ "metadata": {},
446
+ "outputs": [],
447
+ "source": [
448
+ "# define a function to impute missing values using different imputation models\n",
449
+ "\n",
450
+ "def impute_missing_values(imputation, df_fit, df_transform, n_neighbors=5):\n",
451
+ "\n",
452
+ " print('------------------------------------------')\n",
453
+ " print('IMPUTATION PROCESS')\n",
454
+ " print('Number of missing values before imputation: ', df_transform.isnull().sum().sum())\n",
455
+ "\n",
456
+ " global imputation_var\n",
457
+ "\n",
458
+ " if imputation == 'knn':\n",
459
+ "\n",
460
+ " from sklearn.impute import KNNImputer\n",
461
+ " imputer = KNNImputer(n_neighbors=n_neighbors)\n",
462
+ " imputer.fit(df_fit)\n",
463
+ " df_imputed = imputer.transform(df_transform)\n",
464
+ " df_imputed = pd.DataFrame(df_imputed, columns=df_transform.columns)\n",
465
+ " print('knn imputation has been applied') \n",
466
+ " print('Number of missing values after imputation: ', df_imputed.isnull().sum().sum())\n",
467
+ " imputation_var = 'knn'\n",
468
+ " return df_imputed\n",
469
+ " \n",
470
+ " elif imputation == 'mean':\n",
471
+ "\n",
472
+ " from sklearn.impute import SimpleImputer\n",
473
+ " imputer = SimpleImputer(strategy='mean')\n",
474
+ " imputer.fit(df_fit)\n",
475
+ " df_imputed = imputer.transform(df_transform)\n",
476
+ " df_imputed = pd.DataFrame(df_imputed, columns=df_transform.columns)\n",
477
+ " print('mean imputation has been applied')\n",
478
+ " print('Number of missing values after imputation: ', df_imputed.isnull().sum().sum())\n",
479
+ " imputation_var = 'mean'\n",
480
+ " return df_imputed\n",
481
+ " \n",
482
+ " elif imputation == 'median':\n",
483
+ "\n",
484
+ " from sklearn.impute import SimpleImputer\n",
485
+ " imputer = SimpleImputer(strategy='median')\n",
486
+ " imputer.fit(df_fit)\n",
487
+ " df_imputed = imputer.transform(df_transform)\n",
488
+ " df_imputed = pd.DataFrame(df_imputed, columns=df_transform.columns)\n",
489
+ " print('median imputation has been applied')\n",
490
+ " print('Number of missing values after imputation: ', df_imputed.isnull().sum().sum())\n",
491
+ " imputation_var = 'median'\n",
492
+ " return df_imputed\n",
493
+ " \n",
494
+ " elif imputation == 'most_frequent':\n",
495
+ " \n",
496
+ " from sklearn.impute import SimpleImputer\n",
497
+ " imputer = SimpleImputer(strategy='most_frequent')\n",
498
+ " imputer.fit(df_fit)\n",
499
+ " df_imputed = imputer.transform(df_transform)\n",
500
+ " df_imputed = pd.DataFrame(df_imputed, columns=df_transform.columns)\n",
501
+ " print('most frequent imputation has been applied')\n",
502
+ " print('Number of missing values after imputation: ', df_imputed.isnull().sum().sum())\n",
503
+ " imputation_var = 'most_frequent'\n",
504
+ " return df_imputed\n",
505
+ " \n",
506
+ " else:\n",
507
+ " print('Please choose an imputation model from the following: knn, mean, median, most_frequent')\n",
508
+ " df_imputed = df_transform.copy()\n",
509
+ " return df_imputed\n"
510
+ ]
511
+ },
512
+ {
513
+ "attachments": {},
514
+ "cell_type": "markdown",
515
+ "metadata": {
516
+ "slideshow": {
517
+ "slide_type": "skip"
518
+ }
519
+ },
520
+ "source": [
521
+ "#### **Feature Reduction / Selection**"
522
+ ]
523
+ },
524
+ {
525
+ "cell_type": "code",
526
+ "execution_count": 93,
527
+ "metadata": {},
528
+ "outputs": [],
529
+ "source": [
530
+ "def feature_selection(method, X_train, y_train):\n",
531
+ "\n",
532
+ " global feature_selection_var\n",
533
+ " global selected_features\n",
534
+ "\n",
535
+ " print('------------------------------------------')\n",
536
+ " print('FEATURE SELECTION')\n",
537
+ "\n",
538
+ " # if method is boruta, run boruta feature selection and return the selected features and the training set with only the selected features\n",
539
+ "\n",
540
+ " if method == 'boruta':\n",
541
+ " print('Selected method is: ', method)\n",
542
+ " from boruta import BorutaPy\n",
543
+ " from sklearn.ensemble import RandomForestClassifier\n",
544
+ " rf = RandomForestClassifier(n_estimators=100, n_jobs=-1)\n",
545
+ " boruta_selector = BorutaPy(rf,n_estimators='auto', verbose=0, random_state=42)\n",
546
+ " boruta_selector.fit(X_train.values, y_train.values.ravel())\n",
547
+ " selected_feature_indices = boruta_selector.support_\n",
548
+ " selected_columns = X_train.columns[selected_feature_indices]\n",
549
+ " X_train_filtered = X_train.iloc[:, selected_feature_indices]\n",
550
+ " print('Shape of the training set after feature selection with Boruta: ', X_train_filtered.shape)\n",
551
+ " return X_train_filtered, selected_columns\n",
552
+ " \n",
553
+ " if method == 'none':\n",
554
+ " print('Selected method is: ', method)\n",
555
+ " X_train_filtered = X_train\n",
556
+ " print('Shape of the training set after no feature selection: ', X_train_filtered.shape)\n",
557
+ " feature_selection_var = 'none'\n",
558
+ " selected_features = X_train_filtered.columns\n",
559
+ " return X_train_filtered, selected_features \n",
560
+ " \n",
561
+ " if method == 'lasso':\n",
562
+ " print('Selected method is: ', method)\n",
563
+ " from sklearn.linear_model import LassoCV\n",
564
+ " from sklearn.feature_selection import SelectFromModel\n",
565
+ " lasso = LassoCV().fit(X_train, y_train)\n",
566
+ " model = SelectFromModel(lasso, prefit=True)\n",
567
+ " X_train_filtered = model.transform(X_train)\n",
568
+ " selected_features = X_train.columns[model.get_support()]\n",
569
+ " print('Shape of the training set after feature selection with LassoCV: ', X_train_filtered.shape)\n",
570
+ " feature_selection_var = 'lasso'\n",
571
+ " return X_train_filtered, selected_features\n",
572
+ " \n",
573
+ " if method == 'pca':\n",
574
+ " print('Selected method is: ', method)\n",
575
+ " from sklearn.decomposition import PCA\n",
576
+ " pca = PCA(n_components=15)\n",
577
+ " X_train_pca = pca.fit_transform(X_train)\n",
578
+ " selected_features = X_train.columns[pca.explained_variance_ratio_.argsort()[::-1]][:15]\n",
579
+ " print('Shape of the training set after feature selection with PCA: ', X_train_pca.shape)\n",
580
+ " feature_selection_var = 'pca'\n",
581
+ " return X_train_pca, selected_features\n",
582
+ " \n",
583
+ " if method == 'rfe':\n",
584
+ " print('Selected method is: ', method)\n",
585
+ " from sklearn.feature_selection import RFE\n",
586
+ " from sklearn.ensemble import RandomForestClassifier\n",
587
+ " rfe_selector = RFE(estimator=RandomForestClassifier(n_estimators=100, n_jobs=-1), n_features_to_select=15, step=10, verbose=0)\n",
588
+ " rfe_selector.fit(X_train, y_train)\n",
589
+ " selected_features = X_train.columns[rfe_selector.support_]\n",
590
+ " X_train_filtered = X_train.iloc[:, rfe_selector.support_]\n",
591
+ " print('Shape of the training set after feature selection with RFE: ', X_train_filtered.shape)\n",
592
+ " feature_selection_var = 'rfe'\n",
593
+ " return X_train_filtered, selected_features\n",
594
+ " "
595
+ ]
596
+ },
597
+ {
598
+ "attachments": {},
599
+ "cell_type": "markdown",
600
+ "metadata": {
601
+ "slideshow": {
602
+ "slide_type": "skip"
603
+ }
604
+ },
605
+ "source": [
606
+ "#### **Imbalance Treatment**"
607
+ ]
608
+ },
609
+ {
610
+ "cell_type": "code",
611
+ "execution_count": 94,
612
+ "metadata": {},
613
+ "outputs": [],
614
+ "source": [
615
+ "#define a function to oversample and understamble the imbalance in the training set\n",
616
+ "\n",
617
+ "def imbalance_treatment(method, X_train, y_train):\n",
618
+ "\n",
619
+ " global imbalance_var\n",
620
+ "\n",
621
+ " print('------------------------------------------')\n",
622
+ " print('IMBALANCE TREATMENT')\n",
623
+ "\n",
624
+ " if method == 'smote': \n",
625
+ " from imblearn.over_sampling import SMOTE\n",
626
+ " sm = SMOTE(random_state=42)\n",
627
+ " X_train_res, y_train_res = sm.fit_resample(X_train, y_train)\n",
628
+ " print('Shape of the training set after oversampling with SMOTE: ', X_train_res.shape)\n",
629
+ " print('Value counts of the target variable after oversampling with SMOTE: \\n', y_train_res.value_counts())\n",
630
+ " imbalance_var = 'smote'\n",
631
+ " return X_train_res, y_train_res\n",
632
+ " \n",
633
+ " if method == 'undersampling':\n",
634
+ " from imblearn.under_sampling import RandomUnderSampler\n",
635
+ " rus = RandomUnderSampler(random_state=42)\n",
636
+ " X_train_res, y_train_res = rus.fit_resample(X_train, y_train)\n",
637
+ " print('Shape of the training set after undersampling with RandomUnderSampler: ', X_train_res.shape)\n",
638
+ " print('Value counts of the target variable after undersampling with RandomUnderSampler: \\n', y_train_res.value_counts())\n",
639
+ " imbalance_var = 'undersampling'\n",
640
+ " return X_train_res, y_train_res\n",
641
+ " \n",
642
+ " if method == 'rose':\n",
643
+ " from imblearn.over_sampling import RandomOverSampler\n",
644
+ " ros = RandomOverSampler(random_state=42)\n",
645
+ " X_train_res, y_train_res = ros.fit_resample(X_train, y_train)\n",
646
+ " print('Shape of the training set after oversampling with RandomOverSampler: ', X_train_res.shape)\n",
647
+ " print('Value counts of the target variable after oversampling with RandomOverSampler: \\n', y_train_res.value_counts())\n",
648
+ " imbalance_var = 'rose'\n",
649
+ " return X_train_res, y_train_res\n",
650
+ " \n",
651
+ " \n",
652
+ " if method == 'none':\n",
653
+ " X_train_res = X_train\n",
654
+ " y_train_res = y_train\n",
655
+ " print('Shape of the training set after no resampling: ', X_train_res.shape)\n",
656
+ " print('Value counts of the target variable after no resampling: \\n', y_train_res.value_counts())\n",
657
+ " imbalance_var = 'none'\n",
658
+ " return X_train_res, y_train_res\n",
659
+ " \n",
660
+ " else:\n",
661
+ " print('Please choose a valid resampling method: smote, rose, undersampling or none')\n",
662
+ " X_train_res = X_train\n",
663
+ " y_train_res = y_train\n",
664
+ " return X_train_res, y_train_res"
665
+ ]
666
+ },
667
+ {
668
+ "attachments": {},
669
+ "cell_type": "markdown",
670
+ "metadata": {
671
+ "slideshow": {
672
+ "slide_type": "skip"
673
+ }
674
+ },
675
+ "source": [
676
+ "#### **Training Models**"
677
+ ]
678
+ },
679
+ {
680
+ "cell_type": "code",
681
+ "execution_count": 95,
682
+ "metadata": {},
683
+ "outputs": [],
684
+ "source": [
685
+ "# define a function where you can choose the model you want to use to train the data\n",
686
+ "\n",
687
+ "def train_model(model, X_train, y_train, X_test, y_test):\n",
688
+ "\n",
689
+ " global model_var\n",
690
+ "\n",
691
+ " if model == 'random_forest':\n",
692
+ " from sklearn.ensemble import RandomForestClassifier\n",
693
+ " rfc = RandomForestClassifier(n_estimators=100, random_state=13)\n",
694
+ " rfc.fit(X_train, y_train)\n",
695
+ " y_pred = rfc.predict(X_test)\n",
696
+ " model_var = 'random_forest'\n",
697
+ " return y_pred\n",
698
+ "\n",
699
+ " if model == 'logistic_regression':\n",
700
+ " from sklearn.linear_model import LogisticRegression\n",
701
+ " lr = LogisticRegression()\n",
702
+ " lr.fit(X_train, y_train)\n",
703
+ " y_pred = lr.predict(X_test)\n",
704
+ " model_var = 'logistic_regression'\n",
705
+ " return y_pred\n",
706
+ " \n",
707
+ " if model == 'knn':\n",
708
+ " from sklearn.neighbors import KNeighborsClassifier\n",
709
+ " knn = KNeighborsClassifier(n_neighbors=5)\n",
710
+ " knn.fit(X_train, y_train)\n",
711
+ " y_pred = knn.predict(X_test)\n",
712
+ " model_var = 'knn'\n",
713
+ " return y_pred\n",
714
+ " \n",
715
+ " if model == 'svm':\n",
716
+ " from sklearn.svm import SVC\n",
717
+ " svm = SVC()\n",
718
+ " svm.fit(X_train, y_train)\n",
719
+ " y_pred = svm.predict(X_test)\n",
720
+ " model_var = 'svm'\n",
721
+ " return y_pred\n",
722
+ " \n",
723
+ " if model == 'naive_bayes':\n",
724
+ " from sklearn.naive_bayes import GaussianNB\n",
725
+ " nb = GaussianNB()\n",
726
+ " nb.fit(X_train, y_train)\n",
727
+ " y_pred = nb.predict(X_test)\n",
728
+ " model_var = 'naive_bayes'\n",
729
+ " return y_pred\n",
730
+ " \n",
731
+ " if model == 'decision_tree':\n",
732
+ " from sklearn.tree import DecisionTreeClassifier\n",
733
+ " dt = DecisionTreeClassifier()\n",
734
+ " dt.fit(X_train, y_train)\n",
735
+ " y_pred = dt.predict(X_test)\n",
736
+ " model_var = 'decision_tree'\n",
737
+ " return y_pred\n",
738
+ " \n",
739
+ " if model == 'xgboost':\n",
740
+ " from xgboost import XGBClassifier\n",
741
+ " xgb = XGBClassifier()\n",
742
+ " xgb.fit(X_train, y_train)\n",
743
+ " y_pred = xgb.predict(X_test)\n",
744
+ " model_var = 'xgboost'\n",
745
+ " return y_pred\n",
746
+ " \n",
747
+ " else:\n",
748
+ " print('Please choose a model from the following: random_forest, logistic_regression, knn, svm, naive_bayes, decision_tree, xgboost')\n",
749
+ " return None"
750
+ ]
751
+ },
752
+ {
753
+ "cell_type": "code",
754
+ "execution_count": 96,
755
+ "metadata": {},
756
+ "outputs": [],
757
+ "source": [
758
+ "evaluation_score_df = pd.DataFrame(columns=['Model', 'Accuracy', 'Precision', 'Recall', 'F1-score', 'model_variables'])\n",
759
+ "evaluation_count_df = pd.DataFrame(columns=['Model', 'True Negatives', 'False Positives', 'False Negatives', 'True Positives', 'model_variables'])"
760
+ ]
761
+ },
762
+ {
763
+ "attachments": {},
764
+ "cell_type": "markdown",
765
+ "metadata": {
766
+ "slideshow": {
767
+ "slide_type": "skip"
768
+ }
769
+ },
770
+ "source": [
771
+ "#### **Evaluation Function**"
772
+ ]
773
+ },
774
+ {
775
+ "cell_type": "code",
776
+ "execution_count": 101,
777
+ "metadata": {},
778
+ "outputs": [],
779
+ "source": [
780
+ "#define a function that prints the strings below\n",
781
+ "def evaluate_models(model='random_forest'):\n",
782
+ " \n",
783
+ " print('--------------------------------------------------')\n",
784
+ "\n",
785
+ " all_models = ['random_forest', 'logistic_regression', 'knn', 'svm', 'naive_bayes', 'decision_tree', 'xgboost']\n",
786
+ " evaluation_score_append = []\n",
787
+ " evaluation_count_append = []\n",
788
+ " \n",
789
+ " for selected_model in all_models:\n",
790
+ " \n",
791
+ " if model == 'all' or model == selected_model:\n",
792
+ "\n",
793
+ " evaluation_score = []\n",
794
+ " evaluation_count = []\n",
795
+ "\n",
796
+ " y_pred = globals()['y_pred_' + selected_model] # Get the prediction variable dynamically\n",
797
+ "\n",
798
+ " def namestr(obj, namespace):\n",
799
+ " return [name for name in namespace if namespace[name] is obj]\n",
800
+ "\n",
801
+ " model_name = namestr(y_pred, globals())[0]\n",
802
+ " model_name = model_name.replace('y_pred_', '') \n",
803
+ "\n",
804
+ " cm = confusion_matrix(y_test, y_pred)\n",
805
+ "\n",
806
+ " # create a dataframe with the results for each model\n",
807
+ "\n",
808
+ " evaluation_score.append(model_name)\n",
809
+ " evaluation_score.append(round(accuracy_score(y_test, y_pred), 2))\n",
810
+ " evaluation_score.append(round(precision_score(y_test, y_pred, zero_division=0), 2))\n",
811
+ " evaluation_score.append(round(recall_score(y_test, y_pred), 2))\n",
812
+ " evaluation_score.append(round(f1_score(y_test, y_pred), 2))\n",
813
+ " evaluation_score_append.append(evaluation_score)\n",
814
+ "\n",
815
+ "\n",
816
+ " # create a dataframe with the true positives, true negatives, false positives and false negatives for each model\n",
817
+ "\n",
818
+ " evaluation_count.append(model_name)\n",
819
+ " evaluation_count.append(cm[0][0])\n",
820
+ " evaluation_count.append(cm[0][1])\n",
821
+ " evaluation_count.append(cm[1][0])\n",
822
+ " evaluation_count.append(cm[1][1])\n",
823
+ " evaluation_count_append.append(evaluation_count)\n",
824
+ "\n",
825
+ " \n",
826
+ " evaluation_score_append = pd.DataFrame(evaluation_score_append, \n",
827
+ " columns=['Model', 'Accuracy', 'Precision', 'Recall', 'F1-score'])\n",
828
+ " \n",
829
+ " evaluation_score_append['drop duplicates'] = drop_duplicates_var\n",
830
+ " evaluation_score_append['missing values th'] = missing_values_threshold_var\n",
831
+ " evaluation_score_append['variance th'] = variance_threshold_var\n",
832
+ " evaluation_score_append['correlation th'] = correlation_threshold_var\n",
833
+ " evaluation_score_append['outlier removal th'] = outlier_var\n",
834
+ " evaluation_score_append['scaling method'] = scale_model_var\n",
835
+ " evaluation_score_append['imputation method'] = imputation_var\n",
836
+ " evaluation_score_append['feature selection'] = feature_selection_var\n",
837
+ " evaluation_score_append['imbalance treatment'] = imbalance_var\n",
838
+ "\n",
839
+ "\n",
840
+ " evaluation_score_append['model_variables'] = drop_duplicates_var + '_' + str(missing_values_threshold_var) + '_' + str(\n",
841
+ " variance_threshold_var) + '_' + str(correlation_threshold_var) + '_' + str(\n",
842
+ " outlier_var) + '_' + scale_model_var + '_' + imputation_var + '_' + feature_selection_var + '_' + imbalance_var\n",
843
+ " \n",
844
+ "\n",
845
+ " evaluation_count_append = pd.DataFrame(evaluation_count_append,\n",
846
+ " columns=['Model', 'True Negatives', 'False Positives', 'False Negatives', 'True Positives'])\n",
847
+ " \n",
848
+ " evaluation_count_append['drop duplicates'] = drop_duplicates_var\n",
849
+ " evaluation_count_append['missing values th'] = missing_values_threshold_var\n",
850
+ " evaluation_count_append['variance th'] = variance_threshold_var\n",
851
+ " evaluation_count_append['correlation th'] = correlation_threshold_var\n",
852
+ " evaluation_count_append['outlier removal th'] = outlier_var\n",
853
+ " evaluation_count_append['scaling method'] = scale_model_var\n",
854
+ " evaluation_count_append['imputation method'] = imputation_var\n",
855
+ " evaluation_count_append['feature selection'] = feature_selection_var\n",
856
+ " evaluation_count_append['imbalance treatment'] = imbalance_var\n",
857
+ " \n",
858
+ " evaluation_count_append['model_variables'] = drop_duplicates_var + '_' + str(missing_values_threshold_var) + '_' + str(\n",
859
+ " variance_threshold_var) + '_' + str(correlation_threshold_var) + '_' + str(\n",
860
+ " outlier_var) + '_' + scale_model_var + '_' + imputation_var + '_' + feature_selection_var + '_' + imbalance_var\n",
861
+ " \n",
862
+ " return evaluation_score_append, evaluation_count_append"
863
+ ]
864
+ },
865
+ {
866
+ "attachments": {},
867
+ "cell_type": "markdown",
868
+ "metadata": {
869
+ "slideshow": {
870
+ "slide_type": "skip"
871
+ }
872
+ },
873
+ "source": [
874
+ "### **Input Variables**"
875
+ ]
876
+ },
877
+ {
878
+ "cell_type": "code",
879
+ "execution_count": 103,
880
+ "metadata": {},
881
+ "outputs": [
882
+ {
883
+ "data": {
884
+ "application/mercury+json": {
885
+ "code_uid": "Text.0.40.15.8-rand3ea159f1",
886
+ "disabled": false,
887
+ "hidden": false,
888
+ "label": "Missing Value Threeshold",
889
+ "model_id": "1f155017a0e64a71ba2f1a737d93c61d",
890
+ "rows": 1,
891
+ "url_key": "",
892
+ "value": "50",
893
+ "widget": "Text"
894
+ },
895
+ "application/vnd.jupyter.widget-view+json": {
896
+ "model_id": "1f155017a0e64a71ba2f1a737d93c61d",
897
+ "version_major": 2,
898
+ "version_minor": 0
899
+ },
900
+ "text/plain": [
901
+ "mercury.Text"
902
+ ]
903
+ },
904
+ "metadata": {},
905
+ "output_type": "display_data"
906
+ },
907
+ {
908
+ "data": {
909
+ "application/mercury+json": {
910
+ "code_uid": "Text.0.40.15.11-rand7772c265",
911
+ "disabled": false,
912
+ "hidden": false,
913
+ "label": "Variance Threshold",
914
+ "model_id": "6ae03558245f4658abc409261e88e273",
915
+ "rows": 1,
916
+ "url_key": "",
917
+ "value": "0.05",
918
+ "widget": "Text"
919
+ },
920
+ "application/vnd.jupyter.widget-view+json": {
921
+ "model_id": "6ae03558245f4658abc409261e88e273",
922
+ "version_major": 2,
923
+ "version_minor": 0
924
+ },
925
+ "text/plain": [
926
+ "mercury.Text"
927
+ ]
928
+ },
929
+ "metadata": {},
930
+ "output_type": "display_data"
931
+ },
932
+ {
933
+ "data": {
934
+ "application/mercury+json": {
935
+ "code_uid": "Text.0.40.15.14-rand52a68a07",
936
+ "disabled": false,
937
+ "hidden": false,
938
+ "label": "Correlation Threshold",
939
+ "model_id": "325fdc5cafb046c89be6440a2a0e855c",
940
+ "rows": 1,
941
+ "url_key": "",
942
+ "value": "0.95",
943
+ "widget": "Text"
944
+ },
945
+ "application/vnd.jupyter.widget-view+json": {
946
+ "model_id": "325fdc5cafb046c89be6440a2a0e855c",
947
+ "version_major": 2,
948
+ "version_minor": 0
949
+ },
950
+ "text/plain": [
951
+ "mercury.Text"
952
+ ]
953
+ },
954
+ "metadata": {},
955
+ "output_type": "display_data"
956
+ },
957
+ {
958
+ "data": {
959
+ "application/mercury+json": {
960
+ "choices": [
961
+ "none",
962
+ 3,
963
+ 4,
964
+ 5
965
+ ],
966
+ "code_uid": "Select.0.40.16.18-randd219fc2a",
967
+ "disabled": false,
968
+ "hidden": false,
969
+ "label": "Outlier Removal Threshold",
970
+ "model_id": "96591acea02b43f9a366ddfdfff1dfb5",
971
+ "url_key": "",
972
+ "value": 5,
973
+ "widget": "Select"
974
+ },
975
+ "application/vnd.jupyter.widget-view+json": {
976
+ "model_id": "96591acea02b43f9a366ddfdfff1dfb5",
977
+ "version_major": 2,
978
+ "version_minor": 0
979
+ },
980
+ "text/plain": [
981
+ "mercury.Select"
982
+ ]
983
+ },
984
+ "metadata": {},
985
+ "output_type": "display_data"
986
+ },
987
+ {
988
+ "data": {
989
+ "application/mercury+json": {
990
+ "choices": [
991
+ "none",
992
+ "standard",
993
+ "minmax",
994
+ "robust"
995
+ ],
996
+ "code_uid": "Select.0.40.16.25-rand7528f0a1",
997
+ "disabled": false,
998
+ "hidden": false,
999
+ "label": "Scaling Variables",
1000
+ "model_id": "8fc6da55b85c4993bf420c86d2a23a2d",
1001
+ "url_key": "",
1002
+ "value": "standard",
1003
+ "widget": "Select"
1004
+ },
1005
+ "application/vnd.jupyter.widget-view+json": {
1006
+ "model_id": "8fc6da55b85c4993bf420c86d2a23a2d",
1007
+ "version_major": 2,
1008
+ "version_minor": 0
1009
+ },
1010
+ "text/plain": [
1011
+ "mercury.Select"
1012
+ ]
1013
+ },
1014
+ "metadata": {},
1015
+ "output_type": "display_data"
1016
+ },
1017
+ {
1018
+ "data": {
1019
+ "application/mercury+json": {
1020
+ "choices": [
1021
+ "mean",
1022
+ "median",
1023
+ "knn",
1024
+ "most_frequent"
1025
+ ],
1026
+ "code_uid": "Select.0.40.16.29-randb1225c9d",
1027
+ "disabled": false,
1028
+ "hidden": false,
1029
+ "label": "Imputation Methods",
1030
+ "model_id": "193450229f4543079d7a53267d8c1fe1",
1031
+ "url_key": "",
1032
+ "value": "median",
1033
+ "widget": "Select"
1034
+ },
1035
+ "application/vnd.jupyter.widget-view+json": {
1036
+ "model_id": "193450229f4543079d7a53267d8c1fe1",
1037
+ "version_major": 2,
1038
+ "version_minor": 0
1039
+ },
1040
+ "text/plain": [
1041
+ "mercury.Select"
1042
+ ]
1043
+ },
1044
+ "metadata": {},
1045
+ "output_type": "display_data"
1046
+ },
1047
+ {
1048
+ "data": {
1049
+ "application/mercury+json": {
1050
+ "choices": [
1051
+ "none",
1052
+ "lasso",
1053
+ "rfe",
1054
+ "pca",
1055
+ "boruta"
1056
+ ],
1057
+ "code_uid": "Select.0.40.16.34-rand9ae51452",
1058
+ "disabled": false,
1059
+ "hidden": false,
1060
+ "label": "Feature Selection",
1061
+ "model_id": "e556e5025dc14e9e867125680d35025f",
1062
+ "url_key": "",
1063
+ "value": "lasso",
1064
+ "widget": "Select"
1065
+ },
1066
+ "application/vnd.jupyter.widget-view+json": {
1067
+ "model_id": "e556e5025dc14e9e867125680d35025f",
1068
+ "version_major": 2,
1069
+ "version_minor": 0
1070
+ },
1071
+ "text/plain": [
1072
+ "mercury.Select"
1073
+ ]
1074
+ },
1075
+ "metadata": {},
1076
+ "output_type": "display_data"
1077
+ },
1078
+ {
1079
+ "data": {
1080
+ "application/mercury+json": {
1081
+ "choices": [
1082
+ "none",
1083
+ "smote",
1084
+ "undersampling",
1085
+ "rose"
1086
+ ],
1087
+ "code_uid": "Select.0.40.16.38-rand84f919f9",
1088
+ "disabled": false,
1089
+ "hidden": false,
1090
+ "label": "Imbalance Treatment",
1091
+ "model_id": "29560b71dbf84b45a2a487c92c077ad4",
1092
+ "url_key": "",
1093
+ "value": "smote",
1094
+ "widget": "Select"
1095
+ },
1096
+ "application/vnd.jupyter.widget-view+json": {
1097
+ "model_id": "29560b71dbf84b45a2a487c92c077ad4",
1098
+ "version_major": 2,
1099
+ "version_minor": 0
1100
+ },
1101
+ "text/plain": [
1102
+ "mercury.Select"
1103
+ ]
1104
+ },
1105
+ "metadata": {},
1106
+ "output_type": "display_data"
1107
+ },
1108
+ {
1109
+ "data": {
1110
+ "application/mercury+json": {
1111
+ "choices": [
1112
+ "random_forest",
1113
+ "logistic_regression",
1114
+ "knn",
1115
+ "svm",
1116
+ "naive_bayes",
1117
+ "decision_tree",
1118
+ "xgboost"
1119
+ ],
1120
+ "code_uid": "Select.0.40.16.42-rand98b2dc54",
1121
+ "disabled": false,
1122
+ "hidden": false,
1123
+ "label": "Model Selection",
1124
+ "model_id": "d90f6d906955444e9abf735d40442d91",
1125
+ "url_key": "",
1126
+ "value": "random_forest",
1127
+ "widget": "Select"
1128
+ },
1129
+ "application/vnd.jupyter.widget-view+json": {
1130
+ "model_id": "d90f6d906955444e9abf735d40442d91",
1131
+ "version_major": 2,
1132
+ "version_minor": 0
1133
+ },
1134
+ "text/plain": [
1135
+ "mercury.Select"
1136
+ ]
1137
+ },
1138
+ "metadata": {},
1139
+ "output_type": "display_data"
1140
+ },
1141
+ {
1142
+ "name": "stdout",
1143
+ "output_type": "stream",
1144
+ "text": [
1145
+ "------------------------------------------\n",
1146
+ "FEATURE REMOVAL\n",
1147
+ "Shape of the dataframe is: (1175, 590)\n",
1148
+ "the number of columns dropped due to duplications is: 104\n",
1149
+ "the number of columns dropped due to missing values is: 28\n",
1150
+ "the number of columns dropped due to low variance is: 189\n",
1151
+ "the number of columns dropped due to high correlation is: 90\n",
1152
+ "Total number of columns to be dropped is: 411\n",
1153
+ "New shape of the dataframe is: (1175, 179)\n",
1154
+ "<class 'list'>\n",
1155
+ "------------------------------------------\n",
1156
+ "OUTLIER REMOVAL\n",
1157
+ "The z-score threshold is: 5\n",
1158
+ "The number of outliers removed from the dataset is: 163\n",
1159
+ "<class 'pandas.core.frame.DataFrame'>\n",
1160
+ "------------------------------------------\n",
1161
+ "SCALING THE DATAFRAME\n",
1162
+ "The dataframe has been scaled using the standard scaling model\n",
1163
+ "------------------------------------------\n",
1164
+ "SCALING THE DATAFRAME\n",
1165
+ "The dataframe has been scaled using the standard scaling model\n",
1166
+ "------------------------------------------\n",
1167
+ "IMPUTATION PROCESS\n",
1168
+ "Number of missing values before imputation: 3380\n",
1169
+ "median imputation has been applied\n",
1170
+ "Number of missing values after imputation: 0\n",
1171
+ "------------------------------------------\n",
1172
+ "IMPUTATION PROCESS\n",
1173
+ "Number of missing values before imputation: 1196\n",
1174
+ "median imputation has been applied\n",
1175
+ "Number of missing values after imputation: 0\n",
1176
+ "------------------------------------------\n",
1177
+ "FEATURE SELECTION\n",
1178
+ "Selected method is: lasso\n",
1179
+ "Shape of the training set after feature selection with LassoCV: (1175, 14)\n",
1180
+ "------------------------------------------\n",
1181
+ "IMBALANCE TREATMENT\n",
1182
+ "Shape of the training set after oversampling with SMOTE: (2194, 14)\n",
1183
+ "Value counts of the target variable after oversampling with SMOTE: \n",
1184
+ " pass/fail\n",
1185
+ "0 1097\n",
1186
+ "1 1097\n",
1187
+ "dtype: int64\n"
1188
+ ]
1189
+ }
1190
+ ],
1191
+ "source": [
1192
+ "# input train and test sets\n",
1193
+ "input_train_set = X_train\n",
1194
+ "input_test_set = X_test\n",
1195
+ "\n",
1196
+ "# Start widget section\n",
1197
+ "\n",
1198
+ "input_drop_duplicates = 'yes'\n",
1199
+ "input_missing_values_threshold = mr.Text(label=\"Missing Value Threeshold\", value='50')\n",
1200
+ "input_missing_values_threshold = int(input_missing_values_threshold.value)\n",
1201
+ "\n",
1202
+ "input_variance_threshold = mr.Text(label=\"Variance Threshold\", value='0.05') # \n",
1203
+ "input_variance_threshold = float(input_variance_threshold.value)\n",
1204
+ "\n",
1205
+ "input_correlation_threshold = mr.Text(label=\"Correlation Threshold\", value='0.95') # \n",
1206
+ "input_correlation_threshold = float(input_correlation_threshold.value)\n",
1207
+ "\n",
1208
+ "# input outlier removal variables\n",
1209
+ "input_outlier_removal_threshold = mr.Select(label=\"Outlier Removal Threshold\", value=5, choices=['none', 3, 4, 5]) # 'none' or zscore from 0 to 100\n",
1210
+ "if input_outlier_removal_threshold.value != 'none':\n",
1211
+ " input_outlier_removal_threshold = int(input_outlier_removal_threshold.value)\n",
1212
+ "elif input_outlier_removal_threshold.value == 'none':\n",
1213
+ " input_outlier_removal_threshold = str(input_outlier_removal_threshold.value)\n",
1214
+ "\n",
1215
+ "# input scaling variables\n",
1216
+ "input_scale_model = mr.Select(label=\"Scaling Variables\", value=\"standard\", choices=['none', 'standard', 'minmax', 'robust']) # 'none', 'normal', 'standard', 'minmax', 'robust'\n",
1217
+ "input_scale_model = str(input_scale_model.value)\n",
1218
+ "\n",
1219
+ "# input imputation variables\n",
1220
+ "input_imputation_method = mr.Select(label=\"Imputation Methods\", value=\"median\", choices=['mean', 'median', 'knn', 'most_frequent']) # 'mean', 'median', 'knn', 'most_frequent'\n",
1221
+ "input_n_neighbors = 5 # only for knn imputation\n",
1222
+ "input_imputation_method = str(input_imputation_method.value)\n",
1223
+ "\n",
1224
+ "# import feature selection variables\n",
1225
+ "input_feature_selection = mr.Select(label=\"Feature Selection\", value=\"lasso\", choices=['none', 'lasso', 'rfe', 'pca', 'boruta']) # 'none', 'lasso', 'rfe', 'pca', 'boruta'\n",
1226
+ "input_feature_selection = str(input_feature_selection.value)\n",
1227
+ "\n",
1228
+ "# input imbalance treatment variables\n",
1229
+ "input_imbalance_treatment = mr.Select(label=\"Imbalance Treatment\", value=\"smote\", choices=['none', 'smote', 'undersampling', 'rose']) # 'none', 'smote', 'undersampling', 'rose'\n",
1230
+ "input_imbalance_treatment = str(input_imbalance_treatment.value)\n",
1231
+ "\n",
1232
+ "# input model\n",
1233
+ "input_model = mr.Select(label=\"Model Selection\", value=\"random_forest\", choices=['random_forest', 'logistic_regression', 'knn', 'svm', 'naive_bayes','decision_tree','xgboost'])\n",
1234
+ "input_model = str(input_model.value)\n",
1235
+ "\n",
1236
+ "# remove features using the function list_columns_to_drop\n",
1237
+ "\n",
1238
+ "dropped = columns_to_drop(input_train_set, input_drop_duplicates, input_missing_values_threshold, input_variance_threshold, input_correlation_threshold)\n",
1239
+ "\n",
1240
+ "# drop the columns from the training and testing sets and save the new sets as new variables\n",
1241
+ "\n",
1242
+ "X_train2 = input_train_set.drop(dropped, axis=1)\n",
1243
+ "X_test2 = input_test_set.drop(dropped, axis=1)\n",
1244
+ "\n",
1245
+ "\n",
1246
+ "# remove outliers from train dataset\n",
1247
+ "\n",
1248
+ "X_train_dropped_outliers = outlier_removal(X_train2, input_outlier_removal_threshold)\n",
1249
+ "\n",
1250
+ "# scale the training and testing sets\n",
1251
+ "\n",
1252
+ "X_train_scaled = scale_dataframe(input_scale_model, X_train_dropped_outliers, X_train_dropped_outliers)\n",
1253
+ "X_test_scaled = scale_dataframe(input_scale_model, X_train_dropped_outliers, X_test2)\n",
1254
+ "\n",
1255
+ "# impute the missing values in the training and testing sets using the function impute_missing_values\n",
1256
+ "\n",
1257
+ "X_train_imputed = impute_missing_values(input_imputation_method,X_train_scaled, X_train_scaled, input_n_neighbors)\n",
1258
+ "X_test_imputed = impute_missing_values(input_imputation_method,X_train_scaled, X_test_scaled, input_n_neighbors)\n",
1259
+ "\n",
1260
+ "# select features\n",
1261
+ "\n",
1262
+ "X_train_selected, selected_features = feature_selection(input_feature_selection, X_train_imputed, y_train)\n",
1263
+ "\n",
1264
+ "X_train_selected = pd.DataFrame(X_train_selected, columns=selected_features)\n",
1265
+ "X_test_selected = X_test_imputed[selected_features]\n",
1266
+ "\n",
1267
+ "# treat imbalance in the training set using the function oversample\n",
1268
+ "\n",
1269
+ "X_train_res, y_train_res = imbalance_treatment(input_imbalance_treatment, X_train_selected, y_train)\n",
1270
+ "\n",
1271
+ "# train the model using the function train_model and save the predictions as new variables\n",
1272
+ "\n",
1273
+ "y_pred_random_forest = train_model('random_forest', X_train_res, y_train_res, X_test_selected, y_test)\n",
1274
+ "y_pred_logistic_regression = train_model('logistic_regression', X_train_res, y_train_res, X_test_selected, y_test)\n",
1275
+ "y_pred_knn = train_model('knn', X_train_res, y_train_res, X_test_selected, y_test)\n",
1276
+ "y_pred_svm = train_model('svm', X_train_res, y_train_res, X_test_selected, y_test)\n",
1277
+ "y_pred_naive_bayes = train_model('naive_bayes', X_train_res, y_train_res, X_test_selected, y_test)\n",
1278
+ "y_pred_decision_tree = train_model('decision_tree', X_train_res, y_train_res, X_test_selected, y_test)\n",
1279
+ "y_pred_xgboost = train_model('xgboost', X_train_res, y_train_res, X_test_selected, y_test)"
1280
+ ]
1281
+ },
1282
+ {
1283
+ "cell_type": "code",
1284
+ "execution_count": 113,
1285
+ "metadata": {},
1286
+ "outputs": [
1287
+ {
1288
+ "name": "stdout",
1289
+ "output_type": "stream",
1290
+ "text": [
1291
+ "--------------------------------------------------\n"
1292
+ ]
1293
+ },
1294
+ {
1295
+ "data": {
1296
+ "text/html": [
1297
+ "<div>\n",
1298
+ "<style scoped>\n",
1299
+ " .dataframe tbody tr th:only-of-type {\n",
1300
+ " vertical-align: middle;\n",
1301
+ " }\n",
1302
+ "\n",
1303
+ " .dataframe tbody tr th {\n",
1304
+ " vertical-align: top;\n",
1305
+ " }\n",
1306
+ "\n",
1307
+ " .dataframe thead th {\n",
1308
+ " text-align: right;\n",
1309
+ " }\n",
1310
+ "</style>\n",
1311
+ "<table border=\"1\" class=\"dataframe\">\n",
1312
+ " <thead>\n",
1313
+ " <tr style=\"text-align: right;\">\n",
1314
+ " <th></th>\n",
1315
+ " <th>Model</th>\n",
1316
+ " <th>True Negatives</th>\n",
1317
+ " <th>False Positives</th>\n",
1318
+ " <th>False Negatives</th>\n",
1319
+ " <th>True Positives</th>\n",
1320
+ " <th>drop duplicates</th>\n",
1321
+ " <th>missing values th</th>\n",
1322
+ " <th>variance th</th>\n",
1323
+ " <th>correlation th</th>\n",
1324
+ " <th>outlier removal th</th>\n",
1325
+ " <th>scaling method</th>\n",
1326
+ " <th>imputation method</th>\n",
1327
+ " <th>feature selection</th>\n",
1328
+ " <th>imbalance treatment</th>\n",
1329
+ " <th>model_variables</th>\n",
1330
+ " </tr>\n",
1331
+ " </thead>\n",
1332
+ " <tbody>\n",
1333
+ " <tr>\n",
1334
+ " <th>0</th>\n",
1335
+ " <td>random_forest</td>\n",
1336
+ " <td>344</td>\n",
1337
+ " <td>22</td>\n",
1338
+ " <td>22</td>\n",
1339
+ " <td>4</td>\n",
1340
+ " <td>yes</td>\n",
1341
+ " <td>50</td>\n",
1342
+ " <td>0.05</td>\n",
1343
+ " <td>0.95</td>\n",
1344
+ " <td>5</td>\n",
1345
+ " <td>standard</td>\n",
1346
+ " <td>median</td>\n",
1347
+ " <td>lasso</td>\n",
1348
+ " <td>smote</td>\n",
1349
+ " <td>yes_50_0.05_0.95_5_standard_median_lasso_smote</td>\n",
1350
+ " </tr>\n",
1351
+ " </tbody>\n",
1352
+ "</table>\n",
1353
+ "</div>"
1354
+ ],
1355
+ "text/plain": [
1356
+ " Model True Negatives False Positives False Negatives \\\n",
1357
+ "0 random_forest 344 22 22 \n",
1358
+ "\n",
1359
+ " True Positives drop duplicates missing values th variance th \\\n",
1360
+ "0 4 yes 50 0.05 \n",
1361
+ "\n",
1362
+ " correlation th outlier removal th scaling method imputation method \\\n",
1363
+ "0 0.95 5 standard median \n",
1364
+ "\n",
1365
+ " feature selection imbalance treatment \\\n",
1366
+ "0 lasso smote \n",
1367
+ "\n",
1368
+ " model_variables \n",
1369
+ "0 yes_50_0.05_0.95_5_standard_median_lasso_smote "
1370
+ ]
1371
+ },
1372
+ "metadata": {},
1373
+ "output_type": "display_data"
1374
+ },
1375
+ {
1376
+ "data": {
1377
+ "text/html": [
1378
+ "<div>\n",
1379
+ "<style scoped>\n",
1380
+ " .dataframe tbody tr th:only-of-type {\n",
1381
+ " vertical-align: middle;\n",
1382
+ " }\n",
1383
+ "\n",
1384
+ " .dataframe tbody tr th {\n",
1385
+ " vertical-align: top;\n",
1386
+ " }\n",
1387
+ "\n",
1388
+ " .dataframe thead th {\n",
1389
+ " text-align: right;\n",
1390
+ " }\n",
1391
+ "</style>\n",
1392
+ "<table border=\"1\" class=\"dataframe\">\n",
1393
+ " <thead>\n",
1394
+ " <tr style=\"text-align: right;\">\n",
1395
+ " <th></th>\n",
1396
+ " <th>Model</th>\n",
1397
+ " <th>Accuracy</th>\n",
1398
+ " <th>Precision</th>\n",
1399
+ " <th>Recall</th>\n",
1400
+ " <th>F1-score</th>\n",
1401
+ " <th>drop duplicates</th>\n",
1402
+ " <th>missing values th</th>\n",
1403
+ " <th>variance th</th>\n",
1404
+ " <th>correlation th</th>\n",
1405
+ " <th>outlier removal th</th>\n",
1406
+ " <th>scaling method</th>\n",
1407
+ " <th>imputation method</th>\n",
1408
+ " <th>feature selection</th>\n",
1409
+ " <th>imbalance treatment</th>\n",
1410
+ " <th>model_variables</th>\n",
1411
+ " </tr>\n",
1412
+ " </thead>\n",
1413
+ " <tbody>\n",
1414
+ " <tr>\n",
1415
+ " <th>0</th>\n",
1416
+ " <td>random_forest</td>\n",
1417
+ " <td>0.89</td>\n",
1418
+ " <td>0.15</td>\n",
1419
+ " <td>0.15</td>\n",
1420
+ " <td>0.15</td>\n",
1421
+ " <td>yes</td>\n",
1422
+ " <td>50</td>\n",
1423
+ " <td>0.05</td>\n",
1424
+ " <td>0.95</td>\n",
1425
+ " <td>5</td>\n",
1426
+ " <td>standard</td>\n",
1427
+ " <td>median</td>\n",
1428
+ " <td>lasso</td>\n",
1429
+ " <td>smote</td>\n",
1430
+ " <td>yes_50_0.05_0.95_5_standard_median_lasso_smote</td>\n",
1431
+ " </tr>\n",
1432
+ " </tbody>\n",
1433
+ "</table>\n",
1434
+ "</div>"
1435
+ ],
1436
+ "text/plain": [
1437
+ " Model Accuracy Precision Recall F1-score drop duplicates \\\n",
1438
+ "0 random_forest 0.89 0.15 0.15 0.15 yes \n",
1439
+ "\n",
1440
+ " missing values th variance th correlation th outlier removal th \\\n",
1441
+ "0 50 0.05 0.95 5 \n",
1442
+ "\n",
1443
+ " scaling method imputation method feature selection imbalance treatment \\\n",
1444
+ "0 standard median lasso smote \n",
1445
+ "\n",
1446
+ " model_variables \n",
1447
+ "0 yes_50_0.05_0.95_5_standard_median_lasso_smote "
1448
+ ]
1449
+ },
1450
+ "metadata": {},
1451
+ "output_type": "display_data"
1452
+ }
1453
+ ],
1454
+ "source": [
1455
+ "evaluation_score_output, evaluation_counts_output = evaluate_models(input_model)"
1456
+ ]
1457
+ },
1458
+ {
1459
+ "attachments": {},
1460
+ "cell_type": "markdown",
1461
+ "metadata": {
1462
+ "slideshow": {
1463
+ "slide_type": "skip"
1464
+ }
1465
+ },
1466
+ "source": [
1467
+ "#### **Confusion Matrix**"
1468
+ ]
1469
+ },
1470
+ {
1471
+ "cell_type": "code",
1472
+ "execution_count": 125,
1473
+ "metadata": {},
1474
+ "outputs": [
1475
+ {
1476
+ "data": {
1477
+ "text/html": [
1478
+ "<div>\n",
1479
+ "<style scoped>\n",
1480
+ " .dataframe tbody tr th:only-of-type {\n",
1481
+ " vertical-align: middle;\n",
1482
+ " }\n",
1483
+ "\n",
1484
+ " .dataframe tbody tr th {\n",
1485
+ " vertical-align: top;\n",
1486
+ " }\n",
1487
+ "\n",
1488
+ " .dataframe thead th {\n",
1489
+ " text-align: right;\n",
1490
+ " }\n",
1491
+ "</style>\n",
1492
+ "<table border=\"1\" class=\"dataframe\">\n",
1493
+ " <thead>\n",
1494
+ " <tr style=\"text-align: right;\">\n",
1495
+ " <th></th>\n",
1496
+ " <th>Accuracy</th>\n",
1497
+ " <th>Precision</th>\n",
1498
+ " <th>Recall</th>\n",
1499
+ " <th>F1-score</th>\n",
1500
+ " </tr>\n",
1501
+ " </thead>\n",
1502
+ " <tbody>\n",
1503
+ " <tr>\n",
1504
+ " <th>0</th>\n",
1505
+ " <td>0.89</td>\n",
1506
+ " <td>0.15</td>\n",
1507
+ " <td>0.15</td>\n",
1508
+ " <td>0.15</td>\n",
1509
+ " </tr>\n",
1510
+ " </tbody>\n",
1511
+ "</table>\n",
1512
+ "</div>"
1513
+ ],
1514
+ "text/plain": [
1515
+ " Accuracy Precision Recall F1-score\n",
1516
+ "0 0.89 0.15 0.15 0.15"
1517
+ ]
1518
+ },
1519
+ "metadata": {},
1520
+ "output_type": "display_data"
1521
+ },
1522
+ {
1523
+ "data": {
1524
+ "image/png": "iVBORw0KGgoAAAANSUhEUgAAAbsAAAHACAYAAAA7jMYcAAAAOXRFWHRTb2Z0d2FyZQBNYXRwbG90bGliIHZlcnNpb24zLjYuMiwgaHR0cHM6Ly9tYXRwbG90bGliLm9yZy8o6BhiAAAACXBIWXMAAA9hAAAPYQGoP6dpAAAvz0lEQVR4nO3deXxM9/7H8fckkQVJJNQSElJKg9hLUTtBW6pcF23tLW1Ray1XVTe13ZZWr972Uqr1U6r0qrptKWrXiqWW2GpJJCElJKIRWeb3h3baaRaGSaa+eT0fj3ncO2fOnPlMHtJXzsyZORar1WoVAAAGc3P1AAAA5DdiBwAwHrEDABiP2AEAjEfsAADGI3YAAOMROwCA8YgdAMB4Hq4e4HZkZWUpLi5Ovr6+slgsrh4HAFCArFarLl++rKCgILm55b3vdkfHLi4uTsHBwa4eAwDgQjExMapQoUKe69zRsfP19ZUkeVbvK4u7p4unAQpe9MZ/unoEwGUuJyerSmiwrQV5uaNj99tLlxZ3T2KHQsnPz8/VIwAudzNvY3GACgDAeMQOAGA8YgcAMB6xAwAYj9gBAIxH7AAAxiN2AADjETsAgPGIHQDAeMQOAGA8YgcAMB6xAwAYj9gBAIxH7AAAxiN2AADjETsAg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Rs21JAhQzRs2DANGjQoz/vUqlVL3333nY4dO6ZmzZqpbt26mjRpksqVK2dbZ8GCBQoODlaLFi3UtWtX28cDcuPp6alvvvlGpUuX1oMPPqjw8HBNmzbNtofZrVs3dejQQa1atdJdd92lJUuWyGKxaM2aNWrevLkGDBigqlWrqmfPnjp16pTKlCkjSerRo4defPFFjRs3TvXr19fp06f1zDPPOPQzmjRpkurVq6f27durZcuWtig7+rNcsGCB+vTpo9GjR6tatWrq3Lmzdu7cqeDgYIfmAW6VxWr9w4dhgEKiZcuWqlOnjt1XeAEwF3t2AADjETsAgPF4GRMAYDz27AAAxiN2AADjETsAgPGIHQDAeMQOAGA8YgcAMB6xAwAYj9gBAIxH7AAAxvt/FEmUb+P53acAAAAASUVORK5CYII=",
1525
+ "text/plain": [
1526
+ "<Figure size 500x500 with 1 Axes>"
1527
+ ]
1528
+ },
1529
+ "metadata": {},
1530
+ "output_type": "display_data"
1531
+ }
1532
+ ],
1533
+ "source": [
1534
+ "# create a np.array with selected_model values\n",
1535
+ "\n",
1536
+ "conf_matrix = np.array([[evaluation_counts_output['True Negatives'].values[0], evaluation_counts_output['False Positives'].values[0]],\n",
1537
+ " [evaluation_counts_output['False Negatives'].values[0], evaluation_counts_output['True Positives'].values[0]]])\n",
1538
+ "\n",
1539
+ "fig, ax = plot_confusion_matrix(\n",
1540
+ " conf_mat=conf_matrix,\n",
1541
+ " show_absolute=True,\n",
1542
+ " show_normed=True\n",
1543
+ ")\n",
1544
+ "\n",
1545
+ "display(evaluation_score_output[['Accuracy', 'Precision', 'Recall', 'F1-score']])"
1546
+ ]
1547
+ }
1548
+ ],
1549
+ "metadata": {
1550
+ "kernelspec": {
1551
+ "display_name": "base",
1552
+ "language": "python",
1553
+ "name": "python3"
1554
+ },
1555
+ "language_info": {
1556
+ "codemirror_mode": {
1557
+ "name": "ipython",
1558
+ "version": 3
1559
+ },
1560
+ "file_extension": ".py",
1561
+ "mimetype": "text/x-python",
1562
+ "name": "python",
1563
+ "nbconvert_exporter": "python",
1564
+ "pygments_lexer": "ipython3",
1565
+ "version": "3.9.16"
1566
+ },
1567
+ "orig_nbformat": 4
1568
+ },
1569
+ "nbformat": 4,
1570
+ "nbformat_minor": 2
1571
+ }