This repository was archived by the owner on Mar 23, 2026. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathPython_script.py
More file actions
73 lines (60 loc) · 2.41 KB
/
Python_script.py
File metadata and controls
73 lines (60 loc) · 2.41 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
import os
import csv
import numpy as np
import shutil
directory = "dataset/"
for root,dirs,files in os.walk(directory):
a = 0
j = 0
multi_class = []
binary_class = []
for file in files:
if file.endswith(".csv"):
with open(directory+file, 'r', newline = '') as csvfile:
dataset = csv.reader(csvfile, delimiter = ',')
dataset = list(dataset)
label_col = []
#_______________________
#Check number of samples
#_______________________
sample_size = 0
for line in dataset:
sample_size +=1
#________________________
# Check number of features
#________________________
for line1 in dataset:
#print("[DEBUG] Entered for loop of features")
no_of_feat = len(line1)
#print('[DEBUG] No of features ', no_of_feat)
if ((no_of_feat>21) & (sample_size>1000)):
k = True # Setting up a flag
j = j+1
else:
k = False
break
if (k==False): #Skip rest of the code-> go back to for file in files;
continue
#_________________________
# Check for binary classes
#_________________________
for line in dataset:
label_col.append(line[-1])
if(len(set(label_col))>2):
multi_class.append(file)
elif(len(set(label_col))==2):
binary_class.append(file)
a = a+1
else:
print("Single label: Not required")
print("No of files having attributes greater than 20: ", j)
print("No of files with attributes>=20 and binary classes: ", a)
writedirname = "BinaryData_Samplesize_greaterthan_1000/"
p = os.path.abspath('.')
path = os.path.join(p, writedirname)
os.mkdir(path)
directory = "UCI_Dataset/"
for file in binary_class:
src = directory + file
dst = writedirname + file
shutil.copyfile(src, dst)