





"""simple docstring"""




import numpy as np
import requests





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





def  a_       (							_lowercase ,		_lowercase ,		_lowercase ,		_lowercase ,		_lowercase     ):
						_UpperCamelCase    :      Any						     =					len_data

						_UpperCamelCase    :      Optional[int]						     =					np.dot(_lowercase ,		data_x.transpose()     )
						prod -= data_y.transpose()
						_UpperCamelCase    :      str						     =					np.dot(_lowercase ,		_lowercase     )
						_UpperCamelCase    :      Dict						     =					theta - (alpha / n) * sum_grad
						return theta





def  a_       (							_lowercase ,		_lowercase ,		_lowercase ,		_lowercase     ):
						_UpperCamelCase    :      int						     =					np.dot(_lowercase ,		data_x.transpose()     )
						prod -= data_y.transpose()
						_UpperCamelCase    :      Any						     =					np.sum(np.square(_lowercase     )     )
						_UpperCamelCase    :      int						     =					sum_elem / (2 * len_data)
						return error





def  a_       (							_lowercase ,		_lowercase     ):
						_UpperCamelCase    :      Any						     =					10_0000
						_UpperCamelCase    :      Optional[int]						     =					0.0001550

						_UpperCamelCase    :      Dict						     =					data_x.shape[1]
						_UpperCamelCase    :      List[str]						     =					data_x.shape[0] - 1

						_UpperCamelCase    :      int						     =					np.zeros((1, no_features)     )

						for i in range(0 ,		_lowercase     ):
												_UpperCamelCase    :      Tuple						     =					run_steep_gradient_descent(_lowercase ,		_lowercase ,		_lowercase ,		_lowercase ,		_lowercase     )
												_UpperCamelCase    :      str						     =					sum_of_square_error(_lowercase ,		_lowercase ,		_lowercase ,		_lowercase     )
												print(F"""At Iteration {i + 1} - Error is {error:.5f}"""     )

						return theta





def  a_       (							_lowercase ,		_lowercase     ):
						_UpperCamelCase    :      str						     =					sum(abs(y - predicted_y[i]     ) for i, y in enumerate(_lowercase     )     )
						return total / len(_lowercase     )





def  a_       (							):
						_UpperCamelCase    :      Tuple						     =					collect_dataset()

						_UpperCamelCase    :      List[Any]						     =					data.shape[0]
						_UpperCamelCase    :      List[str]						     =					np.c_[np.ones(_lowercase     ), data[:, :-1]].astype(_lowercase     )
						_UpperCamelCase    :      Union[str, Any]						     =					data[:, -1].astype(_lowercase     )

						_UpperCamelCase    :      Any						     =					run_linear_regression(_lowercase ,		_lowercase     )
						_UpperCamelCase    :      Optional[Any]						     =					theta.shape[1]
						print('''Resultant Feature vector : '''     )
						for i in range(0 ,		_lowercase     ):
												print(F"""{theta[0, i]:.5f}"""     )


if __name__ == "__main__":
						main()










"""simple docstring"""




def  a_       (							_lowercase     ):
						_UpperCamelCase    :      str						     =					len(_lowercase     )

						# Set the gap value to be decreased by a factor of 1.3
						# after each iteration
						_UpperCamelCase    :      str						     =					1.3

						# Continue sorting until the gap is 1
						while gap > 1:
												# Decrease the gap value
												_UpperCamelCase    :      Union[str, Any]						     =					int(gap / shrink     )

												# Sort the elements using insertion sort
												for i in range(_lowercase ,		len(_lowercase     )     ):
																		_UpperCamelCase    :      Optional[Any]						     =					collection[i]
																		_UpperCamelCase    :      int						     =					i
																		while j >= gap and collection[j - gap] > temp:
																								_UpperCamelCase    :      List[str]						     =					collection[j - gap]
																								j -= gap
																		_UpperCamelCase    :      Union[str, Any]						     =					temp

						return collection


if __name__ == "__main__":
						import doctest

						doctest.testmod()



