daily pastebin goal
93%
SHARE
TWEET

Untitled

a guest Jan 21st, 2019 64 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. def sigmoid(inX):
  2.     return 1.0/(1+exp(-inX))
  3.  
  4. def gradAscent(dataMatIn, classLabels):
  5.     dataMatrix = mat(dataMatIn)             #convert to NumPy matrix
  6.     labelMat = mat(classLabels).transpose() #convert to NumPy matrix
  7.     m,n = shape(dataMatrix)
  8.     alpha = 0.001
  9.     maxCycles = 500
  10.     weights = ones((n,1))
  11.     for k in range(maxCycles):              #heavy on matrix operations
  12.         h = sigmoid(dataMatrix*weights)     #matrix mult
  13.         error = (labelMat - h)              #vector subtraction
  14.         weights = weights + alpha * dataMatrix.transpose()* error #matrix mult
  15.     return weights
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top