machine_learning.gradient_descent ================================= .. py:module:: machine_learning.gradient_descent .. autoapi-nested-parse:: Implementation of gradient descent algorithm for minimizing cost of a linear hypothesis function. Attributes ---------- .. autoapisummary:: machine_learning.gradient_descent.LEARNING_RATE machine_learning.gradient_descent.m machine_learning.gradient_descent.parameter_vector machine_learning.gradient_descent.test_data machine_learning.gradient_descent.train_data Functions --------- .. autoapisummary:: machine_learning.gradient_descent._error machine_learning.gradient_descent._hypothesis_value machine_learning.gradient_descent.calculate_hypothesis_value machine_learning.gradient_descent.get_cost_derivative machine_learning.gradient_descent.output machine_learning.gradient_descent.run_gradient_descent machine_learning.gradient_descent.summation_of_cost_derivative machine_learning.gradient_descent.test_gradient_descent Module Contents --------------- .. py:function:: _error(example_no, data_set='train') :param data_set: train data or test data :param example_no: example number whose error has to be checked :return: error in example pointed by example number. .. py:function:: _hypothesis_value(data_input_tuple) Calculates hypothesis function value for a given input :param data_input_tuple: Input tuple of a particular example :return: Value of hypothesis function at that point. Note that there is an 'biased input' whose value is fixed as 1. It is not explicitly mentioned in input data.. But, ML hypothesis functions use it. So, we have to take care of it separately. Line 36 takes care of it. .. py:function:: calculate_hypothesis_value(example_no, data_set) Calculates hypothesis value for a given example :param data_set: test data or train_data :param example_no: example whose hypothesis value is to be calculated :return: hypothesis value for that example .. py:function:: get_cost_derivative(index) :param index: index of the parameter vector wrt to derivative is to be calculated :return: derivative wrt to that index Note: If index is -1, this means we are calculating summation wrt to biased parameter. .. py:function:: output(example_no, data_set) :param data_set: test data or train data :param example_no: example whose output is to be fetched :return: output for that example .. py:function:: run_gradient_descent() .. py:function:: summation_of_cost_derivative(index, end=m) Calculates the sum of cost function derivative :param index: index wrt derivative is being calculated :param end: value where summation ends, default is m, number of examples :return: Returns the summation of cost derivative Note: If index is -1, this means we are calculating summation wrt to biased parameter. .. py:function:: test_gradient_descent() .. py:data:: LEARNING_RATE :value: 0.009 .. py:data:: m :value: 5 .. py:data:: parameter_vector :value: [2, 4, 1, 5] .. py:data:: test_data :value: (((515, 22, 13), 555), ((61, 35, 49), 150)) .. py:data:: train_data :value: (((5, 2, 3), 15), ((6, 5, 9), 25), ((11, 12, 13), 41), ((1, 1, 1), 8), ((11, 12, 13), 41))