【发布时间】:2019-11-22 07:55:03
【问题描述】:
我目前正在处理一些科学数据,我正在尝试对其执行聚类任务,但由于数据格式的原因,我收到了一个值错误。这是 [170 行 x 7 列] 中的两个 Pandas DataFrame。
我尝试过转置数据、格式化为列表以及 numpy 数组。我在代码中显示的格式来自此处找到的解决方案:ValueError: cannot copy sequence with size 5 to array axis with dimension 2
#x is the y distance
x = np.empty(7, dtype = object)
x[:] = [distance_lC, distance_fC]
#y is the speed.
y = np.empty(7, dtype = object)
y[:] = [speed_lC, speed_fC]
cell_kmeans = KMeans(n_clusters = 4).fit_predict(y)
fig = plt.figure()
ax = fig.add_subplot(1,1,1)
ax.scatterplot(cell_kmeans)
plt.show()
输出应该给出集群。但我有以下值错误:“ValueError: setting an array element with a sequence。”
【问题讨论】:
-
我认为当你这样做时
y[:] = [speed_lC, speed_fC]你的y将成为一个列表,scikit 不会喜欢它!你能告诉我们speed_lC, speed_fC是什么吗? (使用type(speed_lC)) -
嗨!是的,如前所述,我使用的两个变量是 pandas DataFrames。所以使用
type输出:pandas.core.frame.DataFrame
标签: python numpy sklearn-pandas