machinelearninginaction3x icon indicating copy to clipboard operation
machinelearninginaction3x copied to clipboard

kMeans.py does not work in python3

Open vitoyan opened this issue 7 years ago • 1 comments

in kMeans.py in CH10. it does not work in python3.

    def randCent(dataSet, k):
        n = shape(dataSet)[1]
        centroids = mat(zeros((k, n)))
        for j in range(n):
            minJ = min(dataSet[:,j])
            rangeJ = float(max(dataSet[:,j]) - minJ)

i got a error

rangeJ = float(max(dataSet[:,j]) - minJ)
TypeError: unsupported operand type(s) for -: 'map' and 'map'

vitoyan avatar Dec 11 '17 10:12 vitoyan

CH10 is not working with python3 yet, but to quick fix this, you can change this line in loadDataset()

from: fltLine = map(float,curLine) #map all elements to float() to: fltLine = list(map(float,curLine)) #map all elements to float()

shenyyi avatar Dec 20 '17 04:12 shenyyi