-
Notifications
You must be signed in to change notification settings - Fork 35
/
train_svm.py
40 lines (30 loc) · 975 Bytes
/
train_svm.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
# -*- coding: utf-8 -*-
"""
Created on Mon May 16 20:41:24 2016
@author: ldy
"""
from time import time
from sklearn.metrics import accuracy_score
from sklearn.cross_validation import train_test_split
from sklearn.externals import joblib
from sklearn import svm
#
import numpy as np
acc = []
nums = [75]
for num in nums:
X_train=np.load('features/features%d_train.npy'%num)
y_train=np.load('features/label%d_train.npy'%num)
X_test=np.load('features/features%d_test.npy'%num)
y_test=np.load('features/label%d_test.npy'%num)
print("Fitting the classifier to the training set")
t0 = time()
C = 1000.0 # SVM regularization parameter
clf = svm.SVC(kernel='linear', C=C).fit(X_train, y_train)
print("done in %0.3fs" % (time() - t0))
print("Predicting...")
t0 = time()
y_pred = clf.predict(X_test)
print "Accuracy: %.3f" %(accuracy_score(y_test, y_pred))
acc.append(accuracy_score(y_test, y_pred))
print acc