machinelearninginaction3x
machinelearninginaction3x copied to clipboard
kMeans.py does not work in python3
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'
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()