2017-02-13 11 views
2

의 결과지금은 (알렉시스의 Sarda - 노사 & 알렉시스의 Sarda ~을 작성자에게 감사) <code>dtwclust</code> 패키지를 사용하고 dtwclust

내가 쉽게 문제에 붙어 얻을하는 방법. 여기 내 코드가있다.

sc <- read.table("D:/handling data/confirm.csv", header=T, sep=",") 
rownames(sc) <- sc$STDR_YM_CD 
sc$STDR_YM_CD <- NULL 
sc <- t(sc) 
hc_sbd <- dtwclust(sc, type = 'h', k=3L, method = 'average', preproc = zscore, 
       distance = 'dtw', control = list(trace=TRUE)) 

plot([email protected]) 
plot(hc_sbd, type='sc') 
plot(hc_sbd, type='series', clus=2) 
plot(hc_sbd, type='centroids', clus=2) 

head(hc_sbd) 
write.xlsx(hc_sbd, "D:/handling data/tab1clustn.xlsx") 

나는이 그림을 얻었다. 그리고 클러스터 레이블로 데이터를 내보내고 싶습니다. 두 번째 그림처럼. enter image description here

enter image description here

는 여기에 내가 STDR_YM_CD 당신이 DTW와 클러스터 싶습니다 고유 식별자 가정 내 데이터 링크 http://blogattach.naver.com/e772fb415a6c6ddafd137d427d9ee7953f6e9146/20170207_141_blogfile/khm2963_1486442387926_THgZRt_csv/confirm.csv?type=attachment

+0

데이터를 공유 할 수 있습니까 –

+0

오케이. 하하 미안해. 늦었 어 –

+0

CSV 파일을 공유 할 수 있습니까? 또는'dput' 데이터? –

답변

2

입니다.

sc <- read.table("D:/handling data/confirm.csv", header=T, sep=",") 
df.labels <- sc$STDR_YM_CD #rownames(sc) <- sc$STDR_YM_CD 
sc$STDR_YM_CD <- NULL 
sc <- t(sc) 

hc_sbd <- dtwclust(sc, type = 'h', k=3L, method = 'average', preproc = zscore, 
      distance = 'dtw', control = list(trace=TRUE)) 

hc.clust <- data.frame(STDR_YM_CD = df.labels, dtwclust = [email protected]) 

sc <- merge(sc,hc.clust, by.x = "STDR_YM_CD", by.y = "STDR_YM_CD") 

난 그냥 당신이 클러스터하려고하는 변수는, 그때 나는 열 이름 dtwclust와 dtwclust 결과로부터 새로운 데이터 프레임을 생성, 라벨의 압축을 풉니 다. 우리 고유 레이블을 기반으로 다시 병합하는 것이 좋습니다. 이 작업을 수행하는 다른 방법도 있지만 이것은 하나의 옵션입니다. 나는 그것이 도움이되기를 바란다!

+0

감사합니다 ~ 정말 좋은 대답 ~~ 좋은 하루 되세요 ~~ 당신은 좋은 사람 ~~ –