Run steep gradient descent and updates the Feature vector accordingly_ :param data_x : contains the dataset :param data_y : contains the output associated with each data-entry :param len_data : length of the data_ :param alpha : Learning rate of the model :param theta :
(data_x, data_y, len_data, alpha, theta)
| 41 | |
| 42 | |
| 43 | def run_steep_gradient_descent(data_x, data_y, len_data, alpha, theta): |
| 44 | """Run steep gradient descent and updates the Feature vector accordingly_ |
| 45 | :param data_x : contains the dataset |
| 46 | :param data_y : contains the output associated with each data-entry |
| 47 | :param len_data : length of the data_ |
| 48 | :param alpha : Learning rate of the model |
| 49 | :param theta : Feature vector (weight's for our model) |
| 50 | ;param return : Updated Feature's, using |
| 51 | curr_features - alpha_ * gradient(w.r.t. feature) |
| 52 | >>> import numpy as np |
| 53 | >>> data_x = np.array([[1, 2], [3, 4]]) |
| 54 | >>> data_y = np.array([5, 6]) |
| 55 | >>> len_data = len(data_x) |
| 56 | >>> alpha = 0.01 |
| 57 | >>> theta = np.array([0.1, 0.2]) |
| 58 | >>> run_steep_gradient_descent(data_x, data_y, len_data, alpha, theta) |
| 59 | array([0.196, 0.343]) |
| 60 | """ |
| 61 | n = len_data |
| 62 | |
| 63 | prod = np.dot(theta, data_x.transpose()) |
| 64 | prod -= data_y.transpose() |
| 65 | sum_grad = np.dot(prod, data_x) |
| 66 | theta = theta - (alpha / n) * sum_grad |
| 67 | return theta |
| 68 | |
| 69 | |
| 70 | def sum_of_square_error(data_x, data_y, len_data, theta): |
no test coverage detected