我有一套540的训练集和150个图像像素的测试集。这些值存储在不同的csv文件中,如下所示:
[label],[num0],[num1],...,[num399]
标签是单个字母,400个是像素值。该套装用于手语识别。
代码 -
import numpy as np
import os
import csv
from sklearn import svm
from sklearn import cross_validation
from sklearn import linear_model
path = '/home/goel/skin'
X_train=[]
y_train=[]
X_test=[]
y_test=[]
ylist=[]
with open("20_20_centered_newer.csv",'r') as file:
reader = csv.reader(file,delimiter=',')
reader.next()
for row in file:
y_train.append(row[0])
if row[0] not in ylist:
ylist.append(row[0])
row=row[2:]
row=[int(x) for x in row.split(',')]
X_train.append(np.array(row))
y2list=[]
with open("20x20_test.csv",'r') as file:
reader = csv.reader(file,delimiter=',')
for row in file:
y_test.append(row[0])
if row[0] not in y2list:
y2list.append(row[0])
row=row[2:]
row=[int(x) for x in row.split(',')]
X_test.append(np.array(row))
print ylist
print y2list
#clf = linear_model.SGDClassifier().fit(X_train,y_train)
#clf = svm.SVC(kernel='linear').fit(X_train,y_train)
#clf = svm.LinearSVC().fit(X_train,y_train)
clf = linear_model.LogisticRegression().fit(X_train,y_train)
print clf.score(X_test,y_test)
显然,我在所有分类器中得到的分数为.78,最多12位小数!
这里是否存在我不知道的语义错误?