微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

如何在连续的有意义的时段中对白天进行分组

如何解决如何在连续的有意义的时段中对白天进行分组

我有以下数据帧,其中包含每小时相应的需求。我想根据类似的需求以某种方式对这些时间进行分组但是间的分组必须连续才能有意义。例如,有意义的时间分组可以是 10-12 但不是(10-12、2、4-5)。

1970-01-01 08:00:00     9
1970-01-01 09:00:00    11
1970-01-01 10:00:00    28
1970-01-01 11:00:00    26
1970-01-01 12:00:00    26
1970-01-01 13:00:00    32
1970-01-01 14:00:00    24
1970-01-01 15:00:00    30
1970-01-01 16:00:00    23
1970-01-01 17:00:00    32
1970-01-01 18:00:00    27
1970-01-01 19:00:00    21
1970-01-01 20:00:00    16
1970-01-01 21:00:00    13
1970-01-01 22:00:00     1
1970-01-01 23:00:00     0

temp_data = df.values

ndata = [[td,td] for td in temp_data]
data = np.array(ndata)

# clustering
thresh = (15.0 / 100.0) * (
            max(temp_data) - min(temp_data))  # Threshold 15% of the total range of data

clusters = hcluster.fclusterdata(data,thresh,criterion="distance")

total_clusters = max(clusters)

clustered_index = []
for i in range(total_clusters):
    clustered_index.append([])

for i in range(len(clusters)):
    clustered_index[clusters[i] - 1].append(i)

clustered_range = []
for x in clustered_index:
    clustered_index_x = [temp_data[y] for y in x]
    clustered_range.append((min(clustered_index_x),max(clustered_index_x)))
print(clustered_range)

上面的代码(以及所有无监督的聚类算法)产生了一些聚类值范围,但它不知道小时必须是连续的;它只是对值进行聚类。关于如何解决此限制并同时强制执行连续的几个小时组的任何想法?

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。