acc_rem = [] #初始化精度列表 for ii in range(10): #data.target = data.target + 1 #stdsc = StandardScaler() #label_size = 0.5 (train_data, iter_data, test_data) = elmUtils.splitDataWithIter(data.data, data.target, label_size, 0.3) iter_y = BvsbUtils.KNNClassifierResult(train_data[0], train_data[1], iter_data[0]) bvsbc = BvsbClassifier(train_data[0], train_data[1], iter_data[0], iter_y, test_data[0], test_data[1], iterNum=0.1) bvsbc.createOSELM(n_hidden=1000, active_function="sigmoid") bvsbc.trainOSELMWithKNNButBvsb() print(f'OSELM-BVSB-KNN 正确率为{bvsbc.score(test_data[0], test_data[1])}') acc_temp = bvsbc.score(test_data[0], test_data[1]) #记录每次的精度 acc_rem.append(acc_temp) #将每次的精度存入列表 for i in acc_rem: print(f'{i*100:0.2f}', ) #打印每次精度 acc_mean = np.mean(acc_rem) #求出平均精度 print("{:.2f}".format(acc_mean * 100)) #打印平均精度 print('---------------------以上为OSELM-BVSB-KNN(10次)算法----------------------' ) #运行程序
from elm import BvsbClassifier, BvsbUtils from sklearn import datasets from elm import elmUtils from sklearn.preprocessing import StandardScaler import time print("---------OSELM-BVSB-----------") data = elmUtils.readDataFileToData("data/zoo.data", targetIndex=0) print(f'数据集大小问{data.target.size}') data.data = StandardScaler().fit_transform(data.data) (train, iter, test) = elmUtils.splitDataWithIter(data.data, data.target, 0.05, 0.3) print(f'训练集大小为{train[1].size}') print(f'迭代训练集大小为{iter[1].size}') print(f'测试集大小为{test[1].size}') tic = time.perf_counter_ns() bvsbc = BvsbClassifier(train[0], train[1], iter[0], iter[1], test[0], test[1], iterNum=0.1) bvsbc.createOSELM(n_hidden=1000) bvsbc.trainOSELMWithoutKNN() toc = time.perf_counter_ns() print(f'OSELM-BVSB-KNN 正确率为{bvsbc.score(test[0], test[1])}') print(f'OSELM-BVSB-KNN 项目用时:{(toc - tic) / 1000 / 1000} ms')