(dataMatIn, classLabels)
| 14 | return 1/(1+exp(-inX)) |
| 15 | |
| 16 | def gradAscent(dataMatIn, classLabels): |
| 17 | dataMatrix = mat(dataMatIn) |
| 18 | labelMat = mat(classLabels).transpose() |
| 19 | m, n = shape(dataMatrix) |
| 20 | alpha = 0.001 |
| 21 | maxCycles = 500 |
| 22 | weights = ones((n, 1)) |
| 23 | for k in range(maxCycles): |
| 24 | h = sigmoid(dataMatrix*weights) |
| 25 | error = (labelMat - h) |
| 26 | weights += alpha * dataMatrix.transpose() * error |
| 27 | return weights |
| 28 | |
| 29 | def stocGradAscent0(dataMatrix, classLabels): |
| 30 | m, n = shape(dataMatrix) |