def adaClassify(datToClass, classifierArr): dataMatrix = mat(datToClass) m = shape(dataMatrix)[0] aggClassEst = mat(zeros((m,1))) #iterate all classifier, and estimate a value of each classifier using stumpClassify() for i in range(len(classifierArr)): classEst = boost.stumpClassify(dataMatrix, classifierArr[i]['dim'], classifierArr[i]['thresh'], classifierArr[i]['ineq']) aggClassEst += classifierArr[i]['alpha']*classEst return sign(aggClassEst)
def adaClassify(datToClass, classifierArr): dataMatrix = mat(datToClass) m = shape(dataMatrix)[0] aggClassEst = mat(zeros((m, 1))) for i in range(len(classifierArr)): classEst = stumpClassify(dataMatrix, classifierArr[i]['dim'], classifierArr[i]['thresh'], classifierArr[i]['ineq']) aggClassEst += classifierArr[i]['alpha'] * classEst print(aggClassEst.T) return sign(aggClassEst.T)
def adaClassify(datToClass, classifierArr): ''' classify data with our trained classifiers ''' dataMatrix = np.mat(datToClass) m = np.shape(dataMatrix)[0] aggClassEst = np.mat(np.zeros((m, 1))) for i in range(len(classifierArr)): classEst = stumpClassify(dataMatrix, classifierArr[i]['dim'],\ classifierArr[i]['thresh'],\ classifierArr[i]['ineq']) aggClassEst += classifierArr[i]['alpha'] * classEst #print(aggClassEst) return np.sign(aggClassEst)
def adaClassify(dataToClass, classifierArr): ''' AdaBoost分类函数 input:一个或多个待分类样例、多个弱分类器组成的数组 ''' dataMatrix = np.mat(dataToClass) m = np.shape(dataMatrix)[0] aggClassEst = np.mat(np.zeros((m, 1))) #同上 for i in range(len(classifierArr)): classEst = boost.stumpClassify(dataMatrix,classifierArr[i]['dim'],\ classifierArr[i]['thresh'],\ classifierArr[i]['ineq']) aggClassEst += classifierArr[i]['alpha'] * classEst print(aggClassEst) return np.sign(aggClassEst)
def adaClassify(datToClass, classifierArray): ''' 输入参数: datToClass:一个或者多个待分类样例 classifierArray:多个弱分类进行分类的函数 ''' dataMatrix = np.mat(datToClass) m = np.shape(dataMatrix)[0] #记录每个数据点的类别估计累计值 aggClassEst = np.mat(np.zeros((m, 1))) #遍历classifierArray中的所有弱分类器 for i in range(len(classifierArray)): classEst = boost.stumpClassify(dataMatrix, classifierArray[i]['dim'], \ classifierArray[i]['thresh'], \ classifierArray[i]['ineq']) aggClassEst += classifierArray[i]['alpha'] * classEst print(aggClassEst) return np.sign(aggClassEst)
def adaClassify(dataToClass, classifierArr): """ 根据训练得到的一组弱分类器及其alpha权重,对数据进行分类 :param datToClass: 待分类数据的新数据 :param classifierArr: 弱分类器集合 :return: """ dataMatrix = mat(dataToClass) m = dataMatrix.shape[0] aggClassEst = mat(zeros((m, 1))) print("#############Prediction begin......##########") for i in range(len(classifierArr)): print("==========%d th classifier predict result:===========" % i) classEst = boost.stumpClassify(dataMatrix, classifierArr[i]['dim'], classifierArr[i]['thresh'], classifierArr[i]['ineq']) aggClassEst += classEst * classifierArr[i]['alpha'] print(aggClassEst) print() return sign(aggClassEst)