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]) # KNN bvsbc = BvsbClassifier(train_data[0], train_data[1], iter_data[0], iter_y, test_data[0], test_data[1], iterNum=0.1) bvsbc.createELM(n_hidden=1000, activation_func="tanh", alpha=1.0, random_state=0) bvsbc.X_test = test_data[0] bvsbc.Y_test = test_data[1] bvsbc.trainELMWithKNNButBvsb() print("+++++++++++++++++++") print(bvsbc.score(test_data[0], test_data[1])) acc_temp = bvsbc.score(test_data[0], test_data[1]) #记录每次的精度 acc_rem.append(acc_temp) #将每次的精度存入列表 print("*****************************************************") for i in acc_rem: print(f'{i*100:0.2f}', ) #打印每次精度 acc_mean = np.mean(acc_rem) #求出平均精度 print("**{:.2f}".format(acc_mean * 100)) #打印平均精度 print( '---------------------以上为ELM-KNN(本文)算法(10次)----------------------') #运行程序
data = datasets.load_digits() stdc = StandardScaler() # 均值归一化 label_size = 0.3 data.data = stdc.fit_transform(data.data / 16.0) train, iter, test = elmUtils.splitDataWithIter(data.data, data.target, label_size, 0.2) Y_iter = BvsbUtils.KNNClassifierResult(train[0], train[1], iter[0]) print(Y_iter.size) tic = time.perf_counter_ns() bvsbc = BvsbClassifier(train[0], train[1], iter[0], Y_iter, test[0], test[1], iterNum=0.1) bvsbc.createELM(n_hidden=1000, activation_func="sigmoid", alpha=1.0, random_state=0) bvsbc.X_test = test[0] bvsbc.Y_test = test[1] bvsbc.trainELMWithKNNButBvsb() toc = time.perf_counter_ns() print(bvsbc.score(test[0], test[1])) print("ELM-BVSB 项目用时:%d" % ((toc - tic) / 1000 / 1000))