






import unittest
from pathlib import Path

from transformers import is_vision_available, load_tool
from transformers.testing_utils import get_tests_dir

from .test_tools_common import ToolTesterMixin


if is_vision_available():
   from PIL import Image


class 		lowerCAmelCase_							(     unittest.TestCase							,    UpperCamelCase   ):





     def 	lowerCamelCase       (  self     )		->							List[Any]:
        lowerCamelCase											=load_tool("""image-segmentation"""     )
        self.tool.setup()
        lowerCamelCase											=load_tool("""image-segmentation"""       ,   remote=_UpperCAmelCase     )





     def 	lowerCamelCase       (  self     )		->							Optional[int]:
        lowerCamelCase											=Image.open(Path(get_tests_dir("""fixtures/tests_samples/COCO"""     )     ) / """000000039769.png"""     )
        lowerCamelCase											=self.tool(_UpperCAmelCase       ,   """cat"""     )
        self.assertTrue(isinstance(_UpperCAmelCase       ,   Image.Image     )     )





     def 	lowerCamelCase       (  self     )		->							Optional[int]:
        lowerCamelCase											=Image.open(Path(get_tests_dir("""fixtures/tests_samples/COCO"""     )     ) / """000000039769.png"""     )
        lowerCamelCase											=self.remote_tool(_UpperCAmelCase       ,   """cat"""     )
        self.assertTrue(isinstance(_UpperCAmelCase       ,   Image.Image     )     )





     def 	lowerCamelCase       (  self     )		->							Union[str, Any]:
        lowerCamelCase											=Image.open(Path(get_tests_dir("""fixtures/tests_samples/COCO"""     )     ) / """000000039769.png"""     )
        lowerCamelCase											=self.tool(image=_UpperCAmelCase       ,   label="""cat"""     )
        self.assertTrue(isinstance(_UpperCAmelCase       ,   Image.Image     )     )





     def 	lowerCamelCase       (  self     )		->							Tuple:
        lowerCamelCase											=Image.open(Path(get_tests_dir("""fixtures/tests_samples/COCO"""     )     ) / """000000039769.png"""     )
        lowerCamelCase											=self.remote_tool(image=_UpperCAmelCase       ,   label="""cat"""     )
        self.assertTrue(isinstance(_UpperCAmelCase       ,   Image.Image     )     )







from sklearn.datasets import load_iris
from sklearn.model_selection import train_test_split
from sklearn.neighbors import KNeighborsClassifier

# Load iris file
_UpperCAmelCase				:	Optional[int]    						=    load_iris()
iris.keys()


print(f"Target names: \n {iris.target_names} ")
print(f"\n Features: \n {iris.feature_names}")

# Train set e Test set
_UpperCAmelCase						,						_UpperCAmelCase						,						_UpperCAmelCase						,						_UpperCAmelCase				:	List[Any]    						=    train_test_split(
    iris['data'], iris['target'], random_state=4
)

# KNN

_UpperCAmelCase				:	Optional[int]    						=    KNeighborsClassifier(n_neighbors=1)
knn.fit(X_train, y_train)

# new array to test
_UpperCAmelCase				:	List[Any]    						=    [[1, 2, 1, 4], [2, 3, 4, 5]]

_UpperCAmelCase				:	Tuple    						=    knn.predict(X_new)

print(
    f"\nNew array: \n {X_new}\n\nTarget Names Prediction: \n"
    f" {iris['target_names'][prediction]}"
)