-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathclassifier_test.py
More file actions
32 lines (23 loc) · 831 Bytes
/
Copy pathclassifier_test.py
File metadata and controls
32 lines (23 loc) · 831 Bytes
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
from sklearn import svm, preprocessing
from sklearn import cross_validation
from sklearn.multiclass import OneVsRestClassifier
import numpy as np
'''
Classification Test
'''
# load dataset from pickled numpy files
class_labels = np.load("class_labels.npy")
dataset = np.load("dataset.npy")
# normalize dataset
dataset = preprocessing.scale(dataset)
# split train/test data 50/50
X_train, X_test, y_train, y_test = cross_validation.train_test_split(dataset, class_labels, test_size=0.5)
#train classifier
clf = OneVsRestClassifier(svm.LinearSVC(random_state=0)).fit(X_train, y_train)
# generate predictions for test data
predict = clf.predict(X_test)
# percent correctly predicted
result_sum = float((predict == y_test).sum())
print((result_sum/len(X_test)))
# Accuracy on train/test split
print(clf.score(X_test, y_test))