Errata: January 31, 2019myEye = randMat*invRandMat >>> myEye - eye(4)
file2matrix() is given below. The code in the book will work.
def file2matrix(filename):
fr = open(filename)
arrayOLines = fr.readlines()
numberOfLines = len(arrayOLines)
returnMat = zeros((numberOfLines,3))
classLabelVector = []
index = 0
for line in arrayOLines:
line = line.strip()
listFromLine = line.split('\t')
returnMat[index,:] = listFromLine[0:3]
classLabelVector.append(int(listFromLine[-1]))
index += 1
return returnMat,classLabelVector
datingDataMat, datingLabels = kNN.file2matrix('datingTestSet.txt') datingDataMat, datingLabels = kNN.file2matrix('datingTestSet2.txt') >>> datingLabels[0:20]
['didntLike', 'smallDoses',...>>> datingLabels[0:20]
[3, 2, 1, 1, 1, 1, 3, 3, 1, 3, 1, 1, 2, 1, 1, 1, 1, 1, 2, 3]
datingDataMat, datingLabels = file2matrix('datingTestSet.txt')datingDataMat, datingLabels = file2matrix('datingTestSet2.txt')
l(xi) = log2p(xi)l(xi) = -log2p(xi)
labelCounts[currentLabel] = 0should be indented from the lines above and below it. The code in the repo is correct.
bestFeature = I bestFeature = i
>>> treePlotter.retrieveTree(1){'no surfacing': {0: 'no', 1: {'flippers': {0: {'head': {0: 'no', 1: 'yes'}}, 1: 'no'}}}}
>>> reload(logRegres)>>> from numpy import * At the beginning of the book I mention that this should be added to every interactive session, but it will be helpful for people to see this line here if they don't remember that.
|wTx+b|/ ||w|||wTA+b|/||w||
returnMat = zeros((numIt,n))ws = zeros((n,1)); wsTest = ws.copy(); wsMax = ws.copy()
yHat = mat((m,1))yHat = mat(zeros((m,1)))