SVC分类后为什么结果只有一个

我想对比PCA降维前后模型拟合时间和得分,结果不进行降维运算后分类的结果只有一个,不知道是哪里出了问题,还是确实只能得到一个结果。(想象中应该是将test集图片分类成各个人的,但是结果出来以后都是小布什)

               precision    recall  f1-score   support

 Ariel Sharon       0.00      0.00      0.00        13
 Colin Powell       0.00      0.00      0.00        60
 Donald Rumsfeld    0.00      0.00      0.00        27
George W Bush       0.45      1.00      0.62       146
Gerhard Schroeder   0.00      0.00      0.00        25
  Hugo Chavez       0.00      0.00      0.00        15
   Tony Blair       0.00      0.00      0.00        36

     accuracy                           0.45       322
    macro avg       0.06      0.14      0.09       322
 weighted avg       0.21      0.45      0.28       322

[[ 0 0 0 13 0 0 0]
[ 0 0 0 60 0 0 0]
[ 0 0 0 27 0 0 0]
[ 0 0 0 146 0 0 0]
[ 0 0 0 25 0 0 0]
[ 0 0 0 15 0 0 0]
[ 0 0 0 36 0 0 0]]

from time import time
import matplotlib.pyplot as plt

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

lfw_people = fetch_lfw_people(min_faces_per_person=70, resize=0.4)
n_samples, h, w = lfw_people.images.shape
X = lfw_people.data
n_features = X.shape[1]
y = lfw_people.target
target_names = lfw_people.target_names
n_classes = target_names.shape[0]

X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.25, random_state=42)

t0 = time()
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.fit(X_train, y_train)
print("done in %0.3fs" % (time() - t0))

y_pred=clf.predict(X_test)

print(classification_report(y_test, y_pred, target_names=target_names))
print(confusion_matrix(y_test, y_pred, labels=range(n_classes)))
print(classification_report(y_test, y_pred, target_names=target_names))
print(confusion_matrix(y_test, y_pred, labels=range(n_classes)))

一共是7个人的图片是超过了70张,你打印一下这些人的图片数量:

target = pd.DataFrame(Y)
print(target.value_counts())

输出结果为:
3 530
1 236
6 144
2 121
4 109
0 77
5 71
dtype: int64
这说明这是一共数据分布不均匀的数据集,总样本数量为1288,用530/1288=0.41,你最终的accuracy为0.45,说明你的模型将所有的图片都划分为了George W Bush
或者是你看

img
只有George W Bush的召回率不等于0,且为1,而其余的均为0,这也说明了模型只是简单的将所有的图片都分为了数量最多的George W Bush
如果不进行降维的话,就是一个像素一个特征,就是50*37=1850,样本数才1288,特征数位1850,这是机器学习,不是深度学习啊,这里必须进行降维

你好,我是有问必答小助手,非常抱歉,本次您提出的有问必答问题,技术专家团超时未为您做出解答


本次提问扣除的有问必答次数,已经为您补发到账户,我们后续会持续优化,扩大我们的服务范围,为您带来更好地服务。