-
Notifications
You must be signed in to change notification settings - Fork 0
/
data clean for clasification.py
154 lines (106 loc) · 2.65 KB
/
data clean for clasification.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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
import pandas as pd
df=pd.read_csv('data.csv')
#print(df.head())
new=pd.DataFrame()
# drop ->
dropp=['pluralty','date','outcome','id','sex','marital'] #all sex=1
df=df.drop(dropp,1)
df.info()
# colum need to be changed
# #Gastation
# Gastaion - 280< gas <320 -> 0 risk or 1 no risk
gestation=df['gestation'].values
for i in range(0,len(gestation)):
if gestation[i]>=280 and gestation[i]<=320:
gestation[i]=1
else:
gestation[i] = 0
new['gestation_days']=gestation
#race-> 0=white, 6=mex, 7=black, 8=asian, 9=mix
race=df['race'].values
print(set(race))
x=0
for i in range(0,len(race)):
if race[i] <=5:
race[i]=0
if race[i] ==99:
race[i] =0
if race[i] == 10:
race[i] = 0
print(set(race))
new['race']=race
# education
# mom education, 0=(<8), 1=(8-<12), 2=12, 3=12+trade, 4=12+some college, 5=16, 7=trade (hs unclear), 9=unknown
test=df['ed'].values
new['education']=test
# age - early{0} <=18 : 19<perfect{1}<34 : late>34{2}
age=df['age'].values
for i in range(0,len(age)):
if age[i]<18:
age[i]=0
elif age[i]>=18 and age[i]<=34:
age[i] = 1
elif age[i]>34:
age[i]=2
new['mom_age']=age
# weight & Height
ht=df['ht'].values
wt=df['mwt'].values
weight=[]
for i in range(0,len(ht)):
miter=0.0254*ht[i]
kg=0.453592*wt[i]
bmi=kg/(miter*miter)
if bmi<18.5:
ht[i]=0
elif bmi>=18.5 and bmi<=24.9:
ht[i] = 1
elif bmi> 24.9:
ht[i] = 2
new['mother_bmi']=ht
#For dad
# age - early{0} <=21 : 21<perfect{1}<39 : late>39{2}
d_age=df['dage'].values
for i in range(0,len(d_age)):
if d_age[i]<21:
d_age[i]=0
elif d_age[i]>=21 and d_age[i]<=39:
d_age[i] = 1
elif d_age[i]>39:
d_age[i]=2
new['dad_age']=d_age
# weight & Height
htt=df['dht'].values
wt=df['dwt'].values
d_weight=[]
for i in range(0,len(htt)):
miter=0.0254*htt[i]
kg=0.453592*wt[i]
bmi=kg/(miter*miter)
if bmi<18.5:
wt [i]=0
elif bmi>=18.5 and bmi<=24.9:
wt[i] = 1
elif bmi> 24.9:
wt[i] = 2
new['dad_bmi']=wt
#mother smoke 1= no smoke || 0= smoke
smoke=df['smoke'].values
for i in range(0,len(smoke)):
if smoke[i]==1:
smoke[i]=1
else:
smoke[i]=0
new['smoke']=smoke
#baby weights on -> ounce
#
out=df['wt'].values
outcome=[]
for i in range(0,len(out)):
if out[i]>88 and out[i]<135:
out[i]=1
else:
out[i] = 0
x+=1
new['baby_weight']=out
new.to_csv('data_for_clasification.csv', index=False)