km = TimeSeriesKMeans(n_clusters=3, verbose=True, random_state=seed)
y_pred = km.fit_predict(X_train)
plt.figure()
for yi inrange(3):
plt.subplot(1, 3, yi + 1)
for xx in X_train[y_pred == yi]:
plt.plot(xx.ravel(), "k-", alpha=.2)
plt.plot(km.cluster_centers_[yi].ravel(), "r-")
DTW로 유사성 계산
dba_km = TimeSeriesKMeans(n_clusters=3, n_init=2, metric="dtw", verbose=True,
max_iter_barycenter=10, random_state=seed)
y_pred = dba_km.fit_predict(X_train)
for yi inrange(3):
plt.subplot(1, 3, yi + 1)
for xx in X_train[y_pred == yi]:
plt.plot(xx.ravel(), "k-", alpha=.2)
plt.plot(dba_km.cluster_centers_[yi].ravel(), "r-")
Soft-DTW로 유사성 계산
sdtw_km = TimeSeriesKMeans(n_clusters=3, metric="softdtw",
metric_params={"gamma": .01},
verbose=True, random_state=seed)
y_pred = sdtw_km.fit_predict(X_train)
for yi inrange(3):
plt.subplot(1, 3, yi + 1)
for xx in X_train[y_pred == yi]:
plt.plot(xx.ravel(), "k-", alpha=.2)
plt.plot(sdtw_km.cluster_centers_[yi].ravel(), "r-")