-
Notifications
You must be signed in to change notification settings - Fork 0
/
kFold_final.py
112 lines (74 loc) · 2.66 KB
/
kFold_final.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
import numpy as np
from sklearn import preprocessing
import tensorflow.contrib.learn as skflow
import tensorflow as tf
from sklearn import metrics
from sklearn.feature_selection import SelectKBest
from sklearn import feature_selection as fs
from sklearn.model_selection import KFold
from sklearn.feature_selection import RFE
from sklearn.svm import SVR
import time
start_time = time.time()
tf.logging.set_verbosity(tf.logging.INFO)
data=np.genfromtxt('final.csv',delimiter=',')
X = data[: , 0:1548] # 1546 features, +1 output column, +1 for python index
#X_new = SelectKBest(fs.f_classif, k=600).fit_transform(X, y)
#feature select
#feature_numbers=len(X_new[1])+1
kfoldResult=np.array([])
kf = KFold(n_splits=10, shuffle=False, random_state=None)
for train, test in kf.split(X):
#print(train.shape)
#print(test.shape)
#kfloditeration=kfloditeration+1
X_train=X[train]
X_test=X[test]
#for train set
train_features=X_train[: , 0:1546]
train_output=X_train[:,1546]
#print(train_features.shape)
#feature cut
train_features = SelectKBest(fs.f_classif, k=99).fit_transform(train_features, train_output)
test_features=X_test[: , 0:1546]
test_output=X_test[:,1546]
#feature cut
test_features = SelectKBest(fs.f_classif, k=99).fit_transform(test_features, test_output)
#print(test_features.shape)
#print(X_train_Class)
#data scalling ........... This do Work Faster
train_X = preprocessing.scale(train_features)
test_X = preprocessing.scale(test_features)
#print(train_X.shape)
#print(standardized_X[1,1])
#parameter for classifier
feature_columns = [tf.contrib.layers.real_valued_column("", dimension=98)]
a = np.array([])
p=100
nTimes=2
for i in range(1,nTimes):
#classifier
classifier = skflow.DNNClassifier(feature_columns=feature_columns,
hidden_units=[25,15,10],
n_classes=2,
#optimizer=tf.train.GradientDescentOptimizer(0.1))
optimizer=tf.train.AdamOptimizer)
#train dataset
classifier.fit(train_X, train_output, steps=p)
p=p+22
#accuracy print
accuracy_score = classifier.evaluate(test_X, test_output, steps=1)["accuracy"]
a=np.append(a,accuracy_score)
print("\nTest Accuracy: {0:f}\n".format(accuracy_score))
#for i in range(0,nTimes):
#print(a[i])
#print('Max value')
#print(a.max())
kfoldResult=np.append(kfoldResult,a.max())
for element in kfoldResult:
print(element)
print("Max Value In Kfold : ")
print(kfoldResult.max())
print("Avrg Value In Kfold: ")
print(kfoldResult.mean())
print("--- %s seconds ---" % (time.time() - start_time))