




import numpy as np
import requests





def 							lowerCamelCase    (							)->			str:

       """simple docstring"""




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





def 							lowerCamelCase    (							UpperCAmelCase_	:      Union[str, Any]   ,       UpperCAmelCase_	:      Any   ,       UpperCAmelCase_	:      Union[str, Any]   ,       UpperCAmelCase_	:      List[Any]   ,       UpperCAmelCase_	:      Dict      )->			List[str]:

       """simple docstring"""




       a			   =len_data

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





def 							lowerCamelCase    (							UpperCAmelCase_	:      Optional[Any]   ,       UpperCAmelCase_	:      Dict   ,       UpperCAmelCase_	:      Dict   ,       UpperCAmelCase_	:      int      )->			str:

       """simple docstring"""




       a			   =np.dot(UpperCAmelCase_   ,       data_x.transpose()      )
       prod -= data_y.transpose()
       a			   =np.sum(np.square(UpperCAmelCase_      )      )
       a			   =sum_elem / (2 * len_data)
       return error





def 							lowerCamelCase    (							UpperCAmelCase_	:      Optional[Any]   ,       UpperCAmelCase_	:      str      )->			Optional[Any]:

       """simple docstring"""




       a			   =10_0000
       a			   =0.0_00_15_50

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

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

       for i in range(0   ,       UpperCAmelCase_      ):
              a			   =run_steep_gradient_descent(UpperCAmelCase_   ,       UpperCAmelCase_   ,       UpperCAmelCase_   ,       UpperCAmelCase_   ,       UpperCAmelCase_      )
              a			   =sum_of_square_error(UpperCAmelCase_   ,       UpperCAmelCase_   ,       UpperCAmelCase_   ,       UpperCAmelCase_      )
              print(F'''At Iteration {i + 1} - Error is {error:.5f}'''      )

       return theta





def 							lowerCamelCase    (							UpperCAmelCase_	:      Union[str, Any]   ,       UpperCAmelCase_	:      Any      )->			str:

       """simple docstring"""




       a			   =sum(abs(y - predicted_y[i]      ) for i, y in enumerate(UpperCAmelCase_      )      )
       return total / len(UpperCAmelCase_      )





def 							lowerCamelCase    (							)->			Optional[int]:

       """simple docstring"""




       a			   =collect_dataset()

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

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


if __name__ == "__main__":
    main()






import math
from timeit import timeit





def 							lowerCamelCase    (							UpperCAmelCase_	:      int      )->			int:

       """simple docstring"""




       a			   =0
       a			   =abs(UpperCAmelCase_      )
       while True:
              a			   =n // 10
              digits += 1
              if n == 0:
                     break
       return digits





def 							lowerCamelCase    (							UpperCAmelCase_	:      int      )->			int:

       """simple docstring"""




       return 1 if n == 0 else math.floor(math.log(abs(UpperCAmelCase_      )   ,       10      ) + 1      )





def 							lowerCamelCase    (							UpperCAmelCase_	:      int      )->			int:

       """simple docstring"""




       return len(str(abs(UpperCAmelCase_      )      )      )





def 							lowerCamelCase    (							)->			None:

       """simple docstring"""




       from collections.abc import Callable

       def benchmark_a_function(UpperCAmelCase_	:      Callable   ,       UpperCAmelCase_	:      int      ) -> None:
              a			   =F'''{func.__name__}({value})'''
              a			   =timeit(F'''__main__.{call}'''   ,       setup="""import __main__"""      )
              print(F'''{call}: {func(UpperCAmelCase_      )} -- {timing} seconds'''      )

       for value in (26_2144, 1125_8999_0684_2624, 126_7650_6002_2822_9401_4967_0320_5376):
              for func in (num_digits, num_digits_fast, num_digits_faster):
                     benchmark_a_function(UpperCAmelCase_   ,       UpperCAmelCase_      )
              print()


if __name__ == "__main__":
    import doctest

    doctest.testmod()
    benchmark()
