import numpy as np
import matplotlib.pyplot as plt
import random as rd
from sklearn.datasets import load_iris
from sklearn.model_selection import train_test_split
iris = load_iris()

##
couleurs = np.array(['indigo', 'darkcyan', 'gold'])
fig, ax = plt.subplots(1, 2, figsize=(16,7))
for i in range(2):
    ax[i].scatter(iris.data[:,2*i], iris.data[:,2*i+1], color = couleurs[iris.target])
    h = [plt.Line2D([0,0],[0,0],color=couleurs[j],marker='o',linestyle='', \
         label=l) for j, l in enumerate(iris.target_names)]
    ax[i].legend(handles=h, title='Variété :')
    ax[i].set_xlabel(iris.feature_names[2*i])
    ax[i].set_ylabel(iris.feature_names[2*i + 1])
plt.show()

## Question 1



## Question 2
for k in [...]:
    print(variete[...])
    print("longueur des sépales : ", ..., "cm")
    print("largeur des sépales : ", ..., "cm")
    print("longueur des pétales : ", ..., "cm")
    print("largeur des pétales : ", ..., "cm")


## Entrainement/test
train_data, test_data, train_target, test_target = train_test_split(iris.data, iris.target, test_size=0.5, shuffle=True, random_state=12)

## Question 3



## Question 4



## Question 5



## Question 6



## Question 7
def partition(L,x):
    pivot = ...
    inf, sup = ...
    for e in L[1:]:
        if d(train_data[e],x) < ... :

        else:
            ...
    return pivot, inf, sup

def tri_rapide(L, x):
    if ...:
        return L
    pivot, inf, sup = partition(L,x)
    inf = tri_rapide(inf, x)
    sup = tri_rapide(sup, x)
    return ...

## Question 8



## Question 9



## Question 10



## Question 11



##
def plot_k_plus_proches(x, k):
    indices_voisins = k_plus_proches_voisins(x, k)
    fig, ax = plt.subplots(1, 2, figsize=(16,7))
    for i in range(2):
        ax[i].scatter(train_data[:,2*i], train_data[:,2*i+1], color = couleurs[train_target])
        h = [plt.Line2D([0,0],[0,0],color=couleurs[j],marker='o',linestyle='', \
            label=l) for j, l in enumerate(iris.target_names)]
        ax[i].legend(handles=h, title='Variété :')
        ax[i].set_xlabel(iris.feature_names[2*i])
        ax[i].set_ylabel(iris.feature_names[2*i + 1])
        ax[i].scatter(x[2*i], x[2*i + 1], s=100, marker='X', \
              color=couleurs[prediction_variete(x, k)])
        for j in indices_voisins:
            v = train_data[j]
            ax[i].scatter(v[2*i], v[2*i + 1], s=100, marker='o', \
                color=couleurs[train_target[j]])
    plt.show()

plot_k_plus_proches(test_data[36], 4)

## Question 12




## Question 13




## Question 14





