我正在尝试将这些培训数据提供给sklearn.svm.SVC()
,但在我尝试ValueError: setting an array element with a sequence.
时会返回错误clf.fit(v,v2)
。在将这些数据提交给SVC()
之前,我们如何处理这些数据?
from PIL import Image
from sklearn import svm
for i in xrange(1,55):
t = list(Image.open("train/"+str(i)+".png").getdata())
v.append(t)
v = np.asarray(v)
v2 = np.array(["1","F","9","D","E","E","E","9","0","D","0","3","C","B","F","9","A","E","B","8","A","8","7",
"9","9","3","C","6","1","E","6","6","C","C","F","A","8","0","1","F","F","E","9","4","6","0",
"7","2","D","9","A","C","7","E"])
clf = svm.SVC()
答案 0 :(得分:0)
我认为你正在寻找这样的东西:
from scipy import misc
import glob
from sklearn import svm
filenames = glob.glob('train/*.png')
X = [misc.imread(each).flatten() for each in filenames]
y = ["1","F","9","D","E","E", ...]
model = svm.SVC().fit(X, y)
注意:
X
的格式为(n_images, n_pixels)
n_pixels=width*height
y
的长度为n_images
(在您的示例中为54)这只是一个开始,您应该尝试为分类器提供单个像素的更有意义的功能。