vendredi 17 juin 2016

could not convert string to float kmans,mapreduce,python

i am trying to solve kmeans algorithm( by using mapreduce). however i got stuck on above error.

the input: input is the line passed to function mapper containing two values value1,value2(in this case: 1.0419766942581599, -0.057426677019702423 )

following is the function from my class in which iam getting the error

def mapper(self, _, line):
    line1=line.split(',')

    ##remove spaces
    x1=line1[0].strip()
    x2=line1[1].strip()
    print x1
    print x2
    ##open previous centroids and compare
    tmp=open(self.fullPath,'r+')
    line=tmp.readline()
    lines=line.split('|')
    centroid1 = lines[0].split(',')
    centroid2 = lines[1].split(',')
    tmp.truncate()
    tmp.close()
    d1=e_distance(float(x1),float(x2),centroid1[0],centroid1[1])
    d2=e_distance(float(x1),float(x2),centroid2[0],centroid2[1])
    if(d1<d2):
        yield 'c1',[x[0],x[1]]
    else:
        yield 'c2',[x[0],x[1]]

however i am getting the following error. i am attaching the screenshot for further reference.

thank you!!!

output of the above code

Aucun commentaire:

Enregistrer un commentaire