资源简介
通过主成分分析对手写数字进行特征提取和降维
代码片段和文件信息
# -*- coding: utf-8 -*-
# @Time : 4/12/2020 12:20
# @Author : Eddie Shen
# @Email : sheneddie@outlook.com
# @File : HW5_2.py
# @Software: PyCharm
import matplotlib.pyplot as plt
import numpy as np
import numpy.linalg as la
path = ‘D:\\shene\\Documents\\SUFE\\3D\\Data_Mining\\Data\\zip.train‘
data = np.loadtxt(path)
# Choose number 9.
k = 9
data_k = data[data[: 0] == k 1:]
# Show the 6th handwriting number.
plt.figure()
plt.imshow(data_k[5 :].reshape(16 16) cmap=“gray_r“)
plt.show()
# Show the mean of data_k.
mu = np.mean(data_k axis=0)
plt.figure()
plt.imshow(mu.reshape(16 16) cmap=“gray_r“)
plt.show()
# Principal component analysis.
cov_x = np.cov(data_k rowvar=False)
u v = la.eig(cov_x)
# Show the first principal component.
plt.figure()
plt.imshow(v[: 0].reshape(16 16) cmap=“gray_r“)
plt.show()
# Choose handwriting numbers of the five biggest and five smallest scores.
xi1: np.ndarray = (data_k - mu) @ v[: 0:1]
ind
相关资源
- python一个打砖块的小游戏
- python实验指导书 图文高清版
- python主动安装第三方库
- python爬取豆瓣top250电影信息
- python绘制 大蟒蛇
- python小程序(数组排序)
- Python去水印(基于cv2)
- Python 数据结构入门 - 二叉搜索树(
- python空心电感计算器
- python除法.docx
- 抽奖背后的秘密(python抽奖逻辑)
- 绘制统计学直方图茎叶图(matplotlib)
- python求解标准差
- svm-simple.py(matplotlib)
- python数据分析与处理
- 利用Python将照片在Excel中利用点阵图显
- pygame贪吃蛇
- python turtle 跳房子
- python 人群计数
- 自动化测试(基于pytest)
- 基于树莓派的动态图像对比(py3_ob<
- Python调用第三方API换脸
- “去哪儿吃”帮你选餐厅(python代码
- python 控制台登陆密码验证
- KNN算法的Python实现(datingrecd.ipynb)
- python核心编程第二版-习题答案
- python爬取笔趣阁小说
- Python程序设计基础试题以及答案(3
- python聊天-服务端与客户端
- python递归求最大公约数
评论
共有 条评论