PCAで次元削減を行いたいのですが、どの事例を見てもmnistのようなモノクロ画像の例しかでてきませゆ。カラー画像のような(h,w,3)の画像をPCAに適用するにはどんな形にreshapeすれば良いのでしょうか?
python
1import cv2 2import scipy.misc 3import os 4import sys 5import matplotlib.pyplot as plt 6from sklearn.decomposition import PCA 7 8 9a_path='/Users/adidas' 10ad = [cv2.imread(a_path+'/'+i) for i in os.listdir(a_path)] 11 12ad_img=[cv2.resize(i,(150,150)) for i in ad if i is not None] 13# 次元削減ようにreshape 14ad=np.reshape(van_img, (12129,3,150*150)) 15 16# 次元削減実行 17pca = PCA(n_components=50,svd_solver='full') 18pca.fit(ad[1]) 19x = pca.fit_transform(img) 20print(x.shape) 21 22>>>(3, 3) 23 24 25 26pca.fit(ad[1]) 27>>>PCA(copy=True, iterated_power='auto', n_components=50, random_state=None, 28 svd_solver='full', tol=0.0, whiten=False)
回答2件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
2018/06/02 13:34
2018/06/02 16:49 編集
2018/06/03 00:25
2018/06/03 02:48
2018/06/03 07:30 編集
2018/06/03 07:51
2018/06/03 15:24 編集
2018/06/04 12:19