import pandas as pd import confusion_mat as cfm from sklearn.model_selection import train_test_split from sklearn.metrics import classification_report import numpy as np import matplotlib.pyplot as plt from sklearn.neighbors import KNeighborsClassifier data = pd.read_pickle('Data_KNN.pkl') labels = pd.read_pickle('Labels_KNN.pkl') trainX, testX, trainY, testY = train_test_split(data, labels, test_size=.25, random_state=1) model = KNeighborsClassifier(n_neighbors=200) H = model.fit(trainX, trainY) # acc=model.score(testX,testY) # print("[INFO] raw pixel accuracy: {:.2f}%".format(acc * 100)) predictions = model.predict(testX) print(classification_report(testY, predictions)) np.set_printoptions(precision=1) classLabels = ['zero', 'one', 'two', 'three', 'four', 'five', 'six', 'seven', 'eight', 'nine'] # Plot non-normalized confusion matrix cfm.plot_confusion_matrix(testY, predictions, classes=classLabels) plt.show()
print "%s: %.3f" % (kernel, pred_lin) accur_lin.append(pred_lin) #Store accuracy in a list #print "training_labels", training_labels #print "prediction_labels", prediction_labels if i == 0: y_pred = clf.predict(prediction_data) y_test = prediction_labels # Compute confusion matrix class_names = emotions cnf_matrix = confusion_matrix(y_test, y_pred) np.set_printoptions(precision=2) print y_pred # Plot non-normalized confusion matrix plt.figure() plot_confusion_matrix(cnf_matrix, classes=class_names, title='Confusion matrix') plt.tight_layout() plt.savefig(kernel + '.png') #plt.show() print "Mean value %s svm: %.3f" % (kernel, np.mean(accur_lin) ) #Get mean accuracy of the 10 runs test_on = 'happy' output = [] # testing on external databases for i in range(0, 1): image = cv2.imread('test/' + test_on + '/test' + str(i) + '.png') gray = cv2.cvtColor(image, cv2.COLOR_BGR2GRAY) clahe_image = clahe.apply(gray)
x = np.vstack(x) y = [d['targets'] for d in test_data] y = np.hstack(y).T predicted = p.argmax(axis=1) label = y.argmax(axis=1) # combine into phenemse predicted, phoneme_list = combinePhonemes(predicted, statlist) label, _ = combinePhonemes(label, statlist) grouped_label = groupedList(label) grouped_predicted = groupedList(predicted) accuracy = editdistance.eval(grouped_label, grouped_predicted) / len(grouped_label) print('accuracy %0.2f%%' % accuracy) cm = get_confusion_matrix(predicted, label) # manually normalize sil_0 and sil_1 # cm[39, 39] = 0 # cm[40, 40] = 0 print('calculating accuracy') accuracy = 1 - np.count_nonzero(predicted - label) / predicted.shape[0] print(accuracy * 100, '%') cm[13,13] = 0 plot_confusion_matrix(cm, phoneme_list, title='Phoneme state confusion mat, no silence',save=True) # model = keras.models.load_model('h3_adagrad_relu_u256_e100.h5py') # print('predicting..') # p = model.predict(x) print('hello world')
NUM_STACK = 5 statlist = pickle.load(open('stateList.pkl', 'rb')) p = np.load('predicted_test.npy') train, validation = get_training_and_validation_sets( np.load('G:/train_data.npz')['data']) _, __, test_data = standardize_per_training_set( train, [], np.load('G:/test_data.npz')['data']) print('processing data for input') x = [lmfcc_stack(d['lmfcc'], NUM_STACK) for d in test_data] x = np.vstack(x) y = [d['targets'] for d in test_data] y = np.hstack(y).T predicted = p.argmax(axis=1) label = y.argmax(axis=1) cm = get_confusion_matrix(predicted, label) # manually normalize sil_0 and sil_1 cm[39, 39] = 0 cm[40, 40] = 0 plot_confusion_matrix(cm, statlist) # model = keras.models.load_model('h3_adagrad_relu_u256_e100.h5py') # print('predicting..') # p = model.predict(x) print('hello world')
verbose=1) model.save('E:/Code/htmljscss/model_32_ostu.hdf5') print('[INFO] evaluating network...') predictions = model.predict(testX, batch_size=128) print(classification_report(testY.argmax(axis=1), predictions.argmax(axis=1))) np.set_printoptions(precision=1) classLabels = [ 'zero', 'one', 'two', 'three', 'four', 'five', 'six', 'seven', 'eight', 'nine' ] # Plot non-normalized confusion matrix cfm.plot_confusion_matrix(testY.argmax(axis=1), predictions.argmax(axis=1), classes=classLabels) plt.show() plt.style.use('ggplot') plt.figure() plt.plot(np.arange(0, 10), H.history["accuracy"], label="train_acc") plt.plot(np.arange(0, 10), H.history['val_accuracy'], label='val_acc') plt.title('Training Accuracy') plt.xlabel('Epoch #') plt.ylabel('Accuracy') plt.legend() plt.show() plt.style.use('ggplot') plt.figure()