def main(): UsefulFunctions.warning() # Building Phase first_X, first_Y = UsefulFunctions.loadVehicleData() clf_first, first_training_score, first_training_data, first_testing_data, first_graph_data = analyze( first_X, first_Y) print( "Decision Tree Training Score (first) After Cross Validation: {0:.2f}%" .format(first_training_score * 100)) UsefulFunctions.calc_accuracy(first_training_data[1], clf_first.predict(first_training_data[0]), first_testing_data[1], clf_first.predict(first_testing_data[0])) second_X, second_Y = UsefulFunctions.loadWineData() clf_second, second_training_score, second_training_data, second_testing_data, second_graph_data = analyze( second_X, second_Y) print( "Decision Tree Training Score (second) After Cross Validation: {0:.2f}%" .format(second_training_score * 100)) UsefulFunctions.calc_accuracy(second_training_data[1], clf_second.predict(second_training_data[0]), second_testing_data[1], clf_second.predict(second_testing_data[0]))
def mainCurves(): UsefulFunctions.warning() first_X, first_Y = UsefulFunctions.loadVehicleData() first_graph_data = analyzePerNeighbor(first_X, first_Y) second_X, second_Y = UsefulFunctions.loadWineData() second_graph_data = analyzePerNeighbor(second_X, second_Y) graphDataCurves(first_graph_data, second_graph_data)
def main(): abaloneX, abaloneY = UsefulFunctions.loadVehicleData() clf_abalone, abalone_training_score, abalone_testing_data, abalone_graph_data, abalone_elapsed_time = analyze( abaloneX, abaloneY) print( "Neural Network Training Score (Abalone) After Cross Validation: {0}%". format(abalone_training_score * 100)) print("Neural Network Took (Abalone) {0}s to Train".format( abalone_elapsed_time)) start = time.time() results = clf_abalone.predict(abalone_testing_data[0]) end = time.time() - start print("Neural Network (Abalone) Took {0}s to Test".format(end)) print(confusion_matrix(abalone_testing_data[1], results)) print("Neural Testing Score for Abalone {0}%".format( cal_accuracy(abalone_testing_data[1], results) * 100)) wine_X, wine_Y = UsefulFunctions.loadWineData() clf_wine, wine_training_score, wine_testing_data, wine_graph_data, wine_elapsed_time = analyze( wine_X, wine_Y) print( "Neural Network Tree Training Score (Wine) After Cross Validation: {0}%" .format(wine_training_score * 100)) print("Neural Network Took (Wine) {0}s to Train".format(wine_elapsed_time)) start = time.time() results = clf_wine.predict(wine_testing_data[0]) end = time.time() - start print("Neural Network (Wine) Took {0}s to Test".format(end)) print(confusion_matrix(wine_testing_data[1], results)) print("Neural Testing Score for Wine {0}%".format( cal_accuracy(wine_testing_data[1], results) * 100)) fig = plt.figure(200) ax1 = plt.subplot(211) ax1.plot(abalone_graph_data[0], abalone_graph_data[1]) ax1.set_xlabel("Number of Epochs") ax1.set_ylabel("Cross Validated Accuracy Score") ax1.set_title("Score vs Number of Epochs for Vehicle Data") ax2 = plt.subplot(212) ax2.plot(wine_graph_data[0], wine_graph_data[1]) ax2.set_xlabel("Number of Epochs") ax2.set_ylabel("Cross Validated Accuracy Score") ax2.set_title("Score vs Number of Epochs for Wine Data") fig.tight_layout() plt.show()
def main(): title = "Learning Curves Vehicle (SVM)" abalone_X, abalone_Y = UsefulFunctions.loadVehicleData() abaloneX_train, abaloneX_test, abaloneY_train, abaloneY_test = train_test_split( abalone_X, abalone_Y, test_size=0.30, random_state=100) cv = StratifiedShuffleSplit(n_splits=10, test_size=0.1, random_state=42) # change the kernel here estimator = SVC(gamma=.001, C=1000.0, kernel='poly') plt, abalone_elapsed_time = plot_learning_curve(estimator, title, abaloneX_train, abaloneY_train, (0.1, 0.5), cv=cv, n_jobs=4) print("It took SVM (Abalone) {0}s to train".format(abalone_elapsed_time)) estimator.fit(abaloneX_train, abaloneY_train) t0 = time() y_pred = estimator.predict(abaloneX_test) print("SVM (Abalone) Took {0}s to test".format(time() - t0)) print("SVM Accuracy Score (Abalone) was {0}%".format( accuracy_score(abaloneY_test, y_pred) * 100)) plt.show() title = "Learning Curves Wine (SVM)" wine_X, wine_Y = UsefulFunctions.loadWineData() wineX_train, wineX_test, wineY_train, wineY_test = train_test_split( wine_X, wine_Y, test_size=0.30, random_state=100) cv = StratifiedShuffleSplit(n_splits=10, test_size=0.1, random_state=42) # change the kernel here estimator = SVC(gamma=.001, C=1000.0, kernel='rbf') plt, wine_elapsed_time = plot_learning_curve(estimator, title, wineX_train, wineY_train, (0.1, 1.01), cv=cv, n_jobs=4) print("It took SVM (Wine) {0}s to train".format(wine_elapsed_time)) estimator.fit(wineX_train, wineY_train) t0 = time() y_pred = estimator.predict(wineX_test) print("It took SVM (Wine) {0}s to test".format((time() - t0))) print("SVM Accuracy Score (Wine) was {0}%".format( accuracy_score(wineY_test, y_pred) * 100)) plt.show()