The dataset used in this example is a preprocessed excerpt of the "Labeled Faces in the Wild", aka LFW_:
In [1]:
%matplotlib inline
from time import time
import logging
import matplotlib.pyplot as plt
import numpy as np
from sklearn.model_selection import train_test_split
from sklearn.model_selection import GridSearchCV
from sklearn.datasets import fetch_lfw_people
from sklearn.metrics import classification_report
from sklearn.metrics import confusion_matrix
from sklearn.decomposition import PCA
from sklearn.svm import SVC
from sklearn import manifold
from sklearn.decomposition import NMF
print(__doc__)
# Display progress logs on stdout
logging.basicConfig(level=logging.INFO, format='%(asctime)s %(message)s')
lfw_people = fetch_lfw_people(min_faces_per_person=70, resize=0.4)
# introspect the images arrays to find the shapes (for plotting)
n_samples, h, w = lfw_people.images.shape
# for machine learning we use the 2 data directly (as relative pixel
# positions info is ignored by this model)
X = lfw_people.data
n_features = X.shape[1]
# the label to predict is the id of the person
y = lfw_people.target
target_names = lfw_people.target_names
n_classes = target_names.shape[0]
print("Total dataset size:")
print("n_samples: %d" % n_samples)
print("n_features: %d" % n_features)
print("n_classes: %d" % n_classes)
# split into a training and testing set
X_train, X_test, y_train, y_test = train_test_split(
X, y, test_size=0.25, random_state=42)
2017-03-17 22:37:17,845 Loading LFW people faces from /home/chandu/scikit_learn_data/lfw_home
Automatically created module for IPython interactive environment
Total dataset size:
n_samples: 1288
n_features: 1850
n_classes: 7
In [3]:
n_comp_1 = np.arange(150,250,3)
accuracies = []
components = []
for i in xrange(len(n_comp_1)):
n_components = n_comp_1[i]
model = NMF(n_components=n_components, init='random', random_state=0)
nmf = model.fit(X_train)
X_train_nmf = nmf.transform(X_train)
X_test_nmf = nmf.transform(X_test)
param_grid = {'C': [1e3, 5e3, 1e4, 5e4, 1e5],
'gamma': [0.0001, 0.0005, 0.001, 0.005, 0.01, 0.1], }
clf = GridSearchCV(SVC(kernel='rbf', class_weight='balanced'), param_grid)
clf = clf.fit(X_train_nmf, y_train)
y_pred = clf.predict(X_test_nmf)
accuracies.append(float(np.sum(y_test==y_pred))/len(y_pred))
components.append(n_components)
print('For '+str(n_components)+' components, accuracy is '+str(float(np.sum(y_test==y_pred))/len(y_pred))+' confusion matrix is: ')
print(confusion_matrix(y_test, y_pred, labels=range(n_classes)))
print(classification_report(y_test, y_pred, target_names=target_names))
For 150 components, accuracy is 0.819875776398 confusion matrix is:
[[ 6 4 0 0 1 0 2]
[ 1 54 1 3 0 1 0]
[ 0 3 19 4 0 0 1]
[ 2 3 5 130 1 2 3]
[ 0 0 2 4 17 1 1]
[ 0 0 0 4 2 8 1]
[ 0 2 2 2 0 0 30]]
precision recall f1-score support
Ariel Sharon 0.67 0.46 0.55 13
Colin Powell 0.82 0.90 0.86 60
Donald Rumsfeld 0.66 0.70 0.68 27
George W Bush 0.88 0.89 0.89 146
Gerhard Schroeder 0.81 0.68 0.74 25
Hugo Chavez 0.67 0.53 0.59 15
Tony Blair 0.79 0.83 0.81 36
avg / total 0.82 0.82 0.82 322
For 153 components, accuracy is 0.791925465839 confusion matrix is:
[[ 5 6 0 2 0 0 0]
[ 1 48 2 5 0 2 2]
[ 1 1 20 4 0 0 1]
[ 2 3 6 126 3 3 3]
[ 0 0 0 4 17 1 3]
[ 0 0 0 2 1 11 1]
[ 1 2 1 1 1 2 28]]
precision recall f1-score support
Ariel Sharon 0.50 0.38 0.43 13
Colin Powell 0.80 0.80 0.80 60
Donald Rumsfeld 0.69 0.74 0.71 27
George W Bush 0.88 0.86 0.87 146
Gerhard Schroeder 0.77 0.68 0.72 25
Hugo Chavez 0.58 0.73 0.65 15
Tony Blair 0.74 0.78 0.76 36
avg / total 0.79 0.79 0.79 322
For 156 components, accuracy is 0.788819875776 confusion matrix is:
[[ 5 5 1 0 0 1 1]
[ 3 52 1 3 1 0 0]
[ 0 2 21 3 0 0 1]
[ 2 6 6 126 1 3 2]
[ 0 0 0 4 19 0 2]
[ 2 1 0 2 3 6 1]
[ 2 3 1 5 0 0 25]]
precision recall f1-score support
Ariel Sharon 0.36 0.38 0.37 13
Colin Powell 0.75 0.87 0.81 60
Donald Rumsfeld 0.70 0.78 0.74 27
George W Bush 0.88 0.86 0.87 146
Gerhard Schroeder 0.79 0.76 0.78 25
Hugo Chavez 0.60 0.40 0.48 15
Tony Blair 0.78 0.69 0.74 36
avg / total 0.79 0.79 0.79 322
For 159 components, accuracy is 0.782608695652 confusion matrix is:
[[ 6 5 0 0 0 1 1]
[ 3 48 3 3 2 0 1]
[ 0 2 19 5 0 0 1]
[ 0 6 7 126 1 3 3]
[ 1 0 0 4 18 0 2]
[ 1 1 0 2 2 8 1]
[ 0 2 2 4 0 1 27]]
precision recall f1-score support
Ariel Sharon 0.55 0.46 0.50 13
Colin Powell 0.75 0.80 0.77 60
Donald Rumsfeld 0.61 0.70 0.66 27
George W Bush 0.88 0.86 0.87 146
Gerhard Schroeder 0.78 0.72 0.75 25
Hugo Chavez 0.62 0.53 0.57 15
Tony Blair 0.75 0.75 0.75 36
avg / total 0.78 0.78 0.78 322
For 162 components, accuracy is 0.773291925466 confusion matrix is:
[[ 6 6 0 0 0 1 0]
[ 3 49 1 3 0 0 4]
[ 0 3 21 3 0 0 0]
[ 1 6 8 125 3 2 1]
[ 0 1 0 3 18 1 2]
[ 1 0 0 3 1 9 1]
[ 0 2 1 8 2 2 21]]
precision recall f1-score support
Ariel Sharon 0.55 0.46 0.50 13
Colin Powell 0.73 0.82 0.77 60
Donald Rumsfeld 0.68 0.78 0.72 27
George W Bush 0.86 0.86 0.86 146
Gerhard Schroeder 0.75 0.72 0.73 25
Hugo Chavez 0.60 0.60 0.60 15
Tony Blair 0.72 0.58 0.65 36
avg / total 0.77 0.77 0.77 322
For 165 components, accuracy is 0.757763975155 confusion matrix is:
[[ 5 5 1 1 0 0 1]
[ 2 48 2 5 1 0 2]
[ 0 2 20 3 1 0 1]
[ 2 6 6 122 5 2 3]
[ 1 0 1 5 15 0 3]
[ 1 0 0 5 0 8 1]
[ 0 3 2 4 0 1 26]]
precision recall f1-score support
Ariel Sharon 0.45 0.38 0.42 13
Colin Powell 0.75 0.80 0.77 60
Donald Rumsfeld 0.62 0.74 0.68 27
George W Bush 0.84 0.84 0.84 146
Gerhard Schroeder 0.68 0.60 0.64 25
Hugo Chavez 0.73 0.53 0.62 15
Tony Blair 0.70 0.72 0.71 36
avg / total 0.76 0.76 0.76 322
For 168 components, accuracy is 0.82298136646 confusion matrix is:
[[ 6 6 1 0 0 0 0]
[ 1 54 2 3 0 0 0]
[ 0 4 19 4 0 0 0]
[ 2 3 2 134 3 1 1]
[ 0 0 0 5 16 1 3]
[ 1 0 0 4 0 9 1]
[ 0 2 2 4 0 1 27]]
precision recall f1-score support
Ariel Sharon 0.60 0.46 0.52 13
Colin Powell 0.78 0.90 0.84 60
Donald Rumsfeld 0.73 0.70 0.72 27
George W Bush 0.87 0.92 0.89 146
Gerhard Schroeder 0.84 0.64 0.73 25
Hugo Chavez 0.75 0.60 0.67 15
Tony Blair 0.84 0.75 0.79 36
avg / total 0.82 0.82 0.82 322
For 171 components, accuracy is 0.826086956522 confusion matrix is:
[[ 6 4 2 0 0 1 0]
[ 1 52 0 2 3 0 2]
[ 0 2 22 3 0 0 0]
[ 0 4 3 136 1 1 1]
[ 0 0 3 6 15 0 1]
[ 1 1 0 5 0 8 0]
[ 2 2 2 3 0 0 27]]
precision recall f1-score support
Ariel Sharon 0.60 0.46 0.52 13
Colin Powell 0.80 0.87 0.83 60
Donald Rumsfeld 0.69 0.81 0.75 27
George W Bush 0.88 0.93 0.90 146
Gerhard Schroeder 0.79 0.60 0.68 25
Hugo Chavez 0.80 0.53 0.64 15
Tony Blair 0.87 0.75 0.81 36
avg / total 0.82 0.83 0.82 322
For 174 components, accuracy is 0.77950310559 confusion matrix is:
[[ 6 7 0 0 0 0 0]
[ 3 46 2 7 1 0 1]
[ 0 3 17 7 0 0 0]
[ 2 4 5 130 1 3 1]
[ 1 1 0 3 17 1 2]
[ 1 1 0 4 0 8 1]
[ 1 2 0 4 2 0 27]]
precision recall f1-score support
Ariel Sharon 0.43 0.46 0.44 13
Colin Powell 0.72 0.77 0.74 60
Donald Rumsfeld 0.71 0.63 0.67 27
George W Bush 0.84 0.89 0.86 146
Gerhard Schroeder 0.81 0.68 0.74 25
Hugo Chavez 0.67 0.53 0.59 15
Tony Blair 0.84 0.75 0.79 36
avg / total 0.78 0.78 0.78 322
For 177 components, accuracy is 0.770186335404 confusion matrix is:
[[ 7 6 0 0 0 0 0]
[ 2 49 0 3 4 0 2]
[ 0 4 17 6 0 0 0]
[ 2 5 3 129 3 3 1]
[ 1 1 0 3 15 3 2]
[ 1 1 0 5 1 7 0]
[ 0 4 2 2 3 1 24]]
precision recall f1-score support
Ariel Sharon 0.54 0.54 0.54 13
Colin Powell 0.70 0.82 0.75 60
Donald Rumsfeld 0.77 0.63 0.69 27
George W Bush 0.87 0.88 0.88 146
Gerhard Schroeder 0.58 0.60 0.59 25
Hugo Chavez 0.50 0.47 0.48 15
Tony Blair 0.83 0.67 0.74 36
avg / total 0.77 0.77 0.77 322
For 180 components, accuracy is 0.801242236025 confusion matrix is:
[[ 5 6 1 1 0 0 0]
[ 1 54 0 2 1 1 1]
[ 0 2 19 5 1 0 0]
[ 1 11 3 127 2 1 1]
[ 1 0 0 3 18 1 2]
[ 1 1 0 2 1 10 0]
[ 0 3 3 4 0 1 25]]
precision recall f1-score support
Ariel Sharon 0.56 0.38 0.45 13
Colin Powell 0.70 0.90 0.79 60
Donald Rumsfeld 0.73 0.70 0.72 27
George W Bush 0.88 0.87 0.88 146
Gerhard Schroeder 0.78 0.72 0.75 25
Hugo Chavez 0.71 0.67 0.69 15
Tony Blair 0.86 0.69 0.77 36
avg / total 0.80 0.80 0.80 322
For 183 components, accuracy is 0.785714285714 confusion matrix is:
[[ 6 6 0 0 0 0 1]
[ 2 51 3 3 1 0 0]
[ 0 6 18 2 1 0 0]
[ 2 6 5 128 4 1 0]
[ 1 1 0 3 16 0 4]
[ 1 0 0 4 1 8 1]
[ 2 2 4 1 1 0 26]]
precision recall f1-score support
Ariel Sharon 0.43 0.46 0.44 13
Colin Powell 0.71 0.85 0.77 60
Donald Rumsfeld 0.60 0.67 0.63 27
George W Bush 0.91 0.88 0.89 146
Gerhard Schroeder 0.67 0.64 0.65 25
Hugo Chavez 0.89 0.53 0.67 15
Tony Blair 0.81 0.72 0.76 36
avg / total 0.80 0.79 0.79 322
For 186 components, accuracy is 0.785714285714 confusion matrix is:
[[ 6 6 0 1 0 0 0]
[ 4 49 2 3 1 0 1]
[ 0 2 22 2 1 0 0]
[ 4 6 3 123 6 2 2]
[ 0 1 0 0 20 1 3]
[ 1 0 0 2 3 8 1]
[ 1 4 2 3 0 1 25]]
precision recall f1-score support
Ariel Sharon 0.38 0.46 0.41 13
Colin Powell 0.72 0.82 0.77 60
Donald Rumsfeld 0.76 0.81 0.79 27
George W Bush 0.92 0.84 0.88 146
Gerhard Schroeder 0.65 0.80 0.71 25
Hugo Chavez 0.67 0.53 0.59 15
Tony Blair 0.78 0.69 0.74 36
avg / total 0.80 0.79 0.79 322
For 189 components, accuracy is 0.785714285714 confusion matrix is:
[[ 5 5 1 1 0 0 1]
[ 2 49 4 5 0 0 0]
[ 0 3 19 4 1 0 0]
[ 1 3 6 128 4 3 1]
[ 1 0 0 4 19 1 0]
[ 1 0 0 5 0 8 1]
[ 0 3 1 5 2 0 25]]
precision recall f1-score support
Ariel Sharon 0.50 0.38 0.43 13
Colin Powell 0.78 0.82 0.80 60
Donald Rumsfeld 0.61 0.70 0.66 27
George W Bush 0.84 0.88 0.86 146
Gerhard Schroeder 0.73 0.76 0.75 25
Hugo Chavez 0.67 0.53 0.59 15
Tony Blair 0.89 0.69 0.78 36
avg / total 0.79 0.79 0.78 322
For 192 components, accuracy is 0.776397515528 confusion matrix is:
[[ 4 3 0 3 2 0 1]
[ 3 50 0 2 1 1 3]
[ 2 3 18 3 1 0 0]
[ 4 5 5 123 6 3 0]
[ 0 0 0 3 18 1 3]
[ 0 0 0 3 1 10 1]
[ 0 1 3 3 1 1 27]]
precision recall f1-score support
Ariel Sharon 0.31 0.31 0.31 13
Colin Powell 0.81 0.83 0.82 60
Donald Rumsfeld 0.69 0.67 0.68 27
George W Bush 0.88 0.84 0.86 146
Gerhard Schroeder 0.60 0.72 0.65 25
Hugo Chavez 0.62 0.67 0.65 15
Tony Blair 0.77 0.75 0.76 36
avg / total 0.78 0.78 0.78 322
For 195 components, accuracy is 0.785714285714 confusion matrix is:
[[ 5 3 2 1 0 0 2]
[ 5 48 0 5 0 0 2]
[ 1 1 19 5 1 0 0]
[ 3 4 3 130 2 2 2]
[ 0 0 0 7 15 0 3]
[ 0 1 0 3 0 10 1]
[ 0 2 1 5 0 2 26]]
precision recall f1-score support
Ariel Sharon 0.36 0.38 0.37 13
Colin Powell 0.81 0.80 0.81 60
Donald Rumsfeld 0.76 0.70 0.73 27
George W Bush 0.83 0.89 0.86 146
Gerhard Schroeder 0.83 0.60 0.70 25
Hugo Chavez 0.71 0.67 0.69 15
Tony Blair 0.72 0.72 0.72 36
avg / total 0.79 0.79 0.78 322
For 198 components, accuracy is 0.791925465839 confusion matrix is:
[[ 5 5 1 0 1 0 1]
[ 3 48 1 3 1 2 2]
[ 2 3 18 4 0 0 0]
[ 2 4 3 131 3 2 1]
[ 1 1 0 4 17 0 2]
[ 1 1 0 4 0 8 1]
[ 0 3 1 4 0 0 28]]
precision recall f1-score support
Ariel Sharon 0.36 0.38 0.37 13
Colin Powell 0.74 0.80 0.77 60
Donald Rumsfeld 0.75 0.67 0.71 27
George W Bush 0.87 0.90 0.89 146
Gerhard Schroeder 0.77 0.68 0.72 25
Hugo Chavez 0.67 0.53 0.59 15
Tony Blair 0.80 0.78 0.79 36
avg / total 0.79 0.79 0.79 322
For 201 components, accuracy is 0.801242236025 confusion matrix is:
[[ 5 5 1 1 0 0 1]
[ 3 51 1 3 0 1 1]
[ 1 2 21 3 0 0 0]
[ 1 3 6 127 4 1 4]
[ 1 0 2 2 17 1 2]
[ 0 0 0 4 1 9 1]
[ 1 1 1 3 2 0 28]]
precision recall f1-score support
Ariel Sharon 0.42 0.38 0.40 13
Colin Powell 0.82 0.85 0.84 60
Donald Rumsfeld 0.66 0.78 0.71 27
George W Bush 0.89 0.87 0.88 146
Gerhard Schroeder 0.71 0.68 0.69 25
Hugo Chavez 0.75 0.60 0.67 15
Tony Blair 0.76 0.78 0.77 36
avg / total 0.80 0.80 0.80 322
For 204 components, accuracy is 0.795031055901 confusion matrix is:
[[ 7 6 0 0 0 0 0]
[ 2 50 3 4 1 0 0]
[ 0 0 22 5 0 0 0]
[ 0 2 3 130 6 3 2]
[ 0 0 1 4 16 1 3]
[ 0 1 0 6 0 6 2]
[ 1 4 3 2 0 1 25]]
precision recall f1-score support
Ariel Sharon 0.70 0.54 0.61 13
Colin Powell 0.79 0.83 0.81 60
Donald Rumsfeld 0.69 0.81 0.75 27
George W Bush 0.86 0.89 0.88 146
Gerhard Schroeder 0.70 0.64 0.67 25
Hugo Chavez 0.55 0.40 0.46 15
Tony Blair 0.78 0.69 0.74 36
avg / total 0.79 0.80 0.79 322
For 207 components, accuracy is 0.795031055901 confusion matrix is:
[[ 3 6 1 2 0 0 1]
[ 2 48 3 4 0 1 2]
[ 0 5 18 4 0 0 0]
[ 0 3 4 131 3 5 0]
[ 0 0 0 1 19 3 2]
[ 2 0 0 2 2 8 1]
[ 0 1 1 5 0 0 29]]
precision recall f1-score support
Ariel Sharon 0.43 0.23 0.30 13
Colin Powell 0.76 0.80 0.78 60
Donald Rumsfeld 0.67 0.67 0.67 27
George W Bush 0.88 0.90 0.89 146
Gerhard Schroeder 0.79 0.76 0.78 25
Hugo Chavez 0.47 0.53 0.50 15
Tony Blair 0.83 0.81 0.82 36
avg / total 0.79 0.80 0.79 322
For 210 components, accuracy is 0.785714285714 confusion matrix is:
[[ 8 4 0 0 0 0 1]
[ 4 47 1 3 2 0 3]
[ 0 1 20 4 1 0 1]
[ 2 6 5 128 2 1 2]
[ 0 0 1 4 14 2 4]
[ 0 0 0 5 0 9 1]
[ 1 2 2 4 0 0 27]]
precision recall f1-score support
Ariel Sharon 0.53 0.62 0.57 13
Colin Powell 0.78 0.78 0.78 60
Donald Rumsfeld 0.69 0.74 0.71 27
George W Bush 0.86 0.88 0.87 146
Gerhard Schroeder 0.74 0.56 0.64 25
Hugo Chavez 0.75 0.60 0.67 15
Tony Blair 0.69 0.75 0.72 36
avg / total 0.79 0.79 0.78 322
For 213 components, accuracy is 0.826086956522 confusion matrix is:
[[ 6 7 0 0 0 0 0]
[ 2 50 1 5 0 1 1]
[ 0 1 20 6 0 0 0]
[ 2 1 5 135 1 1 1]
[ 0 1 1 2 19 1 1]
[ 1 0 0 3 1 8 2]
[ 0 1 1 4 0 2 28]]
precision recall f1-score support
Ariel Sharon 0.55 0.46 0.50 13
Colin Powell 0.82 0.83 0.83 60
Donald Rumsfeld 0.71 0.74 0.73 27
George W Bush 0.87 0.92 0.90 146
Gerhard Schroeder 0.90 0.76 0.83 25
Hugo Chavez 0.62 0.53 0.57 15
Tony Blair 0.85 0.78 0.81 36
avg / total 0.82 0.83 0.82 322
For 216 components, accuracy is 0.76397515528 confusion matrix is:
[[ 5 6 0 1 1 0 0]
[ 3 48 2 6 0 1 0]
[ 1 4 17 3 1 0 1]
[ 2 5 5 123 6 2 3]
[ 0 2 1 3 18 1 0]
[ 1 0 0 4 0 9 1]
[ 0 1 3 2 2 2 26]]
precision recall f1-score support
Ariel Sharon 0.42 0.38 0.40 13
Colin Powell 0.73 0.80 0.76 60
Donald Rumsfeld 0.61 0.63 0.62 27
George W Bush 0.87 0.84 0.85 146
Gerhard Schroeder 0.64 0.72 0.68 25
Hugo Chavez 0.60 0.60 0.60 15
Tony Blair 0.84 0.72 0.78 36
avg / total 0.77 0.76 0.76 322
For 219 components, accuracy is 0.829192546584 confusion matrix is:
[[ 6 5 1 0 1 0 0]
[ 3 49 2 5 1 0 0]
[ 0 4 21 2 0 0 0]
[ 2 2 2 134 2 2 2]
[ 0 0 0 2 17 4 2]
[ 0 0 0 3 1 11 0]
[ 0 3 0 4 0 0 29]]
precision recall f1-score support
Ariel Sharon 0.55 0.46 0.50 13
Colin Powell 0.78 0.82 0.80 60
Donald Rumsfeld 0.81 0.78 0.79 27
George W Bush 0.89 0.92 0.91 146
Gerhard Schroeder 0.77 0.68 0.72 25
Hugo Chavez 0.65 0.73 0.69 15
Tony Blair 0.88 0.81 0.84 36
avg / total 0.83 0.83 0.83 322
For 222 components, accuracy is 0.788819875776 confusion matrix is:
[[ 5 4 2 1 0 1 0]
[ 3 50 2 3 0 1 1]
[ 0 3 19 5 0 0 0]
[ 3 5 4 128 2 2 2]
[ 1 0 1 6 15 0 2]
[ 0 0 0 3 2 10 0]
[ 1 4 2 1 0 1 27]]
precision recall f1-score support
Ariel Sharon 0.38 0.38 0.38 13
Colin Powell 0.76 0.83 0.79 60
Donald Rumsfeld 0.63 0.70 0.67 27
George W Bush 0.87 0.88 0.87 146
Gerhard Schroeder 0.79 0.60 0.68 25
Hugo Chavez 0.67 0.67 0.67 15
Tony Blair 0.84 0.75 0.79 36
avg / total 0.79 0.79 0.79 322
For 225 components, accuracy is 0.776397515528 confusion matrix is:
[[ 4 6 1 0 0 1 1]
[ 3 48 2 4 0 0 3]
[ 0 3 20 2 0 0 2]
[ 3 5 5 127 2 1 3]
[ 1 1 0 3 17 0 3]
[ 1 0 0 6 0 7 1]
[ 0 2 2 5 0 0 27]]
precision recall f1-score support
Ariel Sharon 0.33 0.31 0.32 13
Colin Powell 0.74 0.80 0.77 60
Donald Rumsfeld 0.67 0.74 0.70 27
George W Bush 0.86 0.87 0.87 146
Gerhard Schroeder 0.89 0.68 0.77 25
Hugo Chavez 0.78 0.47 0.58 15
Tony Blair 0.68 0.75 0.71 36
avg / total 0.78 0.78 0.77 322
For 228 components, accuracy is 0.760869565217 confusion matrix is:
[[ 3 5 2 0 0 1 2]
[ 2 47 3 4 2 0 2]
[ 0 3 18 4 1 0 1]
[ 2 7 6 127 3 1 0]
[ 1 0 1 3 17 0 3]
[ 1 0 0 5 0 8 1]
[ 1 2 1 5 1 1 25]]
precision recall f1-score support
Ariel Sharon 0.30 0.23 0.26 13
Colin Powell 0.73 0.78 0.76 60
Donald Rumsfeld 0.58 0.67 0.62 27
George W Bush 0.86 0.87 0.86 146
Gerhard Schroeder 0.71 0.68 0.69 25
Hugo Chavez 0.73 0.53 0.62 15
Tony Blair 0.74 0.69 0.71 36
avg / total 0.76 0.76 0.76 322
For 231 components, accuracy is 0.77950310559 confusion matrix is:
[[ 4 6 1 0 1 1 0]
[ 2 48 0 5 1 1 3]
[ 0 3 18 6 0 0 0]
[ 2 5 3 130 2 3 1]
[ 2 0 0 5 15 1 2]
[ 1 0 0 4 0 10 0]
[ 0 2 1 5 2 0 26]]
precision recall f1-score support
Ariel Sharon 0.36 0.31 0.33 13
Colin Powell 0.75 0.80 0.77 60
Donald Rumsfeld 0.78 0.67 0.72 27
George W Bush 0.84 0.89 0.86 146
Gerhard Schroeder 0.71 0.60 0.65 25
Hugo Chavez 0.62 0.67 0.65 15
Tony Blair 0.81 0.72 0.76 36
avg / total 0.78 0.78 0.78 322
For 234 components, accuracy is 0.788819875776 confusion matrix is:
[[ 5 5 2 0 1 0 0]
[ 5 48 1 3 1 0 2]
[ 0 3 18 5 0 0 1]
[ 1 0 7 130 2 2 4]
[ 0 0 1 4 18 0 2]
[ 0 0 0 5 1 9 0]
[ 1 2 2 3 2 0 26]]
precision recall f1-score support
Ariel Sharon 0.42 0.38 0.40 13
Colin Powell 0.83 0.80 0.81 60
Donald Rumsfeld 0.58 0.67 0.62 27
George W Bush 0.87 0.89 0.88 146
Gerhard Schroeder 0.72 0.72 0.72 25
Hugo Chavez 0.82 0.60 0.69 15
Tony Blair 0.74 0.72 0.73 36
avg / total 0.79 0.79 0.79 322
For 237 components, accuracy is 0.810559006211 confusion matrix is:
[[ 8 4 0 1 0 0 0]
[ 0 54 1 2 1 0 2]
[ 0 3 16 7 0 0 1]
[ 2 6 6 125 5 1 1]
[ 0 0 0 3 20 1 1]
[ 1 0 0 3 0 10 1]
[ 1 0 2 3 2 0 28]]
precision recall f1-score support
Ariel Sharon 0.67 0.62 0.64 13
Colin Powell 0.81 0.90 0.85 60
Donald Rumsfeld 0.64 0.59 0.62 27
George W Bush 0.87 0.86 0.86 146
Gerhard Schroeder 0.71 0.80 0.75 25
Hugo Chavez 0.83 0.67 0.74 15
Tony Blair 0.82 0.78 0.80 36
avg / total 0.81 0.81 0.81 322
For 240 components, accuracy is 0.776397515528 confusion matrix is:
[[ 5 7 1 0 0 0 0]
[ 3 49 2 4 2 0 0]
[ 1 4 16 6 0 0 0]
[ 2 6 4 128 0 2 4]
[ 0 2 0 4 17 0 2]
[ 1 0 0 4 0 9 1]
[ 0 3 2 3 1 1 26]]
precision recall f1-score support
Ariel Sharon 0.42 0.38 0.40 13
Colin Powell 0.69 0.82 0.75 60
Donald Rumsfeld 0.64 0.59 0.62 27
George W Bush 0.86 0.88 0.87 146
Gerhard Schroeder 0.85 0.68 0.76 25
Hugo Chavez 0.75 0.60 0.67 15
Tony Blair 0.79 0.72 0.75 36
avg / total 0.78 0.78 0.77 322
For 243 components, accuracy is 0.782608695652 confusion matrix is:
[[ 5 4 2 1 0 0 1]
[ 1 50 2 2 2 0 3]
[ 0 4 19 4 0 0 0]
[ 2 9 2 126 1 4 2]
[ 1 0 0 5 17 0 2]
[ 0 1 0 5 1 8 0]
[ 0 6 0 2 1 0 27]]
precision recall f1-score support
Ariel Sharon 0.56 0.38 0.45 13
Colin Powell 0.68 0.83 0.75 60
Donald Rumsfeld 0.76 0.70 0.73 27
George W Bush 0.87 0.86 0.87 146
Gerhard Schroeder 0.77 0.68 0.72 25
Hugo Chavez 0.67 0.53 0.59 15
Tony Blair 0.77 0.75 0.76 36
avg / total 0.78 0.78 0.78 322
For 246 components, accuracy is 0.745341614907 confusion matrix is:
[[ 4 5 2 1 0 0 1]
[ 2 47 1 6 2 0 2]
[ 1 6 18 1 1 0 0]
[ 2 1 8 125 6 2 2]
[ 0 2 0 7 11 1 4]
[ 0 0 0 7 0 8 0]
[ 0 2 2 4 1 0 27]]
precision recall f1-score support
Ariel Sharon 0.44 0.31 0.36 13
Colin Powell 0.75 0.78 0.76 60
Donald Rumsfeld 0.58 0.67 0.62 27
George W Bush 0.83 0.86 0.84 146
Gerhard Schroeder 0.52 0.44 0.48 25
Hugo Chavez 0.73 0.53 0.62 15
Tony Blair 0.75 0.75 0.75 36
avg / total 0.74 0.75 0.74 322
For 249 components, accuracy is 0.785714285714 confusion matrix is:
[[ 7 3 1 2 0 0 0]
[ 1 47 0 4 3 2 3]
[ 1 3 20 3 0 0 0]
[ 2 5 6 123 4 3 3]
[ 1 1 0 4 16 0 3]
[ 0 0 0 2 1 12 0]
[ 1 3 0 2 1 1 28]]
precision recall f1-score support
Ariel Sharon 0.54 0.54 0.54 13
Colin Powell 0.76 0.78 0.77 60
Donald Rumsfeld 0.74 0.74 0.74 27
George W Bush 0.88 0.84 0.86 146
Gerhard Schroeder 0.64 0.64 0.64 25
Hugo Chavez 0.67 0.80 0.73 15
Tony Blair 0.76 0.78 0.77 36
avg / total 0.79 0.79 0.79 322
In [4]:
plt.plot(components,accuracies)
plt.title('Number of Components vs Accuracy')
plt.xlabel('Components')
plt.ylabel('Accuracy')
plt.show()
In [ ]:
Content source: srikarym/eigenfaces
Similar notebooks: