【发布时间】:2021-07-21 19:56:52
【问题描述】:
我正在研究模糊时间序列,并试图建立一个模型来预测 TAIEX 时间序列。
时间序列图片:https://i.stack.imgur.com/04qkT.png
为了做到这一点,我想使用 DBSCAN 或 OPTICS 将这个时间序列聚类成“n”个聚类,这个数字将进一步用于构建模糊集。
Q1- DBSCAN 或 OPTICS 真的适合对时间序列进行聚类吗?
Q2- 我在使用 DBSCAN 时遇到问题。即使更改参数(eps 和 min_samples),该系列中的大多数点都被识别为异常值(黑点)。会发生什么?
我的代码:
'time_data is a numpy array containing the time series'
db = DBSCAN(eps=50, min_samples=100).fit(time_data)
core_samples_mask = np.zeros_like(db.labels_, dtype=bool)
core_samples_mask[db.core_sample_indices_] = True
labels = db.labels_
# Number of clusters in labels, ignoring noise if present.
n_clusters_ = len(set(labels)) - (1 if -1 in labels else 0)
n_noise_ = list(labels).count(-1)
print('Estimated number of clusters: %d' % n_clusters_)
print('Estimated number of noise points: %d' % n_noise_)
# Plot result
import matplotlib.pyplot as plt
# Black removed and is used for noise instead.
unique_labels = set(labels)
colors = [plt.cm.Spectral(each) for each in np.linspace(0, 1, len(unique_labels))]
for k, col in zip(unique_labels, colors):
if k == -1:
# Black used for noise.
col = [0, 0, 0, 1]
class_member_mask = (labels == k)
xy = dados[class_member_mask & core_samples_mask]
plt.plot(xy[:, 0], xy[:, 1], 'o', markerfacecolor=tuple(col),markeredgecolor='k', markersize=14)
xy = dados[class_member_mask & ~core_samples_mask]
plt.plot(xy[:, 0], xy[:, 1], 'o', markerfacecolor=tuple(col),markeredgecolor='k', markersize=6)
plt.title('Estimated number of clusters: %d' % n_clusters_)
plt.show()
感谢大家的宝贵时间!
【问题讨论】:
标签: python time cluster-analysis series dbscan