# -*- coding: utf-8 -*-
"""
Created on Fri Nov 19 23:08:23 2021

@author: pfaure
"""


from myplotlib import print_1d_data, print_2d_data, print_3d_data
from mydatalib import extract_data_2d, extract_data_3d, scale_data
from mydatalib import apply_kmeans, evaluate


path = './artificial/'
dataset_name = "xclara.arff"

# Extraction et visualisation d'un dataset 2D
data = extract_data_2d(path + dataset_name)
print_2d_data(data, dataset_name=dataset_name+" brute", stop=False)

# Extraction et visualisation d'un dataset 3D
data_golfball = extract_data_3d(path+"golfball.arff")
print_3d_data(data_golfball, dataset_name="golfball.arff", stop=False)

# Scaling des data 2D et visualisation
data_scaled = scale_data(data)
print_2d_data(data_scaled, dataset_name=dataset_name+" scaled", stop=False)


# kmeans = KMeans(n_clusters=3000, random_state=0).fit_predict(data_scaled)
# print_2d_data(data_s_set2_scaled, True, kmeans)
k = []
durations = []
silouettes = []
inerties = []
iterations = []
for i in range(2, 5):
    (model, duration) = apply_kmeans(data_scaled, k=i, init="k-means++")
    print_2d_data(data_scaled, dataset_name=dataset_name,
                  method_name="k-means", k=i, stop=False, c=model.labels_)
    (silouette, inertie, iteration) = evaluate(data_scaled, model)
    k += [i]
    durations += [duration]
    silouettes += [silouette]
    inerties += [inertie]
    iterations += [iteration]

print_1d_data(k, k, x_name="k", y_name="k", stop=False)
print_1d_data(k, durations, x_name="k", y_name="temps de calcul", stop=False)
print_1d_data(k, silouettes, x_name="k",
              y_name="coeficient de silhouette", stop=False)
print_1d_data(k, inerties, x_name="k", y_name="inertie", stop=False)
print_1d_data(k, iterations, x_name="k",
              y_name="nombre d'itérations", stop=True)
