-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpreproc_svm_normalizzato.py
51 lines (43 loc) · 1.34 KB
/
preproc_svm_normalizzato.py
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
# USAGE
# python preproc_svm_normalizzato.py --data data_file.csv
import argparse
import pandas as pd
import numpy as np
ap = argparse.ArgumentParser()
ap.add_argument("-d", "--data", required=True,
help="path to formatted data frame/ear/eye_state")
args = vars(ap.parse_args())
dati=pd.read_csv(args["data"], sep=",", index_col="frame")
#decido di mettere come "1" solo i tag "close"
dati.tag = dati.tag == "close"
'''
dati.tag = dati.tag.where(mask, 1)
mask = dati.tag != "half"
dati.tag = dati.tag.where(mask, 0)
'''
listear=list(dati.ear)
#normalizzo
listear=np.array(listear)
listear=(listear-np.nanmin(listear))/(np.nanmax(listear)-np.nanmin(listear))
listear=list(listear)
listtag=list(dati.tag)
col=['F1',"F2","F3","F4","F5",'F6',"F7","F8","F9","F10",'F11',"F12","F13","blink"]
df_fin=pd.DataFrame(columns=col)
for i in range(6, len(listear)-7):
tmp_ear=listear[i-6:i+7]
tmp_tag=sum(listtag[i-6:i+7])
if tmp_tag==0:
tmp_tag=0
else:
tmp_tag=1
'''
tmp_dict=dict()
for j in range(0,6):
tmp_dict[col[j]]=tmp_ear[j]
'''
tmp_ear.append(tmp_tag)
#df_tmp=pd.DataFrame(data=[tmp_ear], columns=col)
df_fin.loc[i]=tmp_ear
df_fin.index.name="frame"
df_fin.dropna(how='any', inplace=True)
df_fin.to_csv("preprocessed/preproc_{}".format(args["data"][11:]), index=True, header=True)