Python으로 배우는 이산 사건 시뮬레이션
Diogo Costa (PhD, MSc)
Adjunct Professor, University of Saskatchewan, Canada & CEO of ImpactBLUE-Scientific
히스토그램
Matplotlib 패키지
import matplotlib.pyplot as plt
사용: 데이터셋 data의 히스토그램(빈 50개) 생성
plt.hist(data, bins=50)


머신 러닝

이산 사건 모델에서
핵심
관측치와 클러스터 중심점

SciPy 메서드
scipy.cluster.vq.kmeans()
구현
import scipy
scipy.cluster.vq.kmeans(
obs, k_or_guess, iter=20, thresh=1e-05,
check_finite=True, *, seed=None)
obs는 numpy 배열k-means 전: 데이터 화이트닝
obs 데이터의 상관 제거obs 각 차원을 표준편차로 스케일 재조정
SciPy에서
scipy.cluster.vq.whiten(
obs, check_finite=True)
obs는 numpy 배열Process 1의 영향 살펴보기DNT_CURLY_TAG_2

패키지 임포트
import scipy.cluster.vq as scvq
화이트닝 수행
white_data = scvq.whiten(model_results)
클러스터 2개 찾기(파란 점)
cluster_centroids, distortion =
scvq.kmeans(white_data, 2)
기법
단순 방법
nobs = 관측치 개수num_clusters =
int((model_results.shape[0]/2)**0.5)
22
from sklearn.metrics import silhouette_score
k 클러스터 수에 대한 실루엣 점수 계산
for k in range(2, 6):
model = KMeans(n_clusters=k)
model.fit(model_results)
pred = model.predict(model_results)
score = silhouette_score(model_results, pred)
콘솔 출력
Silhouette Score for k = 2: 0.591
Silhouette Score for k = 3: 0.472
Silhouette Score for k = 4: 0.381
Silhouette Score for k = 5: 0.364
Silhouette Score for k = 6: 0.373
결과 해석
score = 1score = -1score가 0에 가까움Python으로 배우는 이산 사건 시뮬레이션