python 2.7 - Unsupported Operand Types for /: 'str' and 'float' -


i'm having bit of trouble understanding error message here...

i have been using sklearn machine learning tools on of data recently. i've tried outputting silhouette coefficient data, using following code below:

distmat = [] 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 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() 

the distmat array series of numbers read csv file. looks this:

[[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]] 

the error message gets returned looks such:

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     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     = 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) /: 'str' , 'float' 

i'm stuck @ understanding error message. how know i've gone wrong? , if kind enough, did go wrong here?

okay... figured out problem lay. changing "dtype" 'object' 'float', problem solved...


Comments

Popular posts from this blog

c# - DetailsView in ASP.Net - How to add another column on the side/add a control in each row? -

javascript - firefox memory leak -

Trying to import CSV file to a SQL Server database using asp.net and c# - can't find what I'm missing -