MCPcopy Index your code
hub / github.com/TheAlgorithms/Python / logistic_reg

Function logistic_reg

machine_learning/logistic_regression.py:112–125  ·  view source on GitHub ↗
(alpha, x, y, max_iterations=70000)

Source from the content-addressed store, hash-verified

110
111# here alpha is the learning rate, X is the feature matrix,y is the target matrix
112def logistic_reg(alpha, x, y, max_iterations=70000):
113 theta = np.zeros(x.shape[1])
114
115 for iterations in range(max_iterations):
116 z = np.dot(x, theta)
117 h = sigmoid_function(z)
118 gradient = np.dot(x.T, h - y) / y.size
119 theta = theta - alpha * gradient # updating the weights
120 z = np.dot(x, theta)
121 h = sigmoid_function(z)
122 j = cost_function(h, y)
123 if iterations % 100 == 0:
124 print(f"loss: {j} \t") # printing the loss after every 100 iterations
125 return theta
126
127
128# In[68]:

Callers 1

Calls 2

cost_functionFunction · 0.85
sigmoid_functionFunction · 0.70

Tested by

no test coverage detected