-
Notifications
You must be signed in to change notification settings - Fork 0
/
svm_k-fold.py
36 lines (31 loc) · 941 Bytes
/
svm_k-fold.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
from sklearn.model_selection import cross_val_score
#Used for storing and loading the trained classifier
from sklearn.externals import joblib
import numpy
from MachineSpecificSettings import Settings
import scipy.io
from DataSetLoaderLib import DataSetLoader
from sklearn import svm
from sklearn import metrics
print("")
print("")
print("")
print("")
targets=numpy.array(joblib.load('DatasetA_ValidationClasses.joblib.pkl'))
d = DataSetLoader();
G = d.LoadDataSet("A");
indices= joblib.load('selected_indicesv2.joblib.pkl')
result=numpy.array(G)[:,indices]
clf = svm.SVC(kernel='poly')
import time
start_time=time.time()
scores = cross_val_score(clf, result, targets, cv=10)
end_time=time.time()-start_time
print "It took: ",end_time
for i in scores:
print i
print("Accuracy: %0.2f (+/- %0.2f)" % (scores.mean(), scores.std() * 2))
filename='svm.joblib.pkl'
joblib.dump(clf,filename, compress=9)
params = clf.get_params()
print params