erjonb commited on
Commit
6bc3be8
·
1 Parent(s): 3437657

Upload P2 - Secom Notebook - Mercury.ipynb

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