我正在使用模糊时间序列,并试图建立一个模型来预测台股时间序列。
时间序列图片:https://i.stack.imgur.com/04qkT.png
为了做到这一点,我想使用DBSCAN或光学将这个时间序列聚类到'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()感谢大家抽出时间来!
发布于 2021-04-29 01:23:40
也许你可以从查看集群的kmeans开始。虽然我不确定它是否适用于时间序列。
https://stackoverflow.com/questions/67300589
复制相似问题