-
Notifications
You must be signed in to change notification settings - Fork 0
/
preProcess.py
60 lines (45 loc) · 1.09 KB
/
preProcess.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
import numpy as np
from pandas import read_csv as read_csv
tr = read_csv("train.csv")
columns = list(tr)
drop = []
#Name
if 'Name' in columns:
drop.append('Name')
#Ticket
if 'Ticket' in columns:
drop.append('Ticket')
#Sex
if 'Sex' in columns:
map = {'male' : 1,'female' : 0}
tr['Male'] = tr['Sex'].map(map)
map = {'male' : 0,'female' : 1}
tr['Female'] = tr['Sex'].map(map)
drop.append('Sex')
#Age - has nulls
ind = tr['Age'].isna()
rands = np.random.rand(ind.sum())*100
tr.loc[ind,'Age'] = rands
#Cabins
#Sex
if 'Cabin' in columns:
tr['Cabin'] = tr['Cabin'].fillna(0)
map = {0 : 0}
tr['Cab'] = tr['Cabin'].map(map)
tr['Cab'] = tr['Cab'].fillna(1)
drop.append('Cabin')
#Embarked
drop.append('Embarked')
tr = tr.drop(drop,axis=1)
map = {1 : 0,0 : 1}
tr['Died'] = tr['Survived'].map(map)
Id = tr.as_matrix(['PassengerId'])
label = tr.as_matrix(['Survived','Died'])
data = tr.as_matrix(['Pclass', 'Age', 'SibSp', 'Parch', 'Fare', 'Male', 'Female', 'Cab'])
#
# print(Id)
print(label)
# print(data)
np.save("id",Id)
np.save("labels",label)
np.save("data",data)