MCPcopy
hub / github.com/Jack-Lee-Hiter/AlgorithmsByPython / stocGradAscent1

Function stocGradAscent1

Logistic regression/Logistic.py:39–51  ·  view source on GitHub ↗
(dataMatrix, classLabels, numIter=150)

Source from the content-addressed store, hash-verified

37 return weights
38
39def stocGradAscent1(dataMatrix, classLabels, numIter=150):
40 m, n = shape(dataMatrix)
41 weights = ones(n)
42 for i in range(numIter):
43 dataIndex = len(list(range(m)))
44 for j in range(m):
45 alpha = 4/(1.0+i+j)+0.01
46 randIndex = int(random.uniform(0, dataIndex))
47 h = sigmoid(sum(dataMatrix[randIndex]*weights))
48 error = classLabels[randIndex] - h
49 weights = weights + alpha * error * dataMatrix[randIndex]
50 dataIndex -= 1
51 return weights
52
53def plotBestFit(weights):
54 import matplotlib.pyplot as plt

Callers 2

colicTestFunction · 0.85
Logistic.pyFile · 0.85

Calls 1

sigmoidFunction · 0.85

Tested by

no test coverage detected