


'''simple docstring'''


import numpy as np
import requests






def 			__lowerCAmelCase			():
		_UpperCAmelCase		:							List[str]             =   requests.get(
		    "https://raw.githubusercontent.com/yashLadha/The_Math_of_Intelligence/"
		    "master/Week1/ADRvsRating.csv" )
		_UpperCAmelCase		:							Optional[int]             =   response.text.splitlines()
		_UpperCAmelCase		:							List[Any]             =   []
		for item in lines:
				_UpperCAmelCase		:							Tuple             =   item.split("," )
				data.append(__lowerCAmelCase )
		data.pop(0 )  # This is for removing the labels from the list
		_UpperCAmelCase		:							List[Any]             =   np.matrix(__lowerCAmelCase )
		return dataset






def 			__lowerCAmelCase			(__lowerCAmelCase   ,			__lowerCAmelCase   ,			__lowerCAmelCase   ,			__lowerCAmelCase   ,			__lowerCAmelCase ):
		_UpperCAmelCase		:							str             =   len_data

		_UpperCAmelCase		:							int             =   np.dot(__lowerCAmelCase   ,			data_x.transpose() )
		prod -= data_y.transpose()
		_UpperCAmelCase		:							Union[str, Any]             =   np.dot(__lowerCAmelCase   ,			__lowerCAmelCase )
		_UpperCAmelCase		:							List[Any]             =   theta - (alpha / n) * sum_grad
		return theta






def 			__lowerCAmelCase			(__lowerCAmelCase   ,			__lowerCAmelCase   ,			__lowerCAmelCase   ,			__lowerCAmelCase ):
		_UpperCAmelCase		:							Dict             =   np.dot(__lowerCAmelCase   ,			data_x.transpose() )
		prod -= data_y.transpose()
		_UpperCAmelCase		:							Tuple             =   np.sum(np.square(__lowerCAmelCase ) )
		_UpperCAmelCase		:							Any             =   sum_elem / (2 * len_data)
		return error






def 			__lowerCAmelCase			(__lowerCAmelCase   ,			__lowerCAmelCase ):
		_UpperCAmelCase		:							Any             =   100_000
		_UpperCAmelCase		:							Optional[int]             =   0.0_0_0_1_5_5_0

		_UpperCAmelCase		:							Union[str, Any]             =   data_x.shape[1]
		_UpperCAmelCase		:							Tuple             =   data_x.shape[0] - 1

		_UpperCAmelCase		:							Dict             =   np.zeros((1, no_features) )

		for i in range(0   ,			__lowerCAmelCase ):
				_UpperCAmelCase		:							Optional[int]             =   run_steep_gradient_descent(__lowerCAmelCase   ,			__lowerCAmelCase   ,			__lowerCAmelCase   ,			__lowerCAmelCase   ,			__lowerCAmelCase )
				_UpperCAmelCase		:							Union[str, Any]             =   sum_of_square_error(__lowerCAmelCase   ,			__lowerCAmelCase   ,			__lowerCAmelCase   ,			__lowerCAmelCase )
				print(F"""At Iteration {i + 1} - Error is {error:.5f}""" )

		return theta






def 			__lowerCAmelCase			(__lowerCAmelCase   ,			__lowerCAmelCase ):
		_UpperCAmelCase		:							Optional[Any]             =   sum(abs(y - predicted_y[i] ) for i, y in enumerate(__lowerCAmelCase ) )
		return total / len(__lowerCAmelCase )






def 			__lowerCAmelCase			():
		_UpperCAmelCase		:							int             =   collect_dataset()

		_UpperCAmelCase		:							Any             =   data.shape[0]
		_UpperCAmelCase		:							int             =   np.c_[np.ones(__lowerCAmelCase ), data[:, :-1]].astype(__lowerCAmelCase )
		_UpperCAmelCase		:							Tuple             =   data[:, -1].astype(__lowerCAmelCase )

		_UpperCAmelCase		:							int             =   run_linear_regression(__lowerCAmelCase   ,			__lowerCAmelCase )
		_UpperCAmelCase		:							str             =   theta.shape[1]
		print("Resultant Feature vector : " )
		for i in range(0   ,			__lowerCAmelCase ):
				print(F"""{theta[0, i]:.5f}""" )


if __name__ == "__main__":
						main()







'''simple docstring'''


def 			__lowerCAmelCase			(__lowerCAmelCase ):
		return "".join(chr(ord(__lowerCAmelCase ) + 32 ) if "A" <= char <= "Z" else char for char in word )


if __name__ == "__main__":
						from doctest import testmod

						testmod()



