def classifier(self): testFeature = np.zeros(20) testFeature[0] = int(self.ui.comboBox_10.currentIndex()) testFeature[1] = int(self.ui.spinBox.text()) testFeature[2] = int(self.ui.comboBox_12.currentIndex()) testFeature[3] = int(self.ui.comboBox_9.currentIndex()) testFeature[4] = int(self.ui.spinBox_2.text()) testFeature[5] = int(self.ui.comboBox_11.currentIndex()) testFeature[6] = int(self.ui.comboBox_5.currentIndex()) testFeature[7] = float(self.ui.doubleSpinBox.text()) testFeature[8] = int(self.ui.comboBox_2.currentIndex()) testFeature[9] = int(self.ui.comboBox_13.currentIndex()) testFeature[10] = int(self.ui.spinBox_3.text()) testFeature[11] = int(self.ui.comboBox_8.currentIndex()) testFeature[12] = int(self.ui.spinBox_4.text()) testFeature[13] = int(self.ui.comboBox_14.currentIndex()) testFeature[14] = int(self.ui.comboBox_7.currentIndex()) testFeature[15] = int(self.ui.spinBox_5.text()) testFeature[16] = int(self.ui.comboBox_4.currentIndex()) testFeature[17] = int(self.ui.spinBox_6.text()) testFeature[18] = int(self.ui.comboBox_3.currentIndex()) testFeature[19] = int(self.ui.comboBox_6.currentIndex()) filePath = self.ui.fileButton.text() trainFeature, trainLabel = read_GermanData20(filePath) predictedLabel = decision_Tree(trainFeature, trainLabel, testFeature) self.ui.textBrowser.setText(str(predictedLabel))
#print(np.array(negFeatureFolders).shape) for i in range(folderNum): subTrainFeature = negFeatureFolders[i] subTrainFeature.extend(posFeature) subTrainFeature = np.array(subTrainFeature) subTrainLabel = list(np.zeros(posNum)) subTrainLabel.extend(list(np.ones(posNum))) subTrainLabel = np.array(subTrainLabel) print("=====%dst Bagging=====") % (i + 1) print("Positive: %d, Negative: %d") % (list(subTrainLabel).count(1), list(subTrainLabel).count(0)) #print(subTrainFeature.shape) #print(subTrainLabel) predictedLabel_temp1 = knn(subTrainFeature, subTrainLabel, testFeature, 5) predictedLabel_temp2 = decision_Tree(subTrainFeature, subTrainLabel, testFeature) predictedLabel_temp3 = adboostDT(subTrainFeature, subTrainLabel, testFeature) predictedLabel_temp4 = RandomForest_Classifer(subTrainFeature, subTrainLabel, testFeature) predictedLabel_temp5 = svmclassifier(subTrainFeature, subTrainLabel, testFeature, 1.0, 0.015625) predictedLabel_temp6 = logistic_regression(subTrainFeature, subTrainLabel, testFeature) predictedLabel_voting1.append(predictedLabel_temp1) predictedLabel_voting2.append(predictedLabel_temp2) predictedLabel_voting3.append(predictedLabel_temp3) predictedLabel_voting4.append(predictedLabel_temp4) predictedLabel_voting5.append(predictedLabel_temp5)
random.shuffle(sequence) negFeatureFolders.append([negFeature[j] for j in sequence[:posNum]]) #print(np.array(negFeatureFolders).shape) for i in range(folderNum): subTrainFeature = negFeatureFolders[i] subTrainFeature.extend(posFeature) subTrainFeature = np.array(subTrainFeature) subTrainLabel = list(np.zeros(posNum)) subTrainLabel.extend(list(np.ones(posNum))) subTrainLabel = np.array(subTrainLabel) print("=====%dst Bagging=====") % (i+1) print("Positive: %d, Negative: %d") % (list(subTrainLabel).count(1), list(subTrainLabel).count(0)) #print(subTrainFeature.shape) #print(subTrainLabel) predictedLabel_temp1 = knn(subTrainFeature, subTrainLabel, testFeature, 5) predictedLabel_temp2 = decision_Tree(subTrainFeature, subTrainLabel, testFeature) predictedLabel_temp3 = adboostDT(subTrainFeature, subTrainLabel, testFeature) predictedLabel_temp4 = RandomForest_Classifer(subTrainFeature, subTrainLabel, testFeature) predictedLabel_temp5 = svmclassifier(subTrainFeature, subTrainLabel, testFeature, 1.0, 0.015625) predictedLabel_temp6 = logistic_regression(subTrainFeature, subTrainLabel, testFeature) predictedLabel_voting1.append(predictedLabel_temp1) predictedLabel_voting2.append(predictedLabel_temp2) predictedLabel_voting3.append(predictedLabel_temp3) predictedLabel_voting4.append(predictedLabel_temp4) predictedLabel_voting5.append(predictedLabel_temp5) predictedLabel_voting6.append(predictedLabel_temp6) print("KNN=====%dst predicted labels:") % (i+1) print(predictedLabel_temp1) print("DT=====%dst predicted labels:") % (i+1) print(predictedLabel_temp2)