deftestRbf(k1):dataArr,labelArr=loadDataSet('testSetRBF.txt')b,alphas=smoP(dataArr,labelArr,200,0.0001,10000,('rbf',k1))datMat=mat(dataArr)labelMat=mat(labelArr).transpos...
def testRbf(k1):
dataArr,labelArr=loadDataSet('testSetRBF.txt')
b,alphas=smoP(dataArr,labelArr,200,0.0001,10000,('rbf',k1))
datMat=mat(dataArr)
labelMat=mat(labelArr).transpose()
svInd=nonzero(alphas.A>0)[0]
print(svInd)
print(alphas[svInd])
sVs=datMat[svInd]
labelSV=labelMat[svInd]
print('there are %d Support Vectors'% shape(sVs)[0])
m,n=shape(datMat)
errorCount=0
# predict=mat(zeros((m,1)))
for i in range(m):
kernelEval = kernelTrans(sVs,datMat[i,:],('rbf',k1))
predict = kernelEval.T * multiply(labelSV,alphas[svInd]) + b
if sign(predict)!=sign(labelArr[i]):errorCount += 1
print('the training error rate is :%f' % (float(errorCount)/m))
dataArr,labelArr=loadDataSet('testSetRBF2.txt')
errorCount=0
datMat=mat(dataArr)
labelMat=mat(labelArr).transpose()
m,n=shape(datMat)
for i in range(m):
kernelEval=kernelTrans(sVs, datMat[i,:],('rbf',k1))
predict=kernelEval.T*multiply(labelSV,alphas[svInd])+b
if sign(predict)!=sign(labelArr[i]):errorCount+=1
print('the test error rate is :%f'%(float(errorCount)/m))
这是SVM算法中的一段程序,运行后有时又能正常使用,大部分会出现下面的错误
RuntimeWarning: invalid value encountered in add
predict = kernelEval.T * multiply(labelSV,alphas[svInd]) + b
求大神解释一下这是什么问题,谢谢!!!!
展开