-
Notifications
You must be signed in to change notification settings - Fork 0
/
classifier-ratio.py
60 lines (46 loc) · 1.59 KB
/
classifier-ratio.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
# all imports
from sklearn import svm,cross_validation
from sklearn.metrics import accuracy_score
from time import time
import numpy as np
import pandas as pd
#read all files
#df1 = pd.read_csv("trainfeature.csv", header = 0)
#df2 = pd.read_csv("trainlabel.csv", header = 0)
#df3 = pd.read_csv("testfeature.csv", header = 0)
#df4 = pd.read_csv("testlabel.csv", header = 0)
df = pd.read_csv("test2.csv", header = 0)
X = np.array(df.drop(['Diagnosis of AKI(acute kidney injury)(1-infection,2-rejection,4-Normal subjects,3tac toxicity)'],1))
y = np.array(df['Diagnosis of AKI(acute kidney injury)(1-infection,2-rejection,4-Normal subjects,3tac toxicity)'])
#convert to numpy array
#features_train = df1.as_matrix()
#labels_train = df2.as_matrix()
#features_test = df3.as_matrix()
#labels_test = df4.as_matrix()
X_train , X_test , y_train , y_test = cross_validation.train_test_split(X,y,test_size=0.2)
#Input style A
# the classifier
#clf = svm.SVC()
# train
#t0 = time()
#clf.fit(features_train, labels_train.ravel())
#print "\ntraining time:", round(time()-t0, 3), "s"
# predict
#t0 = time()
#pred = clf.predict(features_test)
#print "predicting time:", round(time()-t0, 3), "s"
#accuracy = accuracy_score(pred, labels_test.ravel())
#print '\naccuracy = {0}'.format(accuracy)
#Input style B
# the classifier
clf1 = svm.SVC(kernel="rbf")
# train
t1 = time()
clf1.fit(X_train, y_train)
print "\ntraining time:", round(time()-t1, 3), "s"
# predict
t1 = time()
pred = clf1.predict(X_test)
print "predicting time:", round(time()-t1, 3), "s"
accuracy = accuracy_score(pred, y_test)
print '\naccuracy = {0}'.format(accuracy)