


'''simple docstring'''







import numpy as np







class A__	:






      def __init__(			self      :Any					,						SCREAMING_SNAKE_CASE      :Any=5					,						SCREAMING_SNAKE_CASE      :Any=5     )	-> Optional[int]:




             '''simple docstring'''
             _a   :			Tuple					 =depth
             _a   :			Union[str, Any]					 =0
             _a   :			Optional[int]					 =None
             _a   :			Optional[int]					 =None
             _a   :			Tuple					 =min_leaf_size
             _a   :			Union[str, Any]					 =None






      def __UpperCAmelCase	(			self      :Dict					,						SCREAMING_SNAKE_CASE      :List[Any]					,						SCREAMING_SNAKE_CASE      :int     )	-> Dict:




             '''simple docstring'''
             if labels.ndim != 1:
                    print("""Error: Input labels must be one dimensional"""     )

             return np.mean((labels - prediction) ** 2     )






      def __UpperCAmelCase	(			self      :int					,						SCREAMING_SNAKE_CASE      :Union[str, Any]					,						SCREAMING_SNAKE_CASE      :str     )	-> Tuple:




             '''simple docstring'''
             if x.ndim != 1:
                    print("""Error: Input data set must be one dimensional"""     )
                    return
             if len(SCREAMING_SNAKE_CASE     ) != len(SCREAMING_SNAKE_CASE     ):
                    print("""Error: X and y have different lengths"""     )
                    return
             if y.ndim != 1:
                    print("""Error: Data set labels must be one dimensional"""     )
                    return

             if len(SCREAMING_SNAKE_CASE     ) < 2 * self.min_leaf_size:
                    _a   :			Tuple					 =np.mean(SCREAMING_SNAKE_CASE     )
                    return

             if self.depth == 1:
                    _a   :			str					 =np.mean(SCREAMING_SNAKE_CASE     )
                    return

             _a   :			str					 =0
             _a   :			List[str]					 =self.mean_squared_error(SCREAMING_SNAKE_CASE					,						np.mean(SCREAMING_SNAKE_CASE     )     ) * 2
             for i in range(len(SCREAMING_SNAKE_CASE     )     ):
                    if len(x[:i]     ) < self.min_leaf_size:
                           continue
                    elif len(x[i:]     ) < self.min_leaf_size:
                           continue
                    else:
                           _a   :			Optional[int]					 =self.mean_squared_error(x[:i]					,						np.mean(y[:i]     )     )
                           _a   :			Tuple					 =self.mean_squared_error(x[i:]					,						np.mean(y[i:]     )     )
                           _a   :			Dict					 =error_left + error_right
                           if error < min_error:
                                  _a   :			Tuple					 =i
                                  _a   :			List[Any]					 =error

             if best_split != 0:
                    _a   :			Union[str, Any]					 =x[:best_split]
                    _a   :			Optional[Any]					 =y[:best_split]
                    _a   :			Optional[Any]					 =x[best_split:]
                    _a   :			int					 =y[best_split:]

                    _a   :			Union[str, Any]					 =x[best_split]
                    _a   :			int					 =DecisionTree(
                        depth=self.depth - 1					,						min_leaf_size=self.min_leaf_size     )
                    _a   :			str					 =DecisionTree(
                        depth=self.depth - 1					,						min_leaf_size=self.min_leaf_size     )
                    self.left.train(SCREAMING_SNAKE_CASE					,						SCREAMING_SNAKE_CASE     )
                    self.right.train(SCREAMING_SNAKE_CASE					,						SCREAMING_SNAKE_CASE     )
             else:
                    _a   :			Dict					 =np.mean(SCREAMING_SNAKE_CASE     )

             return






      def __UpperCAmelCase	(			self      :int					,						SCREAMING_SNAKE_CASE      :List[Any]     )	-> Optional[int]:




             '''simple docstring'''
             if self.prediction is not None:
                    return self.prediction
             elif self.left or self.right is not None:
                    if x >= self.decision_boundary:
                           return self.right.predict(SCREAMING_SNAKE_CASE     )
                    else:
                           return self.left.predict(SCREAMING_SNAKE_CASE     )
             else:
                    print("""Error: Decision tree not yet trained"""     )
                    return None







class A__	:






      @staticmethod
      def __UpperCAmelCase	(			SCREAMING_SNAKE_CASE      :Union[str, Any]					,						SCREAMING_SNAKE_CASE      :Optional[Any]     )	-> Any:




             '''simple docstring'''
             _a   :			Dict					 =float(0     )
             for label in labels:
                    squared_error_sum += (label - prediction) ** 2

             return float(squared_error_sum / labels.size     )


def      SCREAMING_SNAKE_CASE_ (  )  ->      List[Any]:
       _a   :			Optional[int]					 =np.arange(-1.0   ,1.0   ,0.0_0_5  )
       _a   :			int					 =np.sin(_UpperCAmelCase  )

       _a   :			Dict					 =DecisionTree(depth=10   ,min_leaf_size=10  )
       tree.train(_UpperCAmelCase   ,_UpperCAmelCase  )

       _a   :			Optional[Any]					 =(np.random.rand(10  ) * 2) - 1
       _a   :			Optional[int]					 =np.array([tree.predict(_UpperCAmelCase  ) for x in test_cases]  )
       _a   :			Tuple					 =np.mean((predictions - test_cases) ** 2  )

       print("""Test values: """ + str(_UpperCAmelCase  )  )
       print("""Predictions: """ + str(_UpperCAmelCase  )  )
       print("""Average error: """ + str(_UpperCAmelCase  )  )


if __name__ == "__main__":
   main()
   import doctest

   doctest.testmod(name='''mean_squarred_error''', verbose=True)






'''simple docstring'''







import math


def      SCREAMING_SNAKE_CASE_ (  _UpperCAmelCase     :     int  )  ->      int:
       return sum(int(_UpperCAmelCase  ) for digit in str(_UpperCAmelCase  )  )


def      SCREAMING_SNAKE_CASE_ (  _UpperCAmelCase     :     int = 30  )  ->      int:
       _a   :			List[Any]					 =[]
       for digit in range(2   ,100  ):
              for power in range(2   ,100  ):
                     _a   :			Optional[Any]					 =int(math.pow(_UpperCAmelCase   ,_UpperCAmelCase  )  )
                     if digit == digit_sum(_UpperCAmelCase  ):
                            digit_to_powers.append(_UpperCAmelCase  )

       digit_to_powers.sort()
       return digit_to_powers[n - 1]


if __name__ == "__main__":
   print(solution())


