



"""simple docstring"""
import gc
import threading
import time

import psutil
import torch
class 					a	:



  def __init__(						self :					Tuple		)     ->					Optional[int]:


     '''simple docstring'''




     SCREAMING_SNAKE_CASE_: Optional[int]     			=psutil.Process()
     SCREAMING_SNAKE_CASE_: Tuple     			=False



  def 	lowerCamelCase__       (						self :					Optional[Any]		)     ->					str:


     '''simple docstring'''




     SCREAMING_SNAKE_CASE_: List[str]     			=-1

     while True:
        SCREAMING_SNAKE_CASE_: Optional[int]     			=max(self.process.memory_info().rss       ,		self.cpu_memory_peak		)

        # can't sleep or will not catch the peak right (this comment is here on purpose)
        if not self.peak_monitoring:
           break



  def 	lowerCamelCase__       (						self :					List[str]		)     ->					Optional[int]:


     '''simple docstring'''




     SCREAMING_SNAKE_CASE_: Optional[Any]     			=True
     SCREAMING_SNAKE_CASE_: int     			=threading.Thread(target=self.peak_monitor		)
     SCREAMING_SNAKE_CASE_: Optional[Any]     			=True
     self.thread.start()





  def 	lowerCamelCase__       (						self :					List[str]		)     ->					Optional[Any]:


     '''simple docstring'''




     SCREAMING_SNAKE_CASE_: Any     			=False
     self.thread.join()
     return self.cpu_memory_peak







_UpperCAmelCase     =			PeakCPUMemory()





def      __magic_name__				(							):
   # Time
   SCREAMING_SNAKE_CASE_: Optional[int]     			={"""time""": time.time()}

   gc.collect()
   torch.cuda.empty_cache()

   # CPU mem
   SCREAMING_SNAKE_CASE_: List[Any]     			=psutil.Process().memory_info().rss
   cpu_peak_tracker.start()

   # GPU mem
   for i in range(torch.cuda.device_count() ):
      SCREAMING_SNAKE_CASE_: List[Any]     			=torch.cuda.memory_allocated(lowercase )
   torch.cuda.reset_peak_memory_stats()

   return measures





def      __magic_name__				(							lowercase ):
   # Time
   SCREAMING_SNAKE_CASE_: Union[str, Any]     			={"""time""": time.time() - start_measures["""time"""]}

   gc.collect()
   torch.cuda.empty_cache()

   # CPU mem
   SCREAMING_SNAKE_CASE_: Any     			=(psutil.Process().memory_info().rss - start_measures["""cpu"""]) / 2**20
   SCREAMING_SNAKE_CASE_: Dict     			=(cpu_peak_tracker.stop() - start_measures["""cpu"""]) / 2**20

   # GPU mem
   for i in range(torch.cuda.device_count() ):
      SCREAMING_SNAKE_CASE_: Dict     			=(torch.cuda.memory_allocated(lowercase ) - start_measures[str(lowercase )]) / 2**20
      SCREAMING_SNAKE_CASE_: Optional[int]     			=(torch.cuda.max_memory_allocated(lowercase ) - start_measures[str(lowercase )]) / 2**20

   return measures





def      __magic_name__				(							lowercase							,			lowercase ):
   print(f'''{description}:''' )
   print(f'''- Time: {measures["time"]:.2f}s''' )
   for i in range(torch.cuda.device_count() ):
      print(f'''- GPU {i} allocated: {measures[str(lowercase )]:.2f}MiB''' )
      SCREAMING_SNAKE_CASE_: int     			=measures[f'''{i}-peak''']
      print(f'''- GPU {i} peak: {peak:.2f}MiB''' )
   print(f'''- CPU RAM allocated: {measures["cpu"]:.2f}MiB''' )
   print(f'''- CPU RAM peak: {measures["cpu-peak"]:.2f}MiB''' )








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





def      __magic_name__				(							lowercase							,			lowercase ):
   SCREAMING_SNAKE_CASE_: Dict     			=XGBClassifier()
   classifier.fit(lowercase							,			lowercase )
   return classifier





def      __magic_name__				(							):
   SCREAMING_SNAKE_CASE_: Optional[Any]     			=load_iris()
   SCREAMING_SNAKE_CASE_			,		SCREAMING_SNAKE_CASE_: Tuple     			=data_handling(lowercase )
   SCREAMING_SNAKE_CASE_			,		SCREAMING_SNAKE_CASE_			,		SCREAMING_SNAKE_CASE_			,		SCREAMING_SNAKE_CASE_: List[Any]     			=train_test_split(
       lowercase							,			lowercase							,			test_size=0.25 )

   SCREAMING_SNAKE_CASE_: Tuple     			=iris["""target_names"""]

   # Create an XGBoost Classifier from the training data
   SCREAMING_SNAKE_CASE_: Optional[int]     			=xgboost(lowercase							,			lowercase )

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


if __name__ == "__main__":
   import doctest

   doctest.testmod(verbose=True)
   main()



