【发布时间】:2014-05-10 14:05:43
【问题描述】:
我打算加载我自己的一组非结构化文本数据,可以看到如下:
64.242.88.10 - - [07/Mar/2004:16:05:49 -0800] "GET /twiki/bin/edit/Main/Double_bounce_sender?topicparent=Main.ConfigurationVariables HTTP/1.1" 401 12846
或者也可以采用以下形式:
/usr/local/etc/snmp/snmpd.conf: line 68: Error: Blank line following agentaddress token.
NET-SNMP version 5.3.1
基本上,程序并不关心给定数据的结构。
我已经在 scikit 中编辑了 MeanShift 示例中给出的代码,以便我的代码加载我自己的数据集。在这种情况下,输入文件被命名为 input。
for idx, line in enumerate(input):
if(len(line) == ''):
continue;
line = line.strip()
tmpNumPy = np.array([line])
print tmpNumPy
example = np.append(example, tmpNumPy)
# Compute clustering with MeanShift
# The following bandwidth can be automatically detected using
bandwidth = estimate_bandwidth(example, quantile=0.2, n_samples=500)
ms = MeanShift(bandwidth=bandwidth, bin_seeding=True)
ms.fit(X)
labels = ms.labels_
cluster_centers = ms.cluster_centers_
labels_unique = np.unique(labels)
n_clusters_ = len(labels_unique)
print(labels_unique)
print("number of estimated clusters : %d" % n_clusters_)
但是,当我运行此代码时,它给了我以下错误:
ValueError: data type not understood
我想知道如何使用 scikit 将一组文本数据而不是数值加载到 MeanShift 聚类中,或者我可以采取任何其他方法吗?
注意:我已经通过以下链接没有任何运气:
Meanshift in scikit learn (python) doesn't understand datatype
【问题讨论】:
标签: python machine-learning scikit-learn