Beispiel #1
0
    def testRbf(self, kTup=('rbf', 1.5)):
        dataArr, labelArr = self.loadDataSet('data/svm/testSetRBF.txt')

        svm = SVMLib()
        datMat = mat(dataArr)
        ## 训练数据
        RBF = svm.fit_RBF(dataArr, labelArr, 200, 0.0001, 10000, kTup)
        print RBF.b, '----', RBF.alphas
        print "支持向量数量为 %d " % shape(RBF.sVs)[0]
        m, n = shape(datMat)
        errorCount = 0
        for i in range(m):
            ## 测试数据
            predict = svm.predict_RBF(RBF, datMat[i, :], kTup)
            if sign(predict) != sign(labelArr[i]): errorCount += 1
        print "培训集错误率: %f" % (float(errorCount) / m)
        #
        dataArr, labelArr = self.loadDataSet('data/svm/testSetRBF2.txt')
        errorCount = 0
        datMat = mat(dataArr)
        m, n = shape(datMat)
        for i in range(m):
            predict = svm.predict_RBF(RBF, datMat[i, :], kTup)
            if sign(predict) != sign(labelArr[i]): errorCount += 1
        print "训练集错误率: %f" % (float(errorCount) / m)
	def testRbf(self, kTup=('rbf', 1.5)):
		dataArr, labelArr = self.loadDataSet('data/dataset2svm/testSetRBF.txt')

		svm = SVMLib()
		datMat = mat(dataArr);
		## 训练数据
		RBF = svm.fit_RBF(dataArr, labelArr, 200, 0.0001, 10000, kTup)
		print RBF.b, '----', RBF.alphas
		print "支持向量数量为 %d " % shape(RBF.sVs)[0]
		m, n = shape(datMat)
		errorCount = 0
		for i in range(m):
			## 测试数据
			predict = svm.predict_RBF(RBF, datMat[i, :], kTup)
			if sign(predict) != sign(labelArr[i]): errorCount += 1
		print "培训集错误率: %f" % (float(errorCount) / m)
		#
		dataArr, labelArr = self.loadDataSet('data/dataset2svm/testSetRBF2.txt')
		errorCount = 0
		datMat = mat(dataArr);
		m, n = shape(datMat)
		for i in range(m):
			predict = svm.predict_RBF(RBF, datMat[i, :], kTup)
			if sign(predict) != sign(labelArr[i]): errorCount += 1
		print "训练集错误率: %f" % (float(errorCount) / m)
Beispiel #3
0
    def testDigits(self, kTup=('rbf', 10)):
        dataArr, labelArr = self.loadImages('data/svm/trainingDigits')

        svm = SVMLib()
        RBF = svm.fit_RBF(dataArr, labelArr, 200, 0.0001, 10000, kTup)
        print RBF.b, '----'
        datMat = mat(dataArr)
        print "there are %d Support Vectors" % shape(RBF.sVs)[0]
        m, n = shape(datMat)
        errorCount = 0
        for i in range(m):
            predict = svm.predict_RBF(RBF, datMat[i, :], kTup)
            if sign(predict) != sign(labelArr[i]): errorCount += 1
        print "the training error rate is: %f" % (float(errorCount) / m)

        dataArr, labelArr = self.loadImages('data/svm/testDigits')
        errorCount = 0
        datMat = mat(dataArr)
        m, n = shape(datMat)
        for i in range(m):
            predict = svm.predict_RBF(RBF, datMat[i, :], kTup)
            if sign(predict) != sign(labelArr[i]): errorCount += 1
        print "the test error rate is: %f" % (float(errorCount) / m)
	def testDigits(self, kTup=('rbf', 10)):
		dataArr, labelArr = self.loadImages('data/dataset2svm/trainingDigits')

		svm = SVMLib()
		RBF = svm.fit_RBF(dataArr, labelArr, 200, 0.0001, 10000, kTup)
		print RBF.b, '----'
		datMat = mat(dataArr);
		print "there are %d Support Vectors" % shape(RBF.sVs)[0]
		m, n = shape(datMat)
		errorCount = 0
		for i in range(m):
			predict = svm.predict_RBF(RBF, datMat[i, :], kTup)
			if sign(predict) != sign(labelArr[i]): errorCount += 1
		print "the training error rate is: %f" % (float(errorCount) / m)

		dataArr, labelArr = self.loadImages('data/dataset2svm/testDigits')
		errorCount = 0
		datMat = mat(dataArr);
		m, n = shape(datMat)
		for i in range(m):
			predict = svm.predict_RBF(RBF, datMat[i, :], kTup)
			if sign(predict) != sign(labelArr[i]): errorCount += 1
		print "the test error rate is: %f" % (float(errorCount) / m)