m=m, n=n) print(eigenfaceModel) y_predict = zeros(len(y_test)) for i, X_i in enumerate(X_test): y_predict[i] = eigenfaceModel.noFitTest(X_i, 1) from sklearn.metrics import classification_report print( classification_report(y_test, y_predict, target_names=faces95_own_classes)) if doPlot: plotConfusionMatrix(y_test, y_predict, labels=faces95_own_classes) # ---------------------- OTHER ALGORITHMS ----------------------------- from sklearn.neural_network import MLPClassifier X_train_pca = eigenfaceModel.exportTrainPca() X_test_pca = [] for X_i in X_test: X_test_pca.append(eigenfaceModel.projectOntoFacespace(X_i)) X_test_pca = array(X_test_pca) # train a neural network print("Fitting the classifier to the training set") clf = MLPClassifier(hidden_layer_sizes=( 1024,
w_predict = zeros(len(y_test)) # Array to fill with predictions epsilons = zeros(len(y_test)) for i, X_i in enumerate(X_test): y_pred_i, min_err_i = eigenfaceModel._noFitTest(X_i) epsilons[i] = min_err_i # Method 1: Fixed threshold = 2000 (number deducted from the plots in EDA submodule) w_predict[epsilons <= 250] = 1 print( classification_report(w_true, w_predict, target_names=['Known', 'Unknown'])) plotConfusionMatrix(w_true, w_predict, labels=['Known', 'Unknown']) # Method 2: Threshold calculated as mean + 2sd from the test1 split taken from the known dataset sub_eps = epsilons[:len(y_test1)] threshold = np.mean(sub_eps) + 2 * np.std( sub_eps, ddof=1, dtype=np.float64) w_predict2 = zeros(len(y_test)) w_predict2[epsilons <= threshold] = 1 print( classification_report(w_true, w_predict2, target_names=['Known', 'Unknown'])) plotConfusionMatrix(w_true, w_predict2, labels=['Known', 'Unknown']) # Method 3: Threshold calculated as mean + 3*sd from the test1 split taken from the known dataset sub_eps = epsilons[:len(y_test1)]
#X_test = X_test[y_test < output100_all_classes.index('io')] #y_test = y_test[y_test < output100_all_classes.index('io')] eigenfaceModel = EigenfaceModel(X_train, y_train, nmin=2, nmax=150) print(eigenfaceModel) y_predict2 = zeros(len(y_test)) for i, X_i in enumerate(X_test): y_predict2[i] = eigenfaceModel.noFitTest(X_i, 1) from sklearn.metrics import classification_report import matplotlib.pyplot as plt print(classification_report(y_test, y_predict2, target_names=labels)) plotConfusionMatrix(y_test, y_predict2, labels=labels) # ---------------------- ANGLE ---------------------------------------- y_predict = zeros(len(y_test)) for i, X_i in enumerate(X_test): y_predict[i] = eigenfaceModel.angleTest(X_i, 1) from sklearn.metrics import classification_report import matplotlib.pyplot as plt print(classification_report(y_test, y_predict, target_names=labels)) plotConfusionMatrix(y_test, y_predict, labels=labels) # ---------------------- OTHER ALGORITHMS -----------------------------
eigenfaceModel = EigenfaceModel(X_train, y_train, nmin=2, nmax=150) print(eigenfaceModel) y_predict = zeros(len(y_test)) for i, X_i in enumerate(X_test): y_predict[i] = eigenfaceModel.noFitTest(X_i, 1) from sklearn.metrics import classification_report import matplotlib.pyplot as plt print( classification_report(y_test, y_predict, target_names=output100strict_classes)) plotConfusionMatrix(y_test, y_predict, labels=output100strict_classes) # ---------------------- ANGLE ---------------------------------------- y_predict = zeros(len(y_test)) for i, X_i in enumerate(X_test): y_predict[i] = eigenfaceModel.angleTest(X_i, 1) from sklearn.metrics import classification_report import matplotlib.pyplot as plt print( classification_report(y_test, y_predict, target_names=output100strict_classes))