์ผ | ์ | ํ | ์ | ๋ชฉ | ๊ธ | ํ |
---|---|---|---|---|---|---|
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 |
- DBSCAN
- dataframe
- ๋์ํ๋ณธ
- Python
- ์ค๋ฒ์ํ๋ง
- ํ์ด์ฌ
- ์ฃผ์ฑ๋ถ๋ถ์
- ADP
- numpy
- ๋ฐ์ดํฐ๋ถ๊ท ํ
- opencv
- ๋ฐ์ดํฐ๋ถ์
- t-test
- ๋ ๋ฆฝํ๋ณธ
- ๋ฐ์ดํฐ๋ถ์์ ๋ฌธ๊ฐ
- ADsP
- ๊ตฐ์งํ
- ํ ์คํธ๋ถ์
- pandas
- iloc
- ํฌ๋กค๋ง
- PCA
- ์๋ํด๋ผ์ฐ๋
- LDA
- datascience
- ์ธ๋์ํ๋ง
- Lambda
- ๋ฐ์ดํฐ๋ถ์์ค์ ๋ฌธ๊ฐ
- ๋น ๋ฐ์ดํฐ๋ถ์๊ธฐ์ฌ
- ๋น ๋ฐ์ดํฐ
Data Science LAB
[Python] LDA(Linear Discriminant Analysis) ๋ณธ๋ฌธ
[Python] LDA(Linear Discriminant Analysis)
ใ ใ ใ ใ 2022. 3. 7. 21:45LDA ๊ฐ์
LDA๋ ์ ํ ํ๋ณ ๋ถ์๋ฒ์ผ๋ก, PCA์ ๋งค์ฐ ์ ์ฌํ๊ฒ ์ ๋ ฅ ๋ฐ์ดํฐ์ ์ ์ ์ฐจ์ ๊ณต๊ฐ์ ํฌ์ฌํด ์ฐจ์์ ์ถ์ํ๋ ๊ธฐ๋ฒ์ด๋ค. PCA์์ ์ฐจ์ด๋ LDA๋ ์ง๋ํ์ต์ ๋ถ๋ฅ์์ ์ฌ์ฉํ๊ธฐ ์ฝ๋๋ก ๊ฐ๋ณ ํด๋์ค๋ฅผ ๋ถ๋ณํ ์ ์๋ ๊ธฐ์ค์ ์ต๋ํ ์ ์งํ๋ฉด์ ์ฐจ์์ ์ถ์ํ๋ค. ๋ฐ๋ฉด PCA๋ ์ ๋ ฅ ๋ฐ์ดํฐ์ ๋ณ๋์ฑ์ ๊ฐ์ฅ ํฐ ์ถ์ ์ฐพ์์ง๋ง, LDA๋ ์ ๋ ฅ ๋ฐ์ดํฐ์ ๊ฒฐ์ ๊ฐ ํด๋์ค๋ฅผ ์ต๋ํ์ผ๋ก ๋ถ๋ฆฌํ ์ ์๋ ์ถ์ ์ฐพ๋๋ค.
#์ฐธ๊ณ
2022.03.05 - [Python] PCA(Principal Component Analysis)
[Python] PCA(Principal Component Analysis)
PCA ๊ฐ์ PCA(Principal Component Analysis)๋ ๊ฐ์ฅ ๋ํ์ ์ธ ์ฐจ์ ์ถ์ ๊ธฐ๋ฒ์ผ๋ก ์ฌ๋ฌ ๋ณ์ ๊ฐ์ ์กด์ฌํ๋ ์๊ด๊ด๊ณ๋ฅผ ์ด์ฉํด ์ด๋ฅผ ๋ํํ๋ ์ฃผ์ฑ๋ถ(Principal Component)๋ฅผ ์ถ์ถํด ์ฐจ์์ ์ถ์ํ๋ ๊ธฐ๋ฒ์ด๋ค.
suhye.tistory.com
LDA๋ ํน์ ๊ณต๊ฐ์์์ ํด๋์ค ๋ถ๋ฆฌ๋ฅผ ์ต๋ํํ๋ ์ถ์ ์ฐพ๊ธฐ ์ํด ํด๋์ค ๊ฐ ๋ถ์ฐ๊ณผ ํด๋์ค ๋ด๋ถ ๋ถ์ฐ์ ๋น์จ์ ์ต๋ํํ๋ ๋ฐฉ์์ผ๋ก ์ฐจ์์ ์ถ์ํ๋ค. ์ฆ, ํด๋์ค ๊ฐ ๋ถ์ฐ์ ์ต๋ํ ํฌ๊ฒ, ํด๋์ค ๋ด๋ถ ๋ถ์ฐ์ ์ต๋ํ ์๊ฒ ๊ฐ์ ธ๊ฐ๋ ๋ฐฉ์์ด๋ค.
1. ํด๋์ค ๋ด๋ถ์ ํด๋์ค ๊ฐ ๋ถ์ฐ ํ๋ ฌ์ ๊ตฌํ๋ค. ์ด ๋ ํ๋ ฌ์ ์ ๋ ฅ ๋ฐ์ดํฐ์ ๊ฒฐ์ ๊ฐ ํด๋์ค๋ณ๋ก ๊ฐ๋ณ ํผ์ฒ์ ํ๊ท ๋ฒกํฐ๋ฅผ ๊ธฐ๋ฐ์ผ๋ก ๊ตฌํ๋ค.
2. ํด๋์ค ๋ด๋ถ ๋ถ์ฐ ํ๋ ฌ์ ์๋ ๊ทธ๋ฆผ๊ณผ ๊ฐ์ด ๊ณ ์ ๋ฒกํฐ๋ก ๋ถํดํ๋ค.
3. ๊ณ ์ ๊ฐ์ด ํฐ ์์๋๋ก K(LDA ๋ณํ ์ฐจ์)๊ฐ๋งํผ ์ถ์ถํ๋ค.
4. ๊ณ ์ ๊ฐ์ด ๊ฐ์ฅ ํฐ ์์ผ๋ก ์ถ์ถ๋ ๊ณ ์ ๋ฒกํฐ๋ฅผ ์ด์ฉํ์ฌ ์๋กญ๊ฒ ์ ๋ ฅ๋ฐ์ดํฐ๋ฅผ ๋ณํํ๋ค.
iris ๋ฐ์ดํฐ์ ์ ์ ์ฉ
๋ฐ์ดํฐ์ ๋ก๋ ํ ์ค์ผ์ผ ์ ์ฉ
from sklearn.discriminant_analysis import LinearDiscriminantAnalysis
from sklearn.preprocessing import StandardScaler
from sklearn.datasets import load_iris
iris = load_iris()
iris_scaled = StandardScaler().fit_transform(iris.data)
LDA๋ PCA์๋ ๋ค๋ฅด๊ฒ ์ง๋ํ์ต์ด๋ค.
LDA ์ ์ฉ
lda = LinearDiscriminantAnalysis(n_components=2)
lda.fit(iris_scaled,iris.target)
iris_lda = lda.transform(iris_scaled)
print(iris_lda.shape)

n_components = 2๋ก ์ค์ ํ์ฌ LDA ์๊ณ ๋ฆฌ์ฆ์ ์ ์ฉํ์๋ค.
์๊ฐํ
import pandas as pd
import matplotlib.pyplot as plt
%matplotlib inline
lda_columns = ['lda_component_1','lda_component_2']
iris_df_lda = pd.DataFrame(iris_lda,columns = lda_columns)
iris_df_lda['target'] = iris.target
markers = ['^','s','o']
for i,marker in enumerate(markers):
x_axis_data = iris_df_lda[iris_df_lda['target'] == i]['lda_component_1']
y_axis_data = iris_df_lda[iris_df_lda['target'] == i]['lda_component_2']
plt.scatter(x_axis_data,y_axis_data,marker = marker,label = iris.target_names[i])
plt.legend(loc='upper right')
plt.xlabel('lda_component_1')
plt.ylabel('lda_component_2')
plt.show()

'๐ Machine Learning > ์ฐจ์ ์ถ์' ์นดํ ๊ณ ๋ฆฌ์ ๋ค๋ฅธ ๊ธ
[Python]NMF (0) | 2022.03.08 |
---|---|
[Python] SVD(Singular Value Decomposition) (0) | 2022.03.07 |
[Python] PCA ์์ (0) | 2022.03.06 |
[Python] PCA(Principal Component Analysis) (0) | 2022.03.05 |