






"""simple docstring"""



import numpy as np
import requests




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




def 						lowerCamelCase_				(  __A  :		str			,	__A  :		str			,	__A  :		Optional[int]			,	__A  :		int			,	__A  :		Optional[Any]			):
					lowerCamelCase__				=len_data

					lowerCamelCase__				=np.dot(lowercase__			,	data_x.transpose()			)
					prod -= data_y.transpose()
					lowerCamelCase__				=np.dot(lowercase__			,	lowercase__			)
					lowerCamelCase__				=theta - (alpha / n) * sum_grad
					return theta




def 						lowerCamelCase_				(  __A  :		Union[str, Any]			,	__A  :		List[str]			,	__A  :		List[Any]			,	__A  :		Union[str, Any]			):
					lowerCamelCase__				=np.dot(lowercase__			,	data_x.transpose()			)
					prod -= data_y.transpose()
					lowerCamelCase__				=np.sum(np.square(lowercase__			)			)
					lowerCamelCase__				=sum_elem / (2 * len_data)
					return error




def 						lowerCamelCase_				(  __A  :		Dict			,	__A  :		Optional[int]			):
					lowerCamelCase__				=10_0000
					lowerCamelCase__				=0.0_0_0_1_5_5_0

					lowerCamelCase__				=data_x.shape[1]
					lowerCamelCase__				=data_x.shape[0] - 1

					lowerCamelCase__				=np.zeros((1, no_features)			)

					for i in range(0			,	lowercase__			):
										lowerCamelCase__				=run_steep_gradient_descent(lowercase__			,	lowercase__			,	lowercase__			,	lowercase__			,	lowercase__			)
										lowerCamelCase__				=sum_of_square_error(lowercase__			,	lowercase__			,	lowercase__			,	lowercase__			)
										print(f"At Iteration {i + 1} - Error is {error:.5f}"			)

					return theta




def 						lowerCamelCase_				(  __A  :		Dict			,	__A  :		List[Any]			):
					lowerCamelCase__				=sum(abs(y - predicted_y[i]			) for i, y in enumerate(lowercase__			)			)
					return total / len(lowercase__			)




def 						lowerCamelCase_				(  ):
					lowerCamelCase__				=collect_dataset()

					lowerCamelCase__				=data.shape[0]
					lowerCamelCase__				=np.c_[np.ones(lowercase__			), data[:, :-1]].astype(lowercase__			)
					lowerCamelCase__				=data[:, -1].astype(lowercase__			)

					lowerCamelCase__				=run_linear_regression(lowercase__			,	lowercase__			)
					lowerCamelCase__				=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"""



from __future__ import annotations




def 						lowerCamelCase_				(  __A  :		int			,	__A  :		int			,	__A  :		int			):
					assert n > 1 and a > 0 and greatest_common_divisor(__A			,	__A			) == 1
					((lowerCamelCase__)				,     (lowerCamelCase__)				,     (lowerCamelCase__))				=extended_gcd(__A			,	__A			)  # Implemented below
					lowerCamelCase__				=(b * s) % n
					return x




def 						lowerCamelCase_				(  __A  :		int			,	__A  :		int			):
					((lowerCamelCase__)				,     (lowerCamelCase__))				=extended_euclid(__A			,	__A			)  # Implemented below
					if b < 0:
										lowerCamelCase__				=(b % n + n) % n
					return b




def 						lowerCamelCase_				(  __A  :		int			,	__A  :		int			,	__A  :		int			):
					lowerCamelCase__				=invert_modulo(__A			,	__A			)
					lowerCamelCase__				=(b * s) % n
					return x




def 						lowerCamelCase_				(  __A  :		int			,	__A  :		int			):
					assert a >= 0 and b >= 0

					if b == 0:
										lowerCamelCase__				,     lowerCamelCase__				,     lowerCamelCase__				=a, 1, 0
					else:
										((lowerCamelCase__)				,     (lowerCamelCase__)				,     (lowerCamelCase__))				=extended_gcd(__A			,	a % b			)
										lowerCamelCase__				=q
										lowerCamelCase__				=p - q * (a // b)

					assert a % d == 0 and b % d == 0
					assert d == a * x + b * y

					return (d, x, y)




def 						lowerCamelCase_				(  __A  :		int			,	__A  :		int			):
					if b == 0:
										return (1, 0)
					((lowerCamelCase__)				,     (lowerCamelCase__))				=extended_euclid(__A			,	a % b			)
					lowerCamelCase__				=a // b
					return (y, x - k * y)




def 						lowerCamelCase_				(  __A  :		int			,	__A  :		int			):
					if a < b:
										lowerCamelCase__				,     lowerCamelCase__				=b, a

					while a % b != 0:
										lowerCamelCase__				,     lowerCamelCase__				=b, a % b

					return b


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

						testmod(name="modular_division", verbose=True)
						testmod(name="modular_division2", verbose=True)
						testmod(name="invert_modulo", verbose=True)
						testmod(name="extended_gcd", verbose=True)
						testmod(name="extended_euclid", verbose=True)
						testmod(name="greatest_common_divisor", verbose=True)