title: Could not convert string to float: 'x', Kmeans implemetation python
body: <p>I try get a Silhouette index through kmeans implementation in python. I converter my cvs file to Tuple, but when I try get the k means clusters, get this error: <strong>Could not convert string to float:x</strong>. </p>
  
  <p>This is my code: </p>
  
  <pre><code>def archCVS (filename): #Covert to CVS to Tuple
      fileHandelr = open(filename, "rt")
      lines= fileHandelr.readlines()
      fileHandelr.close()
      #del lines[0] #remove the header
      dataset=[]
      for line in lines:
          instance= lineToTuple(line)
          dataset.append(instance)
      return dataset
  
  def lineToTuple(line): #Conver a comma separate string into tuple
      cleanLine=line.strip()
      cleanLine= cleanLine.replace('"', '')
      lineList=cleanLine.split(",")
      stringToNumbers(lineList)
      lineTuple=tuple(lineList)
      return lineTuple
  
  def stringToNumbers(myList): #Convert string to numbers
      for i in range(len(myList)):
          if(isValidNumberString(myList[i])):
              myList[i]=float(myList[i])
  
  def isValidNumberString(s): #Number verification 
      if len(s)==0:
          return False
      if len(s) &gt; 1 and s[0]=="-":
          s=s[1:]
      for  c in s:
          if c not in "0123456789.":
              return False
      return True
  
  def KmeasandShilo(X):
      kmeans_model =KMeans(n_clusters=2,random_state=10).fit(X)
      labels=kmeans_model.labels_
      Silho= metrics.silhouette_score(X,labels,metric='euclidean')
      return Silho
  </code></pre>
  
  <p>I get this error</p>
  
  <p><a href="http://i.stack.imgur.com/2syCf.jpg" rel="nofollow">Error imagem </a></p>
  
  <p>What can I do?</p>