


'''simple docstring'''
import unittest

import numpy as np
import torch

from .utils_summarization import build_mask, compute_token_type_ids, process_story, truncate_or_pad
class    lowercase	(							unittest.TestCase					):

		"""simple docstring"""

		def     lowerCAmelCase__				(		self							):

							'''simple docstring'''


							UpperCamelCase__   :Any												= 10




		def     lowerCAmelCase__				(		self							):

							'''simple docstring'''


							UpperCamelCase__   :Dict												= [1, 2, 3, 4]
							UpperCamelCase__   :Tuple												= [1, 2, 3, 4, 0, 0, 0, 0, 0, 0]
							self.assertEqual(truncate_or_pad(UpperCamelCase_    ,   self.block_size    ,   0							)    ,   UpperCamelCase_							)




		def     lowerCAmelCase__				(		self							):

							'''simple docstring'''


							UpperCamelCase__   :List[str]												= [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]
							UpperCamelCase__   :Any												= [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]
							self.assertEqual(truncate_or_pad(UpperCamelCase_    ,   self.block_size    ,   0							)    ,   UpperCamelCase_							)




		def     lowerCAmelCase__				(		self							):

							'''simple docstring'''


							UpperCamelCase__   :Any												= [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13]
							UpperCamelCase__   :Optional[Any]												= [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]
							self.assertEqual(truncate_or_pad(UpperCamelCase_    ,   self.block_size    ,   0							)    ,   UpperCamelCase_							)




		def     lowerCAmelCase__				(		self							):

							'''simple docstring'''


							UpperCamelCase__   :List[Any]												= '''It was the year of Our Lord one thousand seven hundred and
        seventy-five.\n\nSpiritual revelations were conceded to England at that
        favoured period, as at this.'''
							UpperCamelCase__					,				UpperCamelCase__   :int												= process_story(UpperCamelCase_							)
							self.assertEqual(UpperCamelCase_    ,   []							)




		def     lowerCAmelCase__				(		self							):

							'''simple docstring'''


							UpperCamelCase__   :Tuple												= ''''''
							UpperCamelCase__					,				UpperCamelCase__   :List[str]												= process_story(UpperCamelCase_							)
							self.assertEqual(UpperCamelCase_    ,   []							)
							self.assertEqual(UpperCamelCase_    ,   []							)




		def     lowerCAmelCase__				(		self							):

							'''simple docstring'''


							UpperCamelCase__   :Tuple												= (
							    '''It was the year of Our Lord one thousand seven hundred and '''
							    '''seventy-five\n\nSpiritual revelations were conceded to England '''
							    '''at that favoured period, as at this.\n@highlight\n\nIt was the best of times'''
							)
							UpperCamelCase__					,				UpperCamelCase__   :Tuple												= process_story(UpperCamelCase_							)

							UpperCamelCase__   :Any												= [
							    '''It was the year of Our Lord one thousand seven hundred and seventy-five.''',
							    '''Spiritual revelations were conceded to England at that favoured period, as at this.''',
							]
							self.assertEqual(UpperCamelCase_    ,   UpperCamelCase_							)

							UpperCamelCase__   :str												= ['''It was the best of times.''']
							self.assertEqual(UpperCamelCase_    ,   UpperCamelCase_							)




		def     lowerCAmelCase__				(		self							):

							'''simple docstring'''


							UpperCamelCase__   :Dict												= torch.tensor([1, 2, 3, 4]							)
							UpperCamelCase__   :Optional[int]												= torch.tensor([1, 1, 1, 1]							)
							np.testing.assert_array_equal(build_mask(UpperCamelCase_    ,   0							).numpy()    ,   expected.numpy()							)




		def     lowerCAmelCase__				(		self							):

							'''simple docstring'''


							UpperCamelCase__   :Tuple												= torch.tensor([1, 2, 3, 4, 23, 23, 23]							)
							UpperCamelCase__   :List[Any]												= torch.tensor([1, 1, 1, 1, 0, 0, 0]							)
							np.testing.assert_array_equal(build_mask(UpperCamelCase_    ,   23							).numpy()    ,   expected.numpy()							)




		def     lowerCAmelCase__				(		self							):

							'''simple docstring'''


							UpperCamelCase__   :Tuple												= torch.tensor([8, 2, 3, 4, 1, 1, 1]							)
							UpperCamelCase__   :Tuple												= torch.tensor([1, 1, 1, 1, 0, 0, 0]							)
							np.testing.assert_array_equal(build_mask(UpperCamelCase_    ,   1							).numpy()    ,   expected.numpy()							)




		def     lowerCAmelCase__				(		self							):

							'''simple docstring'''


							UpperCamelCase__   :List[Any]												= 101
							UpperCamelCase__   :List[str]												= torch.tensor([[1, 2, 3, 4, 5, 6], [1, 2, 3, 101, 5, 6], [1, 101, 3, 4, 101, 6]]							)
							UpperCamelCase__   :Tuple												= torch.tensor([[1, 1, 1, 1, 1, 1], [1, 1, 1, 0, 0, 0], [1, 0, 0, 0, 1, 1]]							)

							UpperCamelCase__   :Any												= compute_token_type_ids(UpperCamelCase_    ,   UpperCamelCase_							)
							np.testing.assert_array_equal(UpperCamelCase_    ,   UpperCamelCase_							)







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 						__UpperCAmelCase			(     a_):
							return (data["data"], data["target"])





def 						__UpperCAmelCase			(     a_							,     a_							,     a_):
							snake_case_				=							XGBRegressor(verbosity=0							,     random_state=42)
							xgb.fit(a_							,     a_)
							# Predict target for test data
							snake_case_				=							xgb.predict(a_)
							snake_case_				=							predictions.reshape(len(a_)							,     1)
							return predictions





def 						__UpperCAmelCase			(     ):
							snake_case_				=							fetch_california_housing()
							snake_case_			,		snake_case_				=							data_handling(a_)
							snake_case_			,		snake_case_			,		snake_case_			,		snake_case_				=							train_test_split(
							    a_							,     a_							,     test_size=0.25							,     random_state=1)
							snake_case_				=							xgboost(a_							,     a_							,     a_)
							# Error printing
							print(f'''Mean Absolute Error : {mean_absolute_error(a_							,     a_)}''')
							print(f'''Mean Square Error  : {mean_squared_error(a_							,     a_)}''')


if __name__ == "__main__":
	import doctest

	doctest.testmod(verbose=True)
	main()





