





from collections.abc import Callable
from math import pi, sqrt
from random import uniform
from statistics import mean




def 						lowerCAmelCase_       (    __UpperCAmelCase:     int ) ->      str:

    # A local function to see if a dot lands in the circle.
    def is_in_circle(__UpperCAmelCase:     float						,  __UpperCAmelCase:     float ) -> bool:
        UpperCamelCase__				:							List[str]			  = sqrt((x**2) + (y**2) )
        # Our circle has a radius of 1, so a distance
        # greater than 1 would land outside the circle.
        return distance_from_centre <= 1

    # The proportion of guesses that landed in the circle
    UpperCamelCase__				:							Optional[int]			  = mean(
        int(is_in_circle(uniform(-1.0						,  1.0 )						,  uniform(-1.0						,  1.0 ) ) )
        for _ in range(_lowercase ) )
    # The ratio of the area for circle to square is pi/4.
    UpperCamelCase__				:							List[Any]			  = proportion * 4
    print(f"The estimated value of pi is {pi_estimate}" )
    print(f"The numpy value of pi is {pi}" )
    print(f"The total error is {abs(pi - pi_estimate )}" )




def 						lowerCAmelCase_       (    __UpperCAmelCase:     int						,  __UpperCAmelCase:     Callable[[float], float]						,  __UpperCAmelCase:     float = 0.0						,  __UpperCAmelCase:     float = 1.0						,  ) ->      float:
    return mean(
        function_to_integrate(uniform(_lowercase						,  _lowercase ) ) for _ in range(_lowercase ) ) * (max_value - min_value)




def 						lowerCAmelCase_       (    __UpperCAmelCase:     int						,  __UpperCAmelCase:     float = 0.0						,  __UpperCAmelCase:     float = 1.0 ) ->      None:

    def identity_function(__UpperCAmelCase:     float ) -> float:
        return x

    UpperCamelCase__				:							Tuple			  = area_under_curve_estimator(
        _lowercase						,  _lowercase						,  _lowercase						,  _lowercase )
    UpperCamelCase__				:							Dict			  = (max_value * max_value - min_value * min_value) / 2

    print('''******************''' )
    print(f"Estimating area under y=x where x varies from {min_value} to {max_value}" )
    print(f"Estimated value is {estimated_value}" )
    print(f"Expected value is {expected_value}" )
    print(f"Total error is {abs(estimated_value - expected_value )}" )
    print('''******************''' )




def 						lowerCAmelCase_       (    __UpperCAmelCase:     int ) ->      None:

    def function_to_integrate(__UpperCAmelCase:     float ) -> float:
        return sqrt(4.0 - x * x )

    UpperCamelCase__				:							Optional[Any]			  = area_under_curve_estimator(
        _lowercase						,  _lowercase						,  0.0						,  2.0 )

    print('''******************''' )
    print('''Estimating pi using area_under_curve_estimator''' )
    print(f"Estimated value is {estimated_value}" )
    print(f"Expected value is {pi}" )
    print(f"Total error is {abs(estimated_value - pi )}" )
    print('''******************''' )


if __name__ == "__main__":
  import doctest

  doctest.testmod()








import numpy as np
from sklearn.datasets import fetch_california_housing
from sklearn.metrics import mean_absolute_error, mean_squared_error
from sklearn.model_selection import train_test_split
from xgboost import XGBRegressor


def       SCREAMING_SNAKE_CASE__  (       _lowercase     : dict			)   ->							tuple:




		'''simple docstring'''
		return (data["data"], data["target"])


def       SCREAMING_SNAKE_CASE__  (       _lowercase     : np.ndarray   ,    _lowercase     : np.ndarray   ,    _lowercase     : np.ndarray			)   ->							np.ndarray:




		'''simple docstring'''
		lowercase__					:      List[str]      =		XGBRegressor(verbosity=0   ,    random_state=42			)
		xgb.fit(_lowercase   ,    _lowercase			)
		# Predict target for test data
		lowercase__					:      Union[str, Any]      =		xgb.predict(_lowercase			)
		lowercase__					:      Tuple      =		predictions.reshape(len(_lowercase			)   ,    1			)
		return predictions


def       SCREAMING_SNAKE_CASE__  (       )   ->							None:




		'''simple docstring'''
		lowercase__					:      List[str]      =		fetch_california_housing()
		lowercase__   ,				lowercase__					:      Optional[int]      =		data_handling(_lowercase			)
		lowercase__   ,				lowercase__   ,				lowercase__   ,				lowercase__					:      Optional[Any]      =		train_test_split(
		    _lowercase   ,    _lowercase   ,    test_size=0.25   ,    random_state=1			)
		lowercase__					:      Any      =		xgboost(_lowercase   ,    _lowercase   ,    _lowercase			)
		# Error printing
		print(f"""Mean Absolute Error : {mean_absolute_error(_lowercase   ,    _lowercase			)}"""			)
		print(f"""Mean Square Error  : {mean_squared_error(_lowercase   ,    _lowercase			)}"""			)


if __name__ == "__main__":
			import doctest

			doctest.testmod(verbose=True)
			main()


