Python 2.7 /:';的操作数类型不受支持;str';和';浮动';

Python 2.7 /:';的操作数类型不受支持;str';和';浮动';,python-2.7,bioinformatics,scikit-learn,Python 2.7,Bioinformatics,Scikit Learn,我在理解这个错误信息方面有点困难 我最近一直在使用sklearn机器学习工具处理我的一些数据。我已尝试使用以下代码输出数据的轮廓系数: distmat = [] for row in distmat_csv: distmat.append(row[1:]) in_distmat.close() distmat_array = np.array(distmat, dtype=object) print distmat_array out_metricsfile = open('Inf

我在理解这个错误信息方面有点困难

我最近一直在使用sklearn机器学习工具处理我的一些数据。我已尝试使用以下代码输出数据的轮廓系数:

distmat = []
for row in distmat_csv:
    distmat.append(row[1:])
in_distmat.close()

distmat_array = np.array(distmat, dtype=object)
print distmat_array


out_metricsfile = open('Influenza A All Subtypes Human Strains %s in %s Clustering Metrics.txt' % (name1, name2), 'w+') 
out_metricsfile.write('%s in %s Clustering Metrics \n' % (name1, name2))
out_metricsfile.write('Estimated number of clusters: %d \n' % n_clusters)
out_metricsfile.write("Silhouette Coefficient: %0.3f \n"
      % metrics.silhouette_score(distmat_array, labels, metric='precomputed'))
out_metricsfile.close()
distmat数组只是我从CSV文件中读取的一系列数字。它看起来像这样:

[[0.000000 0.614841 0.613074 ..., 0.007067 0.007067 0.010601]
 [0.614841 0.000000 0.012367 ..., 0.616608 0.613074 0.611307]
 [0.613074 0.012367 0.000000 ..., 0.614841 0.611307 0.609541]
 ..., 
 [0.007067 0.616608 0.614841 ..., 0.000000 0.010601 0.014134]
 [0.007067 0.613074 0.611307 ..., 0.010601 0.000000 0.010601]
 [0.010601 0.611307 0.609541 ..., 0.014134 0.010601 0.000000]]
返回的错误消息如下所示:

Traceback (most recent call last):
  File "script9-perform-affinity-propagation-and-display.py", line 92, in <module>
    % metrics.silhouette_score(distmat_array, labels, metric='precomputed'))
  File "/Library/Python/2.7/site-packages/scikit_learn-0.13.1-py2.7-macosx-10.8-intel.egg/sklearn/metrics/cluster/unsupervised.py", line 84, in silhouette_score
    return np.mean(silhouette_samples(X, labels, metric=metric, **kwds))
  File "/Library/Python/2.7/site-packages/scikit_learn-0.13.1-py2.7-macosx-10.8-intel.egg/sklearn/metrics/cluster/unsupervised.py", line 146, in silhouette_samples
    for i in range(n)])
  File "/Library/Python/2.7/site-packages/scikit_learn-0.13.1-py2.7-macosx-10.8-intel.egg/sklearn/metrics/cluster/unsupervised.py", line 176, in _intra_cluster_distance
    a = np.mean(distances_row[mask])
  File "/System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python/numpy/core/fromnumeric.py", line 2374, in mean
    return mean(axis, dtype, out)
TypeError: unsupported operand type(s) for /: 'str' and 'float'
回溯(最近一次呼叫最后一次):
文件“script9执行关联传播和显示.py”,第92行,在
%度量值。轮廓图得分(distmat\u数组、标签、度量值='precomputed'))
文件“/Library/Python/2.7/site packages/scikit_learn-0.13.1-py2.7-macosx-10.8-intel.egg/sklearn/metrics/cluster/unsupervised.py”,第84行,轮廓图中
返回np.平均值(轮廓_样本(X,标签,公制=公制,**kwds))
文件“/Library/Python/2.7/site packages/scikit_learn-0.13.1-py2.7-macosx-10.8-intel.egg/sklearn/metrics/cluster/unsupervised.py”,第146行,在剪影示例中
对于范围内的i(n)])
文件“/Library/Python/2.7/site packages/scikit_learn-0.13.1-py2.7-macosx-10.8-intel.egg/sklearn/metrics/cluster/unsupervised.py”,第176行,集群内距离
a=np.平均值(距离[遮罩])
文件“/System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/Python/numpy/core/fromnumeric.py”,第2374行的平均值
返回平均值(轴、数据类型、输出)
TypeError:/:“str”和“float”的操作数类型不受支持

我无法理解错误信息。我怎么知道我哪里出错了?如果有人对我够好的话,我哪里出了问题?

好的。。。所以我实际上找到了问题所在。通过将“数据类型”从“对象”更改为“浮点”,问题得以解决