-
Notifications
You must be signed in to change notification settings - Fork 79
Expand file tree
/
Copy pathrandomsubset.py
More file actions
41 lines (32 loc) · 951 Bytes
/
randomsubset.py
File metadata and controls
41 lines (32 loc) · 951 Bytes
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
import os
from random import *
import pandas as pd
import shutil
rs = Random()
rs.seed(1)
trainlabels = pd.read_csv('trainLabels.csv')
fids = []
opd = pd.DataFrame()
for clabel in range (1,10):
mids = trainlabels[trainlabels.Class == clabel]
mids = mids.reset_index(drop=True)
rchoice = [rs.randint(0,len(mids)-1) for i in range(100)]
print rchoice
# for i in rchoice:
# fids.append(mids.loc[i].Id)
# opd = opd.append(mids.loc[i])
rids = [mids.loc[i].Id for i in rchoice]
fids.extend(rids)
opd = opd.append(mids.loc[rchoice])
print len(fids)
opd = opd.reset_index(drop=True)
print opd
opd.to_csv('subtrainLabels.csv', encoding='utf-8', index=False)
sbase = '/home/moon/train/'
tbase = '/home/moon/subtrain/'
for fid in fids:
fnames = ['{0}.asm'.format(fid),'{0}.bytes'.format(fid)]
for fname in fnames:
cspath = sbase + fname
ctpath = tbase + fname
shutil.copy(cspath,ctpath)