-
Notifications
You must be signed in to change notification settings - Fork 0
/
preprocess.py
60 lines (49 loc) · 1.85 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
# baca file dataset kemudian ditulis kembali ke file
# preprocessing
# - remove atribute (data atribut 3)
# - missing value handling
# - nominal to numeric (hanya yang tidak nominal tidak diubah)
# - normalisasi dataset (z-score) yang merupakan numeric
# ['age','workclass','fnlwgt','education','education-num','marital-status','occupation','relationship','race','sex','capital-gain','capital-loss','hours-per-week','native-country']
import pandas as pd
from sklearn import preprocessing
# Ada masalah, nanti elemennya jadinya ada spasi depannya karena file-nya abis koma ada spasi
class Preprocess(object):
def __init__(self,nameOfFile):
self.dataset = pd.read_csv('dataset/' + nameOfFile,header = None)
self.numberOfAtr = 12
def printDataSet(self):
print(self.dataset.head(5))
# print(self.dataset.describe())
def printHeader(self):
print(self.dataset.columns.values)
def NominalToNumeric(self):
l_pre = preprocessing.LabelEncoder()
self.dataset = self.dataset.apply(l_pre.fit_transform)
# enc = preprocessing.OneHotEncoder()
# enc.fit(self.dataset)
# onehotlabels = enc.transform(self.dataset).toarray()
# print(onehotlabels)
def saveToCSV(self):
self.dataset.to_csv('CencusIncome.data.preprocessing.txt',header = None)
def printAtribute(self,number):
# TBD
print(self.dataset[number].values)
def printRow(self,row):
print(self.dataset.values[row])
def removeAtribute(self,Atribute):
# TBD
return 0
def missingValueHandling(self):
# TBD
return 0
def normalize(self,Atribute):
# TBD
return 0
p = Preprocess('CencusIncome.data.txt')
# p.NominalToNumeric()
# p.printDataSet()
# p.saveToCSV()
p.printAtribute(1)
# p.printRow(1)
# p.printHeader()