반응형
Notice
Recent Posts
Recent Comments
Link
관리 메뉴

bro's coding

sklearn.decomposition.PCA.picture.recover 본문

[AI]/python.sklearn

sklearn.decomposition.PCA.picture.recover

givemebro 2020. 4. 22. 11:35
반응형

https://broscoding.tistory.com/175

 

sklearn.datasets.fetch_lfw_people

people=fetch_lfw_people(min_faces_per_person=20,resize=0.7) dir(people) people.target_names array(['Alejandro Toledo', 'Alvaro Uribe', 'Amelie Mauresmo', 'Andre Agassi', 'Angelina Jolie', 'Ariel Sha..

broscoding.tistory.com

from sklearn.decomposition import PCA
pca=PCA(100)
pca.fit(X_people)
X_pca=pca.transform(X_people)
pca_com=pca.components_[0]

 

 

plt.figure(figsize=[15,15])

for i in range(25):
    pca_com=pca.components_[i]
    plt.subplot(5,5,i+1)
    plt.imshow(pca_com.reshape(87,-1),cmap='gray')

 

# 얼굴 재구성
X_recover=X_pca@pca.components_ # 변환한 값 @ 
X_recover

 

fig=plt.figure(figsize=[10,4])
for i in range(5):
    plt.subplot(2,5,i+1)
    plt.imshow(X_people[i].reshape(87,65),cmap='gray')
    plt.axis('off')
    plt.subplot(2,5,i+6)
    plt.imshow(X_recover[i].reshape(87,-1),cmap='gray')
    plt.axis('off')

 

반응형
Comments