def eigenSpace(matrix): sampleIndex = np.hstack( (np.arange(0, 50), np.arange(250, 300), np.arange(700, 750))) sam_matrix = matrix[sampleIndex, :] ## sam=np.zeros((3,50,30)) ## sam[0]=matrix[0:50:1,:] ## sam[1]=matrix[250:300:1,:] ## sam[2]=matrix[700:750:1,:] eva, eve = functions.pca(sam_matrix) indsort = np.argsort(-eva) indeve = np.array([0, 1, 2]) eveSelect = eve[:, indsort[indeve]] nmat = np.dot(sam_matrix, eveSelect) #pHist(nmat[50:100:1,2]) pEigenSpace_3d((nmat[0:50:1, :], nmat[50:100:1, :], nmat[100:150:1, :]), indeve + 1) pEigenSpace_1((nmat[0:50:1, :], nmat[50:100:1, :], nmat[100:150:1, :]), indeve + 1)
#we don't care for the appearances of mapping[id] = 'dc' all_features[column] = all_features[column].map(mapping) personal_data_encoding('bin', 3) personal_data_encoding('card_id', 10) encoded_feat = pd.get_dummies(all_features) #after the encoding too many columns are created #we use pca to reduce the features and identify the most discriminative ones #we have the best results for 500 components however it takes a lot of time #thus we have 100 for the script comp = 100 test_feature = functions.pca(encoded_feat, enc_label, comp) test_ff = pd.DataFrame(test_feature) rf = RandomForestClassifier() tp, fp, tn, fn, true_labels, probs = functions.cross_validation( rf, test_ff, enc_label, 10, 0.5) print('Random Forest True Positives %s' % sum(tp)) print('Random Forest False Positives %s' % sum(fp)) fScore, precision, recall = functions.metrics(tp, fp, tn, fn) print('Random Forest Fscore %s' % fScore) print('Random Forest Precision %s' % precision) print('Random Forest Recall %s' % recall) #ROC Curve
n1, n2, n3, n4, n5]) plt.style.use('dark_background') fig = plt.figure(figsize=(3,5)) for i in range(len(gray_arr)): plt.subplot(3, 5, i+1) plt.title(i) plt.imshow(gray_arr[i], cmap='gray', vmin=0, vmax=255) plt.xticks([]) plt.yticks([]) plt.show() """ Training """ y = [] for i in gray_arr: y.append(pca(i)[7]) """ Test Images """ # Dragon Queen Test dqt = grayscale_image('images/Dragon Queen Test.jpg') ydq = pca(dqt)[7] # Missandei test mit = grayscale_image('images/Missandei Test.jpg') ymi = pca(mit)[7] # Nichole test nt = grayscale_image('images/Nichole Test.jpg') yn = pca(nt)[7] # Group images
et = np.zeros((19, 1)) etr = np.zeros((19, 1)) acc = np.zeros((19, 1)) e1 = np.zeros((19, 1)) er1 = np.zeros((19, 1)) et1 = np.zeros((19, 1)) etr1 = np.zeros((19, 1)) acc1 = np.zeros((19, 1)) count = 0 for i in range(10, 200, 10): print(i) e[count], er[count], et[count], etr[count], acc[count] = fn.pca( d.trainvector, d.trainlabels, d.testvector, d.testlabels, nc=i, clf='Knn') e1[count], er1[count], et1[count], etr1[count], acc1[count] = fn.pca( d.trainvector, d.trainlabels, d.testvector, d.testlabels, nc=i, clf='NB') count += 1 print( etr1.ravel(),