Skip to content

Commit

Permalink
perceptron
Browse files Browse the repository at this point in the history
  • Loading branch information
WenDesi committed Jul 16, 2016
1 parent 6b4dae2 commit 25e644a
Show file tree
Hide file tree
Showing 23 changed files with 140,839 additions and 0 deletions.
6 changes: 6 additions & 0 deletions .idea/encodings.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

14 changes: 14 additions & 0 deletions .idea/misc.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 8 additions & 0 deletions .idea/mnist_test.iml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 8 additions & 0 deletions .idea/modules.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

43 changes: 43 additions & 0 deletions .idea/workspace.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

55 changes: 55 additions & 0 deletions binary_svm.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
import pandas as pd
import numpy as np
import csv as csv
import cv2

from sklearn.neighbors import KNeighborsClassifier
from sklearn.decomposition import RandomizedPCA
from sklearn.cross_validation import train_test_split
from sklearn.metrics import accuracy_score
from sklearn import svm

def get_hog_features(trainset):
features = []

hog = cv2.HOGDescriptor('hog.xml')

for img in trainset:
img = np.reshape(img,(28,28))
cv_img = img.astype(np.uint8)

hog_feature = hog.compute(cv_img)
# hog_feature = np.transpose(hog_feature)
features.append(hog_feature)

features = np.array(features)
features = np.reshape(features,(-1,324))
print features.shape
return features

train_raw=pd.read_csv('data/train_binary.csv',header=0)
train = train_raw.values


print 'Start PCA to 50'
train_x=train[0::,1::]
train_label=train[::,0]

features = get_hog_features(train_x)

# # pca
# pca = RandomizedPCA(n_components=50, whiten=True).fit(train_x)
# train_x_pca = pca.transform(train_x)
# test_x_pca = pca.transform(test)
# print train_x
a_train, b_train, a_label, b_label = train_test_split(features, train_label, test_size=0.33, random_state=23323)
print a_train.shape
print a_label.shape

print 'Start training'
rbf_svc = svm.SVC(kernel='rbf')
rbf_svc.fit(a_train,a_label)
print 'Start predicting'
b_predict=rbf_svc.predict(b_train)
score=accuracy_score(b_label,b_predict)
print "The accruacy socre is ", score
Loading

0 comments on commit 25e644a

Please sign in to comment.