Repository navigation
Expand file tree
/
Copy pathML_Py_Lab05_PCA_class0517.py
More file actions
60 lines (46 loc) ยท 1.91 KB
/
Copy pathML_Py_Lab05_PCA_class0517.py
File metadata and controls
60 lines (46 loc) ยท 1.91 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
# -*- coding: utf-8 -*-
import numpy as np
import matplotlib.pyplot as plt
from sklearn.datasets import fetch_lfw_people # ์ฌ์ง ์ด๋ฏธ์ง ๋ฐ์ดํฐ ์
from sklearn.neighbors import KNeighborsClassifier # knn ๊ตฌํ ์๊ณ ๋ฆฌ์ฆ
from sklearn.model_selection import train_test_split # ๋ฐ์ดํฐ ์
๋๋๊ธฐ ํด๋์ค
import mglearn # ํ์ด์ฌ ๋จธ์ ๋ฌ๋ ์ฑ
์ฐ์ ๋ถ์ด ๋ง๋ ํจํค์ง
from sklearn.decomposition import PCA
### ํ๊ธ
import matplotlib
from matplotlib import font_manager, rc
font_loc = "C:/Windows/Fonts/malgunbd.ttf"
font_name = font_manager.FontProperties(fname=font_loc).get_name()
matplotlib.rc('font', family=font_name)
people = fetch_lfw_people(min_faces_per_person=20, resize=0.7)
people
image_shape = people.images[0].shape
# target, data, desc...
print(people.DESCR)
print(people.data.shape) # 3023๊ฐ.
print(people.target.shape) # target์ ๋ฐฐ์ด(3023)
print(people.target_names) # ์ฌ์ง ์ฌ๋์ด๋ฆ
print(people.images.shape) # ์ฌ์ง ์์ ์ ๋ณด
fig, axes = plt.subplots(3, 5, figsize=(15,8),
subplot_kw={'xticks':(), 'yticks':()})
a1 = people.target # ์ด๋ค ์ฌ๋์ ๊ฐ๋ฅดํค๋ ๋ฒํธ
a2 = people.images # ์ฌ์ง์ ์ด๋ฏธ์ง ์ ๋ณด
a3 = axes.ravel()
a3
# ==========================================
for target, image, ax in zip(a1, a2, a3):
ax.imshow(image)
ax.set_title(people.target_names[target])
# ๋ฐ์ดํฐ์ ํธ์ค์ ์์ ๊ธฐ ์ํด 50๊ฐ๋ง ์ ํํ๋ค.
mask = np.zeros(people.target.shape, dtype=np.bool)
mask
print(people.target.shape) #์ ์ฒด ๋ฐ์ดํฐ ํฌ๊ธฐ
print(mask)
print(np.unique(people.target)) # ๋์ค๋ ๊ฐ๋ค ์ค๋ณต ์ ์ธํ๊ณ ๋ฝ๊ธฐ
print(np.where(people.target==target)[0][:50])
# ==========================================
for target in np.unique(people.target):
mask[np.where(people.target==target)[0][:50]] = 1
mask
mask[mask==1,].shape
people.data[mask].shape