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

bro's coding

sklearn.decomposition.PCA.basic 본문

[AI]/python.sklearn

sklearn.decomposition.PCA.basic

givemebro 2020. 4. 21. 15:03
반응형

PCA(Principal component analysis)

중요한 feature을 찾아내고 그것을 기준으로 축을 바꾼다.

 

from sklearn.datasets import load_iris
iris=load_iris()

 

from sklearn.decomposition import PCA

 

 

col1=0
col2=1
pca=PCA()
pca.fit(iris.data[:,[col1,col2]])

# 뱡향 백터
com=pca.components_
com

 

'''
array([[ 0.99693955, -0.07817635],
       [ 0.07817635,  0.99693955]])
'''

 

 

plt.scatter(iris.data[:,col1],iris.data[:,col2],c=iris.target)

# 바뀐 축
plt.plot([0,com[0,0]],[0,com[0,1]])
plt.plot([0,com[1,0]],[0,com[1,1]])

# 바뀐 값
x_pca=pca.transform(iris.data[:,[col1,col2]])
x_pca
'''
array([[-0.77592505,  0.38652395],
       [-0.93622478, -0.1275811 ],
       [-1.15124796,  0.05617154],
       [-1.24312428, -0.05134005],
       [-0.88343664,  0.47840027],
       [-0.50811373,  0.80875267],
       [-1.26657719,  0.24774182],
       [-0.86780137,  0.27901236],
       .
       .
       .
       [ 0.06071476, -0.04940474]])
       '''

https://broscoding.tistory.com/168

 

sklearn.cluster.PCA.visualization

https://broscoding.tistory.com/167 sklearn.cluster.PCA PCA(Principal component analysis) 중요한 feature을 찾아내고 그것을 기준으로 축을 바꾼다. from sklearn.datasets import load_iris iris=load_iris(..

broscoding.tistory.com

 

반응형
Comments