机器学习之PCA(降维算法)
程序员文章站
2022-07-13 08:51:41
...
PCA降维
// PCA
import numpy as np
import matplotlib.pyplot as plt
import scipy.io
from scipy.linalg import svd
image = plt.imread('leena.jpg')
print("image: ", image.shape)
plt.figure()
plt.imshow(image)
plt.show()
X = image
h, w, ch = X.shape
K = 90
Xrec = np.zeros((h, w, ch))
for rgb in range(ch):
U, S, V = scipy.linalg.svd(X[:, :, rgb])
P = V[:K, :].T
z = np.dot(X[:, :, rgb], P)
Xrec[:, :, rgb] = np.dot(z, P.T)
print(z)
print(Xrec)
plt.figure()
plt.imshow(Xrec.astype(np.int))
plt.show()
本文中数据集下载地址:
链接:https://pan.baidu.com/s/1io3aZH-QRCqnGardXOH5yg 提取码:83mu
学习讨论群请加QQ群:521364338,扫码进群领取人工智能学习资料,转载标明出处,侵权必究!
下一篇: 机器学习之PCA