|
a |
|
b/others/Under_sampling .ipynb |
|
|
1 |
{ |
|
|
2 |
"cells": [ |
|
|
3 |
{ |
|
|
4 |
"cell_type": "markdown", |
|
|
5 |
"id": "8468ad0d", |
|
|
6 |
"metadata": {}, |
|
|
7 |
"source": [ |
|
|
8 |
"# Undersampling" |
|
|
9 |
] |
|
|
10 |
}, |
|
|
11 |
{ |
|
|
12 |
"cell_type": "code", |
|
|
13 |
"execution_count": 18, |
|
|
14 |
"id": "cfc764c8", |
|
|
15 |
"metadata": {}, |
|
|
16 |
"outputs": [ |
|
|
17 |
{ |
|
|
18 |
"name": "stdout", |
|
|
19 |
"output_type": "stream", |
|
|
20 |
"text": [ |
|
|
21 |
"1694\n", |
|
|
22 |
"Done\n" |
|
|
23 |
] |
|
|
24 |
} |
|
|
25 |
], |
|
|
26 |
"source": [ |
|
|
27 |
"import os\n", |
|
|
28 |
"import random\n", |
|
|
29 |
"import shutil\n", |
|
|
30 |
"\n", |
|
|
31 |
"source = r\"F:\\Leuk study re-designed\\C-NMC\\High imbalance\\Train - 1 to 102 ratio\\enhanched\\hem\"\n", |
|
|
32 |
"dest = r\"F:\\Leuk study re-designed\\C-NMC\\High imbalance\\Majority Calss Undersample\\enhanched\\hem\"\n", |
|
|
33 |
"files = os.listdir(source)\n", |
|
|
34 |
"\n", |
|
|
35 |
"percentage = 50 #High Imbalance\n", |
|
|
36 |
"# percentage = 10 #Low Imbalance\n", |
|
|
37 |
"\n", |
|
|
38 |
"no_of_files = int((percentage/100)*len(files))\n", |
|
|
39 |
"print(no_of_files)\n", |
|
|
40 |
"# no_of_files = len(files) // 5\n", |
|
|
41 |
"\n", |
|
|
42 |
"for file_name in random.sample(files, no_of_files):\n", |
|
|
43 |
" shutil.copy(os.path.join(source, file_name), dest)\n", |
|
|
44 |
"print('Done')" |
|
|
45 |
] |
|
|
46 |
} |
|
|
47 |
], |
|
|
48 |
"metadata": { |
|
|
49 |
"kernelspec": { |
|
|
50 |
"display_name": "leukemia", |
|
|
51 |
"language": "python", |
|
|
52 |
"name": "leukemia" |
|
|
53 |
}, |
|
|
54 |
"language_info": { |
|
|
55 |
"codemirror_mode": { |
|
|
56 |
"name": "ipython", |
|
|
57 |
"version": 3 |
|
|
58 |
}, |
|
|
59 |
"file_extension": ".py", |
|
|
60 |
"mimetype": "text/x-python", |
|
|
61 |
"name": "python", |
|
|
62 |
"nbconvert_exporter": "python", |
|
|
63 |
"pygments_lexer": "ipython3", |
|
|
64 |
"version": "3.8.3" |
|
|
65 |
} |
|
|
66 |
}, |
|
|
67 |
"nbformat": 4, |
|
|
68 |
"nbformat_minor": 5 |
|
|
69 |
} |