大家好,本文将围绕python大作业有哪些题目展开说明,python期末大作业项目是一个很多人都想弄明白的事情,想搞清楚python大作业设计报告需要先了解以下几个事情。
Source code download: 本文相关源码
《Python 程序设计》结业考核大作业
2020 年春季学期 大数据 2018 级
分类和预测要求如下:
- 利用算法实现人脸识别的功能,最后显示某人的预测名字与真实名字
- 数据集按照比例切分为训练集和测试集,报告中给出你的划分比例
- 评估预测模型的优劣:显示主要分类(必有) 指标 precision\recall\f1-score\support (其他指标可自行添加)
- 用可视化包或库(如, matplotlib )显示预测实验的结果,如图所示:
UTOOLS1590802589092.png
- 撰写总结报告, 包含代码基本注释、实验流程,简短总结。
代码注释
下载数据(如果尚未存储在磁盘上)并将其作为numpy数组加载
lfw_people = fetch_lfw_people(min_faces_per_person=70, resize=0.4)
获取图像数组形状属性(用于绘制)
n_samples, h, w = lfw_people.images.shape
对于机器学习,我们直接使用这2个数据(因为相对像素位置信息被该模型忽略 )
X = lfw_people.data
n_features = X.shape[1]
要预测的标签是该人对应的id
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=32)
计算人脸数据集(作为未标记数据集)上的PCA(特征脸):主成分分析PCA降维 保留150个成分
n_components = 150
pca = PCA(n_components=n_components, svd_solver='randomized',
whiten=True).fit(X_train)
降维后的特征脸
eigenfaces = pca.components_.reshape((n_components, h, w))
对划分后的训练集测试集进行相同处理
X_train_pca = pca.transform(X_train)
X_test_pca = pca.transform(X_test)
训练SVM分类模型、超参设定、定义调参器,并设置5折交叉验证 传入SVC
param_grid = {
'C': [1e3, 5e3, 1e4, 5e4, 1e5],
'gamma