数学之路(3)-机器学习(3)-机器学习算法-SVM[9]

我们应用SVM的非线性分类功能对手写数字进行识别,我们在这应用poly做为非线性核

 

 

svm = mlpy.LibSvm(svm_type='c_svc', kernel_type='poly',gamma=10)
svm.learn(x, y)


我们按像素分块读取数字特征后,形成训练样本,送入SVM训练

 

本博客所有内容是原创,如果转载请注明来源

http://blog.csdn.net/myhaspl/

 



对样本本身测试

 

print svm.pred(x)


对供测试的未知样本进行测试

 


测试代码如下:

 

for iii in xrange (1,10):
    testfn= 'nums/test/'+str(iii)+'-test.png'
    testx=[]
    testx.append(getnumc(testfn))
    print svm.pred(testx)


 

 

识别效果还可以,通过增加笔型差异较大的训练样本,效果将更好

>>> runfile(r'I:\book_prog\numsbsvm.py', wdir=r'I:\book_prog')

http://blog.csdn.net/myhaspl
myhaspl@qq.com


loading  ...
[ 1.  1.  1.  1.  2.  2.  2.  2.  3.  3.  3.  3.  4.  4.  4.  4.  5.  5.
  5.  5.  6.  6.  6.  6.  7.  7.  7.  7.  8.  8.  8.  8.  9.  9.  9.  9.]
[ 1.]
[ 2.]
[ 3.]
[ 4.]
[ 5.]
[ 6.]
[ 7.]
[ 8.]
[ 9.]
>>> 


 

posted on 2013-09-15 19:37  新一  阅读(270)  评论(0)    收藏  举报

导航