-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsvmExample.py
More file actions
46 lines (35 loc) · 1.07 KB
/
svmExample.py
File metadata and controls
46 lines (35 loc) · 1.07 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
39
40
41
42
43
44
45
46
'''
This class sets up the titanic problem to be solved using SVM, Support Vector Machines.
Accuracy: 0.77511
'''
#import the SVM class
import SVM.SVM as svm
#import the model
import data.TitanicParser as model
#build the SVM trainer, use 50% of data to train, 30% to validate, and 20% to test
trainer = svm.SVM(partitioner=[.5,.3,.2])
#load training data from the model
X,Y = model.loadTrainData(includeEmbark=False)
#remap labels to -1,1
for i in range(len(Y)):
Y[i] = (Y[i] - .5) * 2
#load the data into the trainer
trainer.loadTrainingData(X,Y)
#start training
trainer.train()
#load the data we want to classify
passenger, testX = model.loadActualTestData(includeEmbark=False)
#open output file
output = open("svmout.csv", "w+")
#print header
output.write("PassengerId,Survived\n")
#predict the labels for our test set
guesses = trainer.predict(testX, negativeValue=0)
#write the guesses out to file
for i in range(len(guesses)):
output.write(str(passenger[i]))
output.write(",")
output.write(str(guesses[i]))
output.write("\n")
#close output
output.close()