Notice
Recent Posts
Recent Comments
Link
관리 메뉴

Star_project

다차원척도법 본문

통계/다변량 분석

다차원척도법

star빛 2022. 6. 3. 11:52

https://stackabuse.com/guide-to-multidimensional-scaling-in-python-with-scikit-learn/

MDS는 저차원 공간에 데이터를 삽입하기 위한 비선형 기술입니다 .

고차원 공간에 있는 점을 저차원 공간에 매핑하면서 해당 점 사이의 거리를 최대한 유지합니다. 이 때문에 저차원 공간에서 점 사이의 쌍별 거리는 실제 거리와 거의 일치합니다.

Some of the important parameters for setting up the MDS
- n_components: 점을 매핑할 차원의 수입니다. 기본값은 2입니다.
- metricTrue: 메트릭 MDS 및 False비메트릭 버전에 대한 기본값이 있는 Boolean 변수입니다 .
- dissimilarity: 기본값은 euclidean유클리드 쌍별 거리를 지정하는 입니다. 다른 가능한 값은 precomputed입니다. 사용 precomputed하려면 쌍별 거리 행렬을 계산하고 이 행렬을 fit()또는 fit_transform()함수에 대한 입력으로 사용해야 합니다.

MDS개체 와 관련된 네 가지 속성 은 다음과 같습니다.
- embedding_: 새 공간의 포인트 위치.
- stress_: MDS에서 사용되는 적합도 통계량입니다.
- dissimilarity_matrix_: 쌍별 거리/비유사성의 행렬.
- n_iter_: 최상의 적합도 측도와 관련된 반복 횟수입니다.

 

from sklearn.manifold import MDS
from matplotlib import pyplot as plt
import sklearn.datasets as dt
import seaborn as sns         
import numpy as np
from sklearn.metrics.pairwise import manhattan_distances, euclidean_distances
from matplotlib.offsetbox import OffsetImage, AnnotationBbox

 

 

X = np.array([[0, 0, 0], [0, 0, 1], [1, 1, 1], [0, 1, 0], [0, 1, 1]])
mds = MDS(random_state=0)
X_transform = mds.fit_transform(X)
print(X_transform) # 차원의 좌표값 계산 2차원으로
[[ 0.72521687  0.52943352]
 [ 0.61640884 -0.48411805]
 [-0.9113603  -0.47905115]
 [-0.2190564   0.71505714]
 [-0.21120901 -0.28132146]]
stress = mds.stress_
print(stress)

## 0.18216844548575456
dist_manhattan = manhattan_distances(X)
mds = MDS(dissimilarity='precomputed', random_state=0)
# Get the embeddings
X_transform_L1 = mds.fit_transform(dist_manhattan)
colors = ['r', 'g', 'b', 'c', 'm']
size = [64, 64, 64, 64, 64]
fig = plt.figure(2, (10,4))
ax = fig.add_subplot(121, projection='3d')
plt.scatter(X[:,0], X[:,1], zs=X[:,2], s=size, c=colors)
plt.title('Original Points')

ax = fig.add_subplot(122)
plt.scatter(X_transform[:,0], X_transform[:,1], s=size, c=colors)
plt.title('Embedding in 2D')
fig.subplots_adjust(wspace=.4, hspace=0.5)
plt.show()

( 거리가 가까울 수록 동질적이다. 유사적이다. )
오른쪽의 플롯은 상대적인 거리를 일반적으로 그대로 유지합니다. 보라색, 녹색 및 파란색은 서로 가깝고 옥색 및 빨간색과 비교할 때 서로에 대한 상대적 위치는 거의 동일합니다.


 

'통계 > 다변량 분석' 카테고리의 다른 글

다중회귀분석 블로그 레퍼런스  (0) 2021.04.25