def mainDecisionTreeImplementation(decisiontreemodel, linPCA, training_dataframe, pca_option): df = pd.read_csv("BreastCancerData.csv") column_titles = None column_titles = processing.processData(df, column_titles) column_titles = np.array(column_titles) training_data = [] final_validation = [] processing.splitData(training_dataframe, .8, training_data, final_validation) training_data = np.array(training_data) final_validation = np.array(final_validation) features = [] labels = [] features, labels = processing.createFeatures_Labels(training_data) np.transpose(labels) features_data = None labels_data = None features_data, labels_data = processing.convertToDataFrame( features, labels, column_titles) if (pca_option == 'no'): # print('model without PCA') DT_STD_means.append( DecisionTree(features_data, labels_data, decisiontreemodel)) elif (pca_option == 'both'): DT_STD_means.append( DecisionTree(features_data, labels_data, decisiontreemodel)) features_data_PCA = processing.linearPCAReduction( features_data, linPCA) features_df_PCA = pd.DataFrame( features_data_PCA, columns=column_titles[1:(features_data_PCA.shape[1] + 1)]) # print('Decision Tree model with PCA') DT_PCA_means.append( DecisionTree(features_df_PCA, labels_data, decisiontreemodel)) else: features_data_PCA = processing.linearPCAReduction( features_data, linPCA) features_df_PCA = pd.DataFrame( features_data_PCA, columns=column_titles[1:(features_data_PCA.shape[1] + 1)]) # print('Decision Tree model with PCA') DT_PCA_means.append( DecisionTree(features_df_PCA, labels_data, decisiontreemodel))
def PolynomialSVMTest(pca_option): import SVM SVM.SVMSimulation(SVM.svm_poly, processing.linear_pca, processing.overall_training_data, pca_option) processing.final_validation = np.array(processing.final_validation) FV_features = [] FV_labels = [] FV_features, FV_labels = processing.createFeatures_Labels( processing.final_validation) FV_features_data = None FV_labels_data = None FV_features_data, FV_labels_data = processing.convertToDataFrame( FV_features, FV_labels, processing.column_titles) global SVM_POLY_final_predictions if(pca_option == 'yes' or pca_option == 'both'): transformed_FV = processing.linear_pca.transform(FV_features_data) final_predictions = SVM.svm_poly.predict(transformed_FV) SVM_GAUS_final_predictions = final_predictions accuracy = metrics.accuracy_score(final_predictions, FV_labels) precision = metrics.precision_score( FV_labels, final_predictions, average='micro') recall = metrics.recall_score( FV_labels, final_predictions, average='micro') print('POLYNOMIAL SVM MODEL FINAL TEST DATA ACCURACY: ', 100 * accuracy) print('POLYNOMIAL SVM MODEL FINAL TEST DATA PRECISION: ', 100 * precision) print('POLYNOMIAL SVM MODEL FINAL TEST DATA RECALL: ', 100 * recall) print() return accuracy, precision, recall else: final_predictions = SVM.svm_poly.predict(FV_features_data) SVM_GAUS_final_predictions = final_predictions accuracy = metrics.accuracy_score(final_predictions, FV_labels) precision = metrics.precision_score( FV_labels, final_predictions, average='micro') recall = metrics.recall_score( FV_labels, final_predictions, average='micro') print('POLYNOMIAL SVM MODEL FINAL TEST DATA ACCURACY: ', 100 * accuracy) print('POLYNOMIAL SVM MODEL FINAL TEST DATA PRECISION: ', 100 * precision) print('POLYNOMIAL SVM MODEL FINAL TEST DATA RECALL: ', 100 * recall) print() return accuracy, precision, recall
def NeuralNetworkTest(pca_option): import NN NN.NeuralNetworkSimulation( NN.nn, processing.linear_pca, processing.overall_training_data, pca_option) processing.final_validation = np.array(processing.final_validation) FV_features = [] FV_labels = [] FV_features, FV_labels = processing.createFeatures_Labels( processing.final_validation) FV_features_data = None FV_labels_data = None FV_features_data, FV_labels_data = processing.convertToDataFrame( FV_features, FV_labels, processing.column_titles) global NN_final_predictions if(pca_option == 'yes' or pca_option == 'both'): transformed_FV = processing.linear_pca.transform(FV_features_data) final_predictions = NN.nn.predict(transformed_FV) NN_final_predictions = final_predictions accuracy = metrics.accuracy_score(final_predictions, FV_labels) precision = metrics.precision_score( FV_labels, final_predictions, average='micro') recall = metrics.recall_score( FV_labels, final_predictions, average='micro') print('NEURAL NETWORK MODEL FINAL TEST DATA ACCURACY: ', 100 * accuracy) print('NEURAL NETWORK MODEL FINAL TEST DATA PRECISION: ', 100 * precision) print('NEURAL NETWORK MODEL FINAL TEST DATA RECALL: ', 100 * recall) print() return accuracy, precision, recall else: final_predictions = NN.nn.predict(FV_features_data) NN_final_predictions = final_predictions accuracy = metrics.accuracy_score(final_predictions, FV_labels) precision = metrics.precision_score( FV_labels, final_predictions, average='micro') recall = metrics.recall_score( FV_labels, final_predictions, average='micro') print('NEURAL NETWORK MODEL FINAL TEST DATA ACCURACY: ', 100 * accuracy) print('NEURAL NETWORK MODEL FINAL TEST DATA PRECISION: ', 100 * precision) print('NEURAL NETWORK MODEL FINAL TEST DATA RECALL: ', 100 * recall) print() return accuracy, precision, recall
def RandomForestTest(pca_option): import RF RF.RandomForestSimulation( RF.rf, processing.linear_pca, processing.overall_training_data, pca_option) processing.final_validation = np.array(processing.final_validation) FV_features = [] FV_labels = [] FV_features, FV_labels = processing.createFeatures_Labels( processing.final_validation) FV_features_data = None FV_labels_data = None FV_features_data, FV_labels_data = processing.convertToDataFrame( FV_features, FV_labels, processing.column_titles) global RF_final_predictions if(pca_option == 'yes' or pca_option == 'both'): transformed_FV = processing.linear_pca.transform(FV_features_data) final_predictions = RF.rf.predict(transformed_FV) RF_final_predictions = final_predictions accuracy = metrics.accuracy_score(final_predictions, FV_labels) precision = metrics.precision_score( FV_labels, final_predictions, average='micro') recall = metrics.recall_score( FV_labels, final_predictions, average='micro') print('RANDOM FOREST MODEL FINAL TEST DATA ACCURACY: ', 100 * accuracy) print('RANDOM FOREST MODEL FINAL TEST DATA PRECISION: ', 100 * precision) print('RANDOM FOREST MODEL FINAL TEST DATA RECALL: ', 100 * recall) print() return accuracy, precision, recall else: final_predictions = RF.rf.predict(FV_features_data) RF_final_predictions = final_predictions accuracy = metrics.accuracy_score(final_predictions, FV_labels) precision = metrics.precision_score( FV_labels, final_predictions, average='micro') recall = metrics.recall_score( FV_labels, final_predictions, average='micro') print('RANDOM FOREST MODEL FINAL TEST DATA ACCURACY: ', 100 * accuracy) print('RANDOM FOREST MODEL FINAL TEST DATA PRECISION: ', 100 * precision) print('RANDOM FOREST MODEL FINAL TEST DATA RECALL: ', 100 * recall) print() return accuracy, precision, recall
def mainNeuralNetworkImplementation(nnmodel, linPCA, training_dataframe, pca_option): df = pd.read_csv("BreastCancerData.csv") column_titles = None column_titles = processing.processData(df, column_titles) column_titles = np.array(column_titles) training_data = [] final_validation = [] processing.splitData(training_dataframe, .8, training_data, final_validation) training_data = np.array(training_data) final_validation = np.array(final_validation) features = [] labels = [] features, labels = processing.createFeatures_Labels(training_data) np.transpose(labels) features_data = None labels_data = None features_data, labels_data = processing.convertToDataFrame( features, labels, column_titles) if(pca_option == 'both'): #print('Random Forest model without PCA') NN_STD_means.append(NeuralNetwork( features_data, labels_data, nnmodel)) # print() features_data_PCA = processing.linearPCAReduction( features_data, linPCA) features_df_PCA = pd.DataFrame( features_data_PCA, columns=column_titles[1:(features_data_PCA.shape[1] + 1)]) #print('Random Forest model with PCA') NN_PCA_means.append(NeuralNetwork( features_df_PCA, labels_data, nnmodel)) elif(pca_option == 'yes'): features_data_PCA = processing.linearPCAReduction( features_data, linPCA) features_df_PCA = pd.DataFrame( features_data_PCA, columns=column_titles[1:(features_data_PCA.shape[1] + 1)]) #print('Random Forest model with PCA') NN_PCA_means.append(NeuralNetwork( features_df_PCA, labels_data, nnmodel)) else: NN_STD_means.append(NeuralNetwork( features_data, labels_data, nnmodel))