PCA主成分分析+SVM实现人脸识别

原文地址:
http://ihoge.cn/2018/PCA+SVM人脸识别.html

加载数据

这里使用的测试数据共包含40位人员照片,每个人10张照片。也可登陆http://www.cl.cam.ac.uk/research/dtg/attarchive/facesataglance.html 查看400张照片的缩略图。

import time 
import logging
from sklearn.datasets import fetch_olivetti_faceslogging.basicConfig(level = logging.INFO, format="%(asctime)s %(message)s") # 这里INFO必须大写data_home = 'code/datasets/'
logging.info("开始加载数据")
faces = fetch_olivetti_faces(data_home=data_home)
logging.info("加载完成")

这里做下简单的解释:

加载的图片保存在faces变量里,sklaern已经把每张照片处理成剪切掉头发部分并且64x64大小且人脸居中显示。在真实生产环境中这一步很重要,否则模型将被大量的噪声干扰(即照片背景,变化的发型等,这些特征都应该排除在输入特征之外)。最后要成功下载数据集还需要安装Python图片图里工具Pillow否则无法对图片解码。下面输出下数据的概要信息:

import  numpy as npX = faces.data
y = faces.targettargets = np.unique(faces.target)
target_names = np.array(["p%d" % t for t in targets]) #给每个人做标签
n_targets = target_name.shape[0]
n_samples, h, w = faces.images.shapeprint('Samples count:{}\nTarget count:{}'.format(n_samples, n_targets))
print('Image size:{}x{}\nData shape:{}'.format(w, h, X.shape))
Samples count:400
Target count:40
Image size:64x64
Data shape:(400, 4096)

由输出可知,共有40人,照片总量400,输入特征(64x64=4096)个。

为了直观观察数据,从每个人物的照片里随机选择一张显示,定义下画图工具:

其中输入参数images是一个二维数据,每一行都是一个图片数据。在加载数据时,fech_ollivetti_faces()函数已经自动做了预处理,图片的每个像素的RBG值都转换成了[0,1]浮点数。因此,画出来的照片也是黑白的。子图片识别领域一般用黑白照片就可以了,减少计算量的同时也更加准确。

%matplotlib inline
from matplotlib import pyplot as plt
def plot_gallery(images, titles, h, w, n_row=2, n_col=5):
#     显示图片阵列:plt.figure(figsize=(2*n_col, 2.2*n_row),dpi=140)plt.subplots_adjust(bottom=0, left=.01, right=.99, top=.90, hspace=.01)for i in range(n_row * n_col):plt.subplot(n_row, n_col, i+1)plt.imshow(images[i].reshape((h,w)), cmap=plt.cm.gray)plt.title(titles[i])plt.axis('off')
n_row = 2
n_col = 6sample_images = None
sample_titles = []
for i in range(n_targets):people_images = X[y==i]  # 注意这里传入ipeople_sample_index = np.random.randint(0, people_images.shape[0], 1)people_sample_image = people_images[people_sample_index, :]if sample_images is not None:sample_images = np.concatenate((sample_images, people_sample_image), axis=0)else:sample_images =people_sample_imagesample_titles.append(target_names[i])   # 这里target_names是在前面生成的标签plot_gallery(sample_images, sample_titles, h, w, n_row, n_col)#代码中X[y=i]可以选择除特定的所有照片,随机选出来的照片放在sample.images数组对象里,最后调用之前定义的函数把照片画出来。

from sklearn.model_selection import train_test_splitX_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.2, random_state=4)

支持向量机第一次尝试

直接食用支持向量机来实现人脸识别:

from time import time
from sklearn.svm import SVCt = time()
clf = SVC(class_weight='balanced')
clf.fit(X_train, y_train)
print("耗时:{}秒".format(time() - t))
耗时:1.0220119953155518秒

1、接着对人脸数据进行预测:使用confusion_matrix查看准确性:

from sklearn.metrics import confusion_matrixy_pred = clf.predict(X_test)
cm = confusion_matrix(y_test, y_pred, labels=range(n_targets))
print("confusion_matrix:\n")
# np.set_printoptions(threshold=np.nan)
print(cm[:10])
confusion_matrix:[[0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0][0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 1 0 0 0 0 0][0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0][0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0][0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0][0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0][0 0 0 0 0 0 0 0 0 0 0 4 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0][0 0 0 0 0 0 0 0 0 0 0 2 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0][0 0 0 0 0 0 0 0 0 0 0 4 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0][0 0 0 0 0 0 0 0 0 0 0 2 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0]]

上面np.set_printoptions()是为了确保cm完整输出,这是因为这个数组是40x40的,默认情况下不会全部输出。??

2、使用classification_report查看准确性

但是很明显输出结果效果很差。 因为confusion_matrix理想的输出是矩阵的对角线上有数组,其他地方都为0,而且这里很多图片都被预测成索引为12的类别了。我买再来看下classification_report的结果:

from sklearn.metrics import classification_reportprint(classification_report(y_test, y_pred, target_names = target_names)) #这里y_test和y_pred不要颠倒。
             precision    recall  f1-score   supportp0       0.00      0.00      0.00         1p1       0.00      0.00      0.00         3p2       0.00      0.00      0.00         2p3       0.00      0.00      0.00         1p4       0.00      0.00      0.00         1p5       0.00      0.00      0.00         1p6       0.00      0.00      0.00         4p7       0.00      0.00      0.00         2p8       0.00      0.00      0.00         4p9       0.00      0.00      0.00         2p10       0.00      0.00      0.00         1p11       0.00      0.00      0.00         0p12       0.00      0.00      0.00         4p13       0.00      0.00      0.00         4p14       0.00      0.00      0.00         1p15       0.00      0.00      0.00         1p16       0.00      0.00      0.00         3p17       0.00      0.00      0.00         2p18       0.00      0.00      0.00         2p19       0.00      0.00      0.00         2p20       0.00      0.00      0.00         1p21       0.00      0.00      0.00         2p22       0.00      0.00      0.00         3p23       0.00      0.00      0.00         2p24       0.00      0.00      0.00         3p25       0.00      0.00      0.00         3p26       0.00      0.00      0.00         2p27       0.00      0.00      0.00         2p28       0.00      0.00      0.00         0p29       0.00      0.00      0.00         2p30       0.00      0.00      0.00         2p31       0.00      0.00      0.00         3p32       0.00      0.00      0.00         2p33       0.00      0.00      0.00         2p34       0.00      0.00      0.00         0p35       0.00      0.00      0.00         2p36       0.00      0.00      0.00         3p37       0.00      0.00      0.00         1p38       0.00      0.00      0.00         2p39       0.00      0.00      0.00         2avg / total       0.00      0.00      0.00        80/Users/hadoop/anaconda3/lib/python3.6/site-packages/sklearn/metrics/classification.py:1135: UndefinedMetricWarning: Precision and F-score are ill-defined and being set to 0.0 in labels with no predicted samples.'precision', 'predicted', average, warn_for)
/Users/hadoop/anaconda3/lib/python3.6/site-packages/sklearn/metrics/classification.py:1137: UndefinedMetricWarning: Recall and F-score are ill-defined and being set to 0.0 in labels with no true samples.'recall', 'true', average, warn_for)

结果不出预料,果然很差。

这是因为:这里把每个像素都作为一个输入特征来处理,这样那个数据噪声太严重了,模型根本没有办法对训练数据集进行拟合。这里有4096个特征向量,可是数据集大小才400个,比特征个数少了太多,而且分出20%作为测试集。这种情况下根本无法进行准确的训练和预测。

使用PCA来处理数据集

选择kk

解决上述问题的办法有两种,一个是加大数据样本量(在这里这个不太现实),或者使用PCA给数据降维,值选择前k个最重要的特征。

这里我们根据PCA算法来计算失真程度来确定k值。

在sklearn里,可以从PCA模型的explained_variance_ratio_变量里获取经PCA处理后的数据还原率。这是一个数组,所有元素求和即可知道选择的k值的数据还原率。随着kk的增大,数值会无限接近于1。

利用这一特征,可以让k取值10~300之间,每个30取一次样。针对这里的情况选择失真度小于5%即可。

from sklearn.decomposition import PCAprint("Exploring explained variance ratio for dataset ...")
candidate_components = range(10, 300, 30)
explained_ratios = []
t = time()
for c in candidate_components:pca = PCA(n_components=c)X_pca = pca.fit_transform(X)explained_ratios.append(np.sum(pca.explained_variance_ratio_))
print('Done in {0:.2f}s'.format(time()-t))
Exploring explained variance ratio for dataset ...
Done in 2.17s
plt.figure(figsize=(8, 5), dpi=100)
plt.grid()
plt.plot(candidate_components, explained_ratios)
plt.xlabel('Number of PCA Components')
plt.ylabel('Explained Variance Ratio')
plt.title('Explained variance ratio for PCA')
plt.yticks(np.arange(0.5, 1.05, .05))
plt.xticks(np.arange(0, 300, 20));

由上图可知,若要保留95%的数据还原率,kk值选择120即可。为了更直观的看不同k值的区别,这里画出来体验下:

def title_prefix(prefix, title):return "{}: {}".format(prefix, title)n_row = 1
n_col = 5sample_images = sample_images[0:5]
sample_titles = sample_titles[0:5]plotting_images = sample_images
plotting_titles = [title_prefix('orig', t) for t in sample_titles]
candidate_components = [120, 75, 37, 19, 8]
for c in candidate_components:print("Fitting and projecting on PCA(n_components={}) ...".format(c))t = time()pca = PCA(n_components=c)pca.fit(X)X_sample_pca = pca.transform(sample_images)X_sample_inv = pca.inverse_transform(X_sample_pca)plotting_images = np.concatenate((plotting_images, X_sample_inv), axis=0)sample_title_pca = [title_prefix('{}'.format(c), t) for t in sample_titles]plotting_titles = np.concatenate((plotting_titles, sample_title_pca), axis=0)print("Done in {0:.2f}s".format(time() - t))print("Plotting sample image with different number of PCA conpoments ...")
plot_gallery(plotting_images, plotting_titles, h, w,n_row * (len(candidate_components) + 1), n_col)
Fitting and projecting on PCA(n_components=120) ...
Done in 0.18s
Fitting and projecting on PCA(n_components=75) ...
Done in 0.14s
Fitting and projecting on PCA(n_components=37) ...
Done in 0.11s
Fitting and projecting on PCA(n_components=19) ...
Done in 0.07s
Fitting and projecting on PCA(n_components=8) ...
Done in 0.06s
Plotting sample image with different number of PCA conpoments ...

利用GridSearchCV选出最优参数

接下来选择k=120k=120作为PCA的参数对数据集和测试集进行特征提取,然后调用GridSearchCV选出最优参数

n_components = 120print("Fitting PCA by using training data ...")
t = time()
pca = PCA(n_components=n_components, svd_solver='randomized', whiten=True).fit(X_train)
print("Done in {0:.2f}s".format(time() - t))print("Projecting input data for PCA ...")
t = time()
X_train_pca = pca.transform(X_train)
X_test_pca = pca.transform(X_test)
print("Done in {0:.2f}s".format(time() - t))
Fitting PCA by using training data ...
Done in 0.16s
Projecting input data for PCA ...
Done in 0.01s
from sklearn.model_selection import GridSearchCVprint("Searching the best parameters for SVC ...")
param_grid = {'C': [1, 5, 10, 50],'gamma': [0.0001, 0.0005, 0.001, 0.005, 0.01]}
clf = GridSearchCV(SVC(kernel='rbf', class_weight='balanced'), param_grid, verbose=2, n_jobs=4)# 参数n_jobs=4表示启动4个进程
clf = clf.fit(X_train_pca, y_train)
print("Best parameters found by grid search:")
print(clf.best_params_)
Searching the best parameters for SVC ...
Fitting 3 folds for each of 20 candidates, totalling 60 fits
[CV] C=1, gamma=0.0001 ...............................................
[CV] C=1, gamma=0.0001 ...............................................
[CV] C=1, gamma=0.0001 ...............................................
[CV] C=1, gamma=0.0005 ...............................................
[CV] ................................ C=1, gamma=0.0001, total=   0.1s
[CV] C=1, gamma=0.0005 ...............................................
[CV] ................................ C=1, gamma=0.0001, total=   0.1s
[CV] C=1, gamma=0.0005 ...............................................
[CV] ................................ C=1, gamma=0.0001, total=   0.1s
[CV] C=1, gamma=0.001 ................................................
[CV] ................................ C=1, gamma=0.0005, total=   0.1s
[CV] C=1, gamma=0.001 ................................................
[CV] ................................ C=1, gamma=0.0005, total=   0.1s
[CV] C=1, gamma=0.001 ................................................
[CV] ................................ C=1, gamma=0.0005, total=   0.1s
[CV] C=1, gamma=0.01 .................................................
[CV] ................................. C=1, gamma=0.001, total=   0.1s
[CV] C=5, gamma=0.0001 ...............................................
[CV] ................................. C=1, gamma=0.001, total=   0.1s
[CV] C=5, gamma=0.0005 ...............................................
[CV] ................................. C=1, gamma=0.001, total=   0.1s
[CV] C=1, gamma=0.005 ................................................
[CV] .................................. C=1, gamma=0.01, total=   0.1s
[CV] C=1, gamma=0.01 .................................................
[CV] ................................ C=5, gamma=0.0001, total=   0.1s
[CV] C=5, gamma=0.0001 ...............................................
[CV] ................................ C=5, gamma=0.0005, total=   0.1s
[CV] C=5, gamma=0.001 ................................................
[CV] ................................. C=1, gamma=0.005, total=   0.1s
[CV] C=1, gamma=0.005 ................................................
[CV] .................................. C=1, gamma=0.01, total=   0.1s
[CV] C=1, gamma=0.01 .................................................
[CV] ................................ C=5, gamma=0.0001, total=   0.1s
[CV] C=5, gamma=0.0005 ...............................................
[CV] ................................. C=5, gamma=0.001, total=   0.1s
[CV] C=5, gamma=0.001 ................................................
[CV] ................................. C=1, gamma=0.005, total=   0.1s
[CV] C=1, gamma=0.005 ................................................
[CV] ................................ C=5, gamma=0.0005, total=   0.1s
[CV] C=5, gamma=0.0005 ...............................................
[CV] .................................. C=1, gamma=0.01, total=   0.1s
[CV] C=5, gamma=0.0001 ...............................................
[CV] ................................. C=5, gamma=0.001, total=   0.1s
[CV] C=5, gamma=0.001 ................................................
[CV] ................................. C=1, gamma=0.005, total=   0.1s
[CV] ................................ C=5, gamma=0.0005, total=   0.1s
[CV] C=5, gamma=0.005 ................................................
[CV] C=5, gamma=0.01 .................................................
[CV] ................................ C=5, gamma=0.0001, total=   0.1s
[CV] C=10, gamma=0.0001 ..............................................
[CV] ................................. C=5, gamma=0.001, total=   0.1s
[CV] C=10, gamma=0.001 ...............................................
[CV] ................................. C=5, gamma=0.005, total=   0.1s
[CV] C=5, gamma=0.005 ................................................
[CV] .................................. C=5, gamma=0.01, total=   0.1s
[CV] C=5, gamma=0.01 .................................................
[CV] ............................... C=10, gamma=0.0001, total=   0.1s
[CV] C=10, gamma=0.0005 ..............................................
[CV] ................................ C=10, gamma=0.001, total=   0.1s
[CV] C=10, gamma=0.001 ...............................................
[CV] ................................. C=5, gamma=0.005, total=   0.1s
[CV] C=5, gamma=0.005 ................................................
[CV] ............................... C=10, gamma=0.0005, total=   0.1s
[CV] C=10, gamma=0.0005 ..............................................
[CV] .................................. C=5, gamma=0.01, total=   0.1s
[CV] C=10, gamma=0.0001 ..............................................
[CV] ................................ C=10, gamma=0.001, total=   0.1s
[CV] C=10, gamma=0.001 ...............................................
[CV] ................................. C=5, gamma=0.005, total=   0.1s
[CV] C=5, gamma=0.01 .................................................
[CV] ............................... C=10, gamma=0.0001, total=   0.1s
[CV] C=10, gamma=0.0001 ..............................................
[CV] ............................... C=10, gamma=0.0005, total=   0.1s
[CV] C=10, gamma=0.0005 ..............................................
[CV] ................................ C=10, gamma=0.001, total=   0.1s
[CV] C=10, gamma=0.005 ...............................................
[CV] .................................. C=5, gamma=0.01, total=   0.1s
[CV] C=10, gamma=0.005 ...............................................
[CV] ............................... C=10, gamma=0.0001, total=   0.1s
[CV] C=10, gamma=0.01 ................................................
[CV] ............................... C=10, gamma=0.0005, total=   0.1s
[CV] C=50, gamma=0.0005 ..............................................
[CV] ................................ C=10, gamma=0.005, total=   0.1s
[CV] C=50, gamma=0.001 ...............................................
[CV] ................................ C=10, gamma=0.005, total=   0.1s
[CV] C=10, gamma=0.005 ...............................................
[CV] ................................. C=10, gamma=0.01, total=   0.1s
[CV] C=50, gamma=0.0001 ..............................................
[CV] ............................... C=50, gamma=0.0005, total=   0.1s
[CV] C=50, gamma=0.0005 ..............................................
[CV] ................................ C=50, gamma=0.001, total=   0.1s
[CV] C=50, gamma=0.001 ...............................................
[CV] ............................... C=50, gamma=0.0001, total=   0.1s
[CV] ................................ C=10, gamma=0.005, total=   0.1s
[CV] C=10, gamma=0.01 ................................................
[CV] ............................... C=50, gamma=0.0005, total=   0.1s
[CV] C=50, gamma=0.0001 ..............................................
[CV] C=50, gamma=0.0005 ..............................................
[CV] ................................ C=50, gamma=0.001, total=   0.1s
[CV] ................................. C=10, gamma=0.01, total=   0.1s
[CV] C=10, gamma=0.01 ................................................
[CV] C=50, gamma=0.005 ...............................................
[CV] ............................... C=50, gamma=0.0001, total=   0.1s
[CV] C=50, gamma=0.0001 ..............................................
[CV] ............................... C=50, gamma=0.0005, total=   0.1s
[CV] C=50, gamma=0.001 ...............................................
[CV] ................................. C=10, gamma=0.01, total=   0.1s
[CV] ................................ C=50, gamma=0.005, total=   0.1s
[CV] C=50, gamma=0.005 ...............................................
[CV] C=50, gamma=0.005 ...............................................
[CV] ............................... C=50, gamma=0.0001, total=   0.1s
[CV] ................................ C=50, gamma=0.001, total=   0.1s
[CV] ................................ C=50, gamma=0.005, total=   0.1s
[CV] ................................ C=50, gamma=0.005, total=   0.1s
[CV] C=50, gamma=0.01 ................................................
[CV] ................................. C=50, gamma=0.01, total=   0.0s
[CV] C=50, gamma=0.01 ................................................
[CV] ................................. C=50, gamma=0.01, total=   0.0s
[CV] C=50, gamma=0.01 ................................................
[CV] ................................. C=50, gamma=0.01, total=   0.0s
Best parameters found by grid search:
{'C': 10, 'gamma': 0.0005}[Parallel(n_jobs=4)]: Done  60 out of  60 | elapsed:    1.9s finished

测试模型准确性

接着使用这一模型对测试集进行预测,并分别使用confusion_matrixclassification_report查看其效果

t = time()
y_pred = clf.best_estimator_.predict(X_test_pca)
cm = confusion_matrix(y_test, y_pred, labels=range(n_targets))
print("Done in {0:.2f}.\n".format(time()-t))
print("confusion matrix:")
np.set_printoptions(threshold=np.nan)
print(cm[:10])
Done in 0.01.confusion matrix:
[[1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0][0 3 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0][0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0][0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0][0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0][0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0][0 0 0 0 0 0 3 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0][0 0 0 0 0 0 0 2 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0][0 0 0 0 0 0 0 0 4 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0][0 0 0 0 0 0 0 0 0 2 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0]]
from sklearn.metrics import classification_report
print(classification_report(y_test, y_pred, target_names=target_names)) #这里注意y_test和y_pred位置不要颠倒
             precision    recall  f1-score   supportp0       1.00      1.00      1.00         1p1       1.00      1.00      1.00         3p2       1.00      0.50      0.67         2p3       1.00      1.00      1.00         1p4       1.00      1.00      1.00         1p5       1.00      1.00      1.00         1p6       1.00      0.75      0.86         4p7       1.00      1.00      1.00         2p8       1.00      1.00      1.00         4p9       1.00      1.00      1.00         2p10       1.00      1.00      1.00         1p11       1.00      1.00      1.00         4p12       1.00      1.00      1.00         4p13       1.00      1.00      1.00         1p14       1.00      1.00      1.00         1p15       0.75      1.00      0.86         3p16       1.00      1.00      1.00         2p17       1.00      1.00      1.00         2p18       1.00      1.00      1.00         2p19       1.00      1.00      1.00         1p20       1.00      1.00      1.00         2p21       1.00      1.00      1.00         3p22       1.00      1.00      1.00         2p23       1.00      1.00      1.00         3p24       0.75      1.00      0.86         3p25       1.00      1.00      1.00         2p26       1.00      1.00      1.00         2p27       1.00      1.00      1.00         2p28       1.00      1.00      1.00         2p29       1.00      1.00      1.00         3p30       1.00      1.00      1.00         2p31       1.00      1.00      1.00         2p32       1.00      1.00      1.00         2p33       1.00      1.00      1.00         3p34       1.00      1.00      1.00         1p35       1.00      1.00      1.00         2p36       1.00      1.00      1.00         2avg / total       0.98      0.97      0.97        80/Users/hadoop/anaconda3/lib/python3.6/site-packages/sklearn/metrics/classification.py:1428: UserWarning: labels size, 37, does not match size of target_names, 40.format(len(labels), len(target_names))

疑问:

效果非常乐观,但是仍有个问题:怎么确定p0~p37分别对应的是哪个一个人?

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.mzph.cn/news/293056.shtml

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

龙芯发布.NET 6.0.100开发者内测版

龙芯在龙芯开源社区发布了LoongArch64-.NET-SDK-6.0.100开发者内测版的新闻 ,龙芯.NET基于上游社区 版本 适配支持龙芯平台架构。目前支持LoongArch64架构和MIPS64架构,LoongArch64架构的.NET-SDK-3.1已完成,安装包下载地址LoongArch64-.NET …

数据挖掘的9大成熟技术和应用

http://ihoge.cn/2018/DataMining.html 数据挖掘的9大成熟技术和应用 基于数据挖掘的9大主要成熟技术以及在数据化运营中的主要应用: 1、决策树 2、神经网络 3、回归 4、关联规则 5、聚类 6、贝叶斯分类 7、支持向量机 8、主成分分析 9、假设检验 1 决…

LVS:三种负载均衡方式与八种均衡算法

1、什么是LVS? 首先简单介绍一下LVS (Linux Virtual Server)到底是什么东西,其实它是一种集群(Cluster)技术,采用IP负载均衡技术和基于内容请求分发技术。调度器具有很好的吞吐率,将请求均衡地转移到不同的服务器上执行&#xff0…

排查 .NET开发的工厂MES系统 内存泄漏分析

一:背景 1. 讲故事上个月有位朋友加微信求助,说他的程序跑着跑着就内存爆掉了,寻求如何解决,截图如下:从聊天内容看,这位朋友压力还是蛮大的,话说这貌似是我分析的第三个 MES 系统了&#xff0c…

DataGirdView 常用操作

1、将数据源的某列添加到已有DataGirdView的列 例如:将文件夹下所有文件名添加到DataGirdView 的文件名一列,图片如下: 首先在datagridview把文件名列的DATAPROPERTYNAME设为你要显示的数据列的名字.此处我绑定的是folder.Name,所以直接在DAT…

Android之Android studio Gradle sync failed: Unknown host ‘services.gradle.org

错误描述: Gradle sync failed: Unknown host services.gradle.org. You may need to adjust the proxy settings in Gradle.Consult IDE log for more details (Help | Show Log)解决办法: 下载gradlectrlalts 然后输入gradle;在project-…

使用aconda3-5.1.0(Python3.6.4) 搭建pyspark远程部署

参考:http://ihoge.cn/2018/anacondaPyspark.html 前言 首次安装的环境搭配是这样的: jdk8 hadoop2.6.5 spark2.1 scala2.12.4 Anaconda3-5.1.0 一连串的报错让人惊喜无限,尽管反复调整配置始终无法解决。 坑了一整天后最后最终发现…

假如人类长出翅膀,会变成这种怪样子

鲁迅曾经说过:“不会画漫画的段子手不是好英语老师”咳咳~ 图图君就是这样一位专注知识科普的双语漫画家长按二维码带你去图图君家串串门儿想知道人类长出翅膀的怪样子吗?长按二维码关注回复“翅膀”寻找答案吧在这里你不仅可以大口呼吸知识还能顺便学个…

CSS3实战开发: 纯CSS实现图片过滤分类显示特效

CSS3实战开发: 纯CSS实现图片过滤分类显示特效 原文:CSS3实战开发: 纯CSS实现图片过滤分类显示特效各位网友大家好,今天我要带领大家开发一个纯CSS的图片分类显示的网址导航,单纯看标题大家可能有些困惑,依照以往惯例,我先给大家演…

C# WPF DataGrid获取单元格并改变背景色

01—概述WPF 自带了一个表格控件datagrid,这个控件类似winfrom中的datagridview,在数据显示的时候也经常会用到,这节主要讲解如何从后台代码获取到单元格控件并改变其相关属性:背景色、前景色、字体等。02—效果演示03—代码后台c…

PingingLab传世经典系列《CCNA完全配置宝典》-3.4 Trunk进阶配置

3.4 Trunk进阶配置实验目的:1、掌握Native vlan和Allow vlan的配置。2、理解Native vlan和Allow vlan的功能。实验拓扑:实验步骤:1、依据图中拓扑配置4台主机的IP地址,其中PC通过路由器模拟,配置如下:PC1(c…

python浮点数类型与数学_Python3标准库:decimal定点数和浮点数的数学运算

1. decimal定点数和浮点数的数学运算 decimal模块实现了定点和浮点算术运算,使用的是大多数人所熟悉的模型,而不是程序员熟悉的模式(即大多数计算机硬件实现的IEEE浮点数运算)。Decimal实例可以准确的表示如何数,对其上火其下取整&#xff0c…

业务功能中包含邮件发送,怎么测试?

前言网站开发中,经常碰到需要发送邮件的场景。比如,重置用户密码,需要执行下列流程:用户在重置页面输入邮箱地址进入邮箱,使用获得的重置链接打开重置页面输入新密码一般来说,重置链接都需要包含一个token值…

如何用CSS让一个容器水平垂直居中?

- 第一类&#xff08;被居中的元素有固定的宽高&#xff09; 效果&#xff1a; 第一种方法&#xff08;绝对定位 负margin&#xff09;<div class"div1"> <div class"div2"></div> </div><style type"text/css"&g…

和男朋友出去玩,该去哪里​?

1 当代熬夜人的脑回路&#xff08;素材来源网络&#xff0c;侵删&#xff09;▼2 确实需要找一下眼珠子&#xff08;via.剪怪不怪&#xff0c;侵删&#xff09;▼3 原来是老师想太多&#xff08;via.万事屋纸纸酱&#xff0c;侵删&#xff09;▼4 有一个会英语的妈妈&#x…

查询表结构的语句总结

四种方式&#xff1a;① DESC 表名② DESCRIBE 表名③ SHOW COLUMNS FROM 表名④ SHOW CREATE TABLE 表名从以上图片结果中可以看出&#xff1a;show columns 和 desc 和 describe 的结果是一样的&#xff0c;即&#xff1a;会将查询的表的每个字段的具体信息列出来,查询的行数…

ch340串口驱动_关于串口下载问题和超时

串口下载适用于mini、精英、战舰、探索者、阿波罗429不适用于阿波罗767&#xff0c;H743&#xff0c;号令者1052保证板子在独立供电状态下&#xff0c;电源灯处于亮灯状态下&#xff0c;USB线接板子上USB_232&#xff0c;RXD 和 PA9(STM32 的 TXD)TXD 和 PA10(STM32的 RXD)通过…

tcpdump抓取HTTP包

http://blog.csdn.net/kofandlizi/article/details/8106841 cpdump -XvvennSs 0 -i eth0 tcp[20:2]0x4745 or tcp[20:2]0x4854 0x4745 为"GET"前两个字母"GE" 0x4854 为"HTTP"前两个字母"HT" 说明&#xff1a; 通常情况下:一…