




"""simple docstring"""
import numpy as np
from matplotlib import pyplot as plt
from sklearn.datasets import load_iris
from sklearn.metrics import ConfusionMatrixDisplay
from sklearn.model_selection import train_test_split
from xgboost import XGBClassifier





def 						UpperCAmelCase				(			A__:    dict     )  ->     tuple:
			return (data["data"], data["target"])





def 						UpperCAmelCase				(			A__:    np.ndarray							,				A__:    np.ndarray     )  ->     XGBClassifier:
			__lowerCamelCase					:	Tuple	       =				XGBClassifier()
			classifier.fit(A__							,				A__     )
			return classifier





def 						UpperCAmelCase				(			)  ->     None:
			__lowerCamelCase					:	Optional[Any]	       =				load_iris()
			__lowerCamelCase       ,      __lowerCamelCase					:	str	       =				data_handling(A__     )
			__lowerCamelCase       ,      __lowerCamelCase       ,      __lowerCamelCase       ,      __lowerCamelCase					:	Any	       =				train_test_split(
			    A__							,				A__							,				test_size=0.25     )

			__lowerCamelCase					:	Optional[int]	       =				iris['target_names']

			# Create an XGBoost Classifier from the training data
			__lowerCamelCase					:	int	       =				xgboost(A__							,				A__     )

			# Display the confusion matrix of the classifier with both training and test sets
			ConfusionMatrixDisplay.from_estimator(
			    A__							,				A__							,				A__							,				display_labels=A__							,				cmap='Blues'							,				normalize='true'							,				)
			plt.title('Normalized Confusion Matrix - IRIS Dataset'     )
			plt.show()


if __name__ == "__main__":
					import doctest

					doctest.testmod(verbose=True)
					main()









"""simple docstring"""
import json
import os
import tempfile
import unittest
import unittest.mock as mock
from pathlib import Path

from requests.exceptions import HTTPError

from transformers.utils import (
    CONFIG_NAME,
    FLAX_WEIGHTS_NAME,
    TF2_WEIGHTS_NAME,
    TRANSFORMERS_CACHE,
    WEIGHTS_NAME,
    cached_file,
    get_file_from_repo,
    has_file,
)


a_				:    Tuple										=     '''hf-internal-testing/tiny-random-bert'''
a_				:    List[Any]										=     os.path.join(TRANSFORMERS_CACHE, '''models--hf-internal-testing--tiny-random-bert''')
a_				:    Dict										=     '''9b8c223d42b2188cb49d29af482996f9d0f3e5a6'''

class __lowercase(      unittest.TestCase				):




					'''simple docstring'''


					def     snake_case_				(    self     ):
								__lowerCamelCase					:	List[Any]	       =				cached_file(__a						,	__a     )
								# Should have downloaded the file in here
								self.assertTrue(os.path.isdir(__a     )     )
								# Cache should contain at least those three subfolders:
								for subfolder in ["blobs", "refs", "snapshots"]:
											self.assertTrue(os.path.isdir(os.path.join(__a						,	__a     )     )     )
								with open(os.path.join(__a						,	'refs'						,	'main'     )     ) as f:
											__lowerCamelCase					:	Optional[int]	       =				f.read()
								self.assertEqual(__a						,	os.path.join(__a						,	'snapshots'						,	__a						,	__a     )     )
								self.assertTrue(os.path.isfile(__a     )     )

								# File is cached at the same place the second time.
								__lowerCamelCase					:	Optional[Any]	       =				cached_file(__a						,	__a     )
								self.assertEqual(__a						,	__a     )

								# Using a specific revision to test the full commit hash.
								__lowerCamelCase					:	Optional[int]	       =				cached_file(__a						,	__a						,	revision='9b8c223'     )
								self.assertEqual(__a						,	os.path.join(__a						,	'snapshots'						,	__a						,	__a     )     )
					def     snake_case_				(    self     ):
								with self.assertRaisesRegex(__a						,	'is not a valid model identifier'     ):
											__lowerCamelCase					:	List[str]	       =				cached_file('tiny-random-bert'						,	__a     )

								with self.assertRaisesRegex(__a						,	'is not a valid git identifier'     ):
											__lowerCamelCase					:	int	       =				cached_file(__a						,	__a						,	revision='aaaa'     )

								with self.assertRaisesRegex(__a						,	'does not appear to have a file named'     ):
											__lowerCamelCase					:	List[Any]	       =				cached_file(__a						,	'conf'     )
					def     snake_case_				(    self     ):
								with self.assertRaisesRegex(__a						,	'does not appear to have a file named'     ):
											__lowerCamelCase					:	Dict	       =				cached_file(__a						,	'conf'     )

								with open(os.path.join(__a						,	'refs'						,	'main'     )     ) as f:
											__lowerCamelCase					:	Any	       =				f.read()
								self.assertTrue(os.path.isfile(os.path.join(__a						,	'.no_exist'						,	__a						,	'conf'     )     )     )

								__lowerCamelCase					:	str	       =				cached_file(__a						,	'conf'						,	_raise_exceptions_for_missing_entries=__a     )
								self.assertIsNone(__a     )

								__lowerCamelCase					:	int	       =				cached_file(__a						,	'conf'						,	local_files_only=__a						,	_raise_exceptions_for_missing_entries=__a     )
								self.assertIsNone(__a     )

								__lowerCamelCase					:	List[str]	       =				mock.Mock()
								__lowerCamelCase					:	str	       =				500
								__lowerCamelCase					:	Union[str, Any]	       =				{}
								__lowerCamelCase					:	Dict	       =				HTTPError
								__lowerCamelCase					:	Any	       =				{}

								# Under the mock environment we get a 500 error when trying to reach the tokenizer.
								with mock.patch('requests.Session.request'						,	return_value=__a     ) as mock_head:
											__lowerCamelCase					:	Any	       =				cached_file(__a						,	'conf'						,	_raise_exceptions_for_connection_errors=__a     )
											self.assertIsNone(__a     )
											# This check we did call the fake head request
											mock_head.assert_called()
					def     snake_case_				(    self     ):
								self.assertTrue(has_file('hf-internal-testing/tiny-bert-pt-only'						,	__a     )     )
								self.assertFalse(has_file('hf-internal-testing/tiny-bert-pt-only'						,	__a     )     )
								self.assertFalse(has_file('hf-internal-testing/tiny-bert-pt-only'						,	__a     )     )
					def     snake_case_				(    self     ):
								# `get_file_from_repo` returns None if the file does not exist
								self.assertIsNone(get_file_from_repo('bert-base-cased'						,	'ahah.txt'     )     )

								# The function raises if the repository does not exist.
								with self.assertRaisesRegex(__a						,	'is not a valid model identifier'     ):
											get_file_from_repo('bert-base-case'						,	__a     )

								# The function raises if the revision does not exist.
								with self.assertRaisesRegex(__a						,	'is not a valid git identifier'     ):
											get_file_from_repo('bert-base-cased'						,	__a						,	revision='ahaha'     )

								__lowerCamelCase					:	Optional[int]	       =				get_file_from_repo('bert-base-cased'						,	__a     )
								# The name is the cached name which is not very easy to test, so instead we load the content.
								__lowerCamelCase					:	int	       =				json.loads(open(__a						,	'r'     ).read()     )
								self.assertEqual(config['hidden_size']						,	768     )





					def     snake_case_				(    self     ):
								with tempfile.TemporaryDirectory() as tmp_dir:
											__lowerCamelCase					:	int	       =				Path(__a     ) / 'a.txt'
											filename.touch()
											self.assertEqual(get_file_from_repo(__a						,	'a.txt'     )						,	str(__a     )     )

											self.assertIsNone(get_file_from_repo(__a						,	'b.txt'     )     )



