Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- def sigmoid(inX):
- return 1.0/(1+exp(-inX))
- def stocGradAscent(dataMatrix, classLabels):
- m,n = shape(dataMatrix)
- alpha = 0.01
- weights = ones(n) #initialize to all ones
- for i in range(m):
- h = sigmoid(sum(dataMatrix[i]*weights))
- error = classLabels[i] - h
- weights = weights + alpha * error * dataMatrix[i]
- return weights
Add Comment
Please, Sign In to add comment