-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSVM.py
More file actions
38 lines (31 loc) · 1.06 KB
/
Copy pathSVM.py
File metadata and controls
38 lines (31 loc) · 1.06 KB
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
import numpy
from sklearn import svm
from sklearn.model_selection import cross_val_score
from sklearn.multiclass import OneVsRestClassifier
# load dataset
dataset = numpy.loadtxt("heart.txt", delimiter=",")
# split into input (X) and output (Y) variables
X = dataset[:, 0:13]
Y = dataset[:,13]
XTest1 = dataset[0:91, 0:13]
YTest1 = dataset[0:91, 13]
XTest1 = numpy.concatenate([XTest1, dataset[181:271, 0:13]])
YTest1 = numpy.concatenate([YTest1, dataset[181:271, 13]])
XTest1Valid = dataset[91:181, 0:13]
YTest1Valid = dataset[91:181, 13]
XPredict = dataset[250:271, 0:13]
YPredict = dataset[250:271, 13]
ovr = OneVsRestClassifier(svm.SVC(kernel='linear', C=2))
ovr.fit(X, Y)
cross = cross_val_score(ovr, X, Y, cv=3)
print("Cross-Validation")
print(cross)
scores = ovr.score(XTest1, YTest1)
print("Evalutation: %0.2f%%" % (scores.mean()*100))
scores = ovr.score(XTest1Valid, YTest1Valid)
print("Validation: %0.2f%%" % (scores.mean()*100))
print("Vraies valeurs = ")
print(YPredict)
print("Prédictions = ")
print(ovr.predict(XPredict))
print(ovr.decision_function(XPredict))