from numpy import * import AdaBoost datMat, classLabels = AdaBoost.loadSimpData() # D=mat(ones((5,1))/5) # print(AdaBoost.buildingStump(datMat,classLabels,D)) classEstArr = AdaBoost.adaBoostTrainDS(datMat, classLabels, 10) print(AdaBoost.adaClassify([[5, 5], [0, 0]], classEstArr))
ax = plt.subplot(111) #画图 for index in sortedIndicies.tolist()[0]: if classLabels[index] == 1.0: delX = 0; delY = yStep; else: delX = xStep; delY = 0; ySum += cur[1] ax.plot([cur[0],cur[0]-delX],[cur[1],cur[1]-delY], c='b') cur = (cur[0]-delX,cur[1]-delY) ax.plot([0,1],[0,1],'b--') plt.xlabel('False positive rate') plt.ylabel('True positive rate') plt.title('ROC curve for AdaBoost horse colic detection system') ax.axis([0,1,0,1]) plt.show() print("the Area Under the Curve is: ",ySum*xStep) if __name__ == '__main__': trainingMat,trainingLabels = AdaBoost.loadDataSet('horseColicTraining2.txt') classifierArray = AdaBoost.adaBoostTrainDS(trainingMat,trainingLabels, 10) testMat,testLabels = AdaBoost.loadDataSet('horseColicTest2.txt') prediction10 = AdaBoost.adaClassify(testMat, classifierArray) print(prediction10) plotROC(prediction10, testLabels)
# -*- coding: utf-8 -*- """ AdaBoost:简单数据集 @author: Jerry """ import numpy as np import AdaBoost def loadDataSet(): dataMat = np.matrix(([1., 2.1], [2., 1.1], [1.3, 1.], [1., 1.], [2., 1.])) classLabels = [1.0, 1.0, -1.0, -1.0, 1.0] return dataMat, classLabels if __name__ == '__main__': dataMat, classLabels = loadDataSet() # AdaBoost.adaBoostTrainDS(dataMat,classLabels, 9) classifierArray = AdaBoost.adaBoostTrainDS(dataMat, classLabels, 30) predictedLabel = AdaBoost.adaClassify([0, 0], classifierArray) print(predictedLabel)
# -*- coding: utf-8 -*- """ Created on Wed Oct 10 20:38:02 2018 @author: tf """ import AdaBoost import numpy as np #dataMat, labelMat = AdaBoost.loadDataSet() #print(dataMat, '\n', labelMat) #D = np.ones((5, 1)) / 5 #bestStump, minErr, bestClassEst = AdaBoost.buildStump(dataMat, labelMat, D) #print(bestStump, '\n', minErr, '\n', bestClassEst) #classifierArr = AdaBoost.adaBoostTrainDS(dataMat, labelMat) #print(classifierArr) #print(max(0.1,0.2)) #clas = AdaBoost.adaClassify(np.array([[5, 5], [0, 0]]), classifierArr) #print(clas) dataMat, labelMat = AdaBoost.loadFileDataSet('horseColicTraining2.txt') classifierArr = AdaBoost.adaBoostTrainDS(dataMat, labelMat) #print(classifierArr) testDataMat, testLabelMat = AdaBoost.loadFileDataSet('horseColicTest2.txt') errRate = AdaBoost.adaClassify(testDataMat, classifierArr, testLabelMat) print(errRate)