【发布时间】:2015-09-27 16:29:17
【问题描述】:
我想将我的 csv 数据可视化到集群中。
供您参考。 我可以将 csv 数据可视化为 3D 图形。
这是我的代码。
import pandas as pd
import numpy as np
import matplotlib.pyplot as plt
from mpl_toolkits.mplot3d import axes3d
MY_FILE = 'total_watt.csv'
df = pd.read_csv(MY_FILE, parse_dates=[0], header=None, names=['datetime', 'consumption'])
df['date'] = [x.date() for x in df['datetime']]
df['time'] = [x.time() for x in df['datetime']]
pv = df.pivot(index='time', columns='date', values='consumption')
# to avoid holes in the surface
pv = pv.fillna(0.0)
xx, yy = np.mgrid[0:len(pv),0:len(pv.columns)]
fig = plt.figure()
ax = fig.add_subplot(111, projection='3d')
surf=ax.plot_surface(xx, yy, pv.values, cmap='jet', cstride=1, rstride=1)
fig.colorbar(surf, shrink=0.5, aspect=10)
dates = [x.strftime('%m-%d') for x in pv.columns]
times = [x.strftime('%H:%M') for x in pv.index]
ax.set_title('Energy consumptions Clusters', color='lightseagreen')
ax.set_xlabel('time', color='darkturquoise')
ax.set_ylabel('date(year 2011)', color='darkturquoise')
ax.set_zlabel('energy consumption', color='darkturquoise')
ax.set_xticks(xx[::10,0])
ax.set_xticklabels(times[::10], color='lightseagreen')
ax.set_yticks(yy[0,::10])
ax.set_yticklabels(dates[::10], color='lightseagreen')
ax.set_axis_bgcolor('black')
plt.show()
#Thanks for reading! Looking forward to the Skype Interview.
这是图表,我从这段代码中得到的。
我想我应该改变这段代码的一些点,以便将数据分为三组:高、中、低能耗。
我想通过对数据进行聚类得到的图像是这样的。(2D,3colors。)
k 均值??????我应该使用吗?..
【问题讨论】:
-
请将您的标题编辑成更有意义的内容,而不是评论
-
我也想拥有如此漂亮的数据集群...
-
通过查看您的数据,我会尝试一些具有径向基函数的集群,例如来自 sklearn 的 SVC。顺便提一句。有一个很好的流程图:scikit-learn.org/stable/tutorial/machine_learning_map/…
标签: python pandas matplotlib scikit-learn