Guest User

Untitled

a guest
Jan 21st, 2019
72
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.36 KB | None | 0 0
  1. def sigmoid(inX):
  2. return 1.0/(1+exp(-inX))
  3.  
  4. def stocGradAscent(dataMatrix, classLabels):
  5. m,n = shape(dataMatrix)
  6. alpha = 0.01
  7. weights = ones(n) #initialize to all ones
  8. for i in range(m):
  9. h = sigmoid(sum(dataMatrix[i]*weights))
  10. error = classLabels[i] - h
  11. weights = weights + alpha * error * dataMatrix[i]
  12. return weights
Add Comment
Please, Sign In to add comment