(alpha, x, y, max_iterations=70000)
| 110 | |
| 111 | # here alpha is the learning rate, X is the feature matrix,y is the target matrix |
| 112 | def 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]: |
no test coverage detected