我在早上,下午和晚上都有38套公寓和电力消耗的数据集.我正在尝试使用scikit-learn的k-Means实现来聚类这个数据集,并且我得到了一些有趣的结果.
第一个聚类结果:

这一切都很好,有4个簇我显然得到4个标签与每个公寓相关联 - 0,1,2和3.使用方法的random_state参数KMeans,我可以修复质心随机初始化的种子,所以始终如一获得归属于同一公寓的相同标签.
然而,由于该特定情况是关于能量消耗,因此可以执行最高和最低消费者之间的可测量分类.因此,我希望将标签0分配给消费水平最低的公寓,将标签1分配给消耗更多的公寓,依此类推.
截至目前,我的标签是[2 1 3 0],或["黑色","绿色","蓝色","红色"]; 我希望他们是[0 1 2 3]或["红色","绿色","黑色","蓝色"].我应该如何继续这样做,同时仍然保持质心初始化随机(使用固定种子)?
非常感谢你的帮助!
我正在尝试设置一系列垂直轴跨度来象征不同时间的不同切换位置。例如,在下图中,切换位置 1(绿色)发生了很多次,在其他位置之间交替。

我在元组列表中绘制运行 for 循环的这些跨度,每个包含每个间隔的初始和最终索引以绘制 axvspan。
def plotShades(timestamp, intervals, colour):
for i in range(len(intervals)):
md.plt.axvspan(timestamp[intervals[i][0]], timestamp[intervals[i][1]], alpha=0.5, color=colour, label="interval")
Run Code Online (Sandbox Code Playgroud)
然后调用另一个函数,绘制每个不同开关位置的阴影:
def plotAllOutcomes(timestamp, switches):
#switches is a list of 7 arrays indicating when the switcher is at each one of the 7 positions. If the array has a 1 value, the switcher is there. 0 otherwise.
colors = ['#d73027', '#fc8d59', '#fee08b', '#ffffbf', '#d9ef8b', '#91cf60', '#1a9850']
intervals = []
for i in range(len(switches)):
intervals.append(getIntervals(switches[i], timestamp))
plotShades(timestamp, intervals[i], colors[i])
md.plt.legend()
Run Code Online (Sandbox Code Playgroud)
使用我放在这里的代码片段(不是最好的代码,我知道 - 我在 …