Example #1
0
    print(f"findBestKWithCrossValidation: {findBestKWithCrossValidation}")
    print("\n")

    print('-' * 175)
    print(f"Iris dataset classification: \n")
    startTime = time.time()

    #  Entrainement sur l'ensemble de données Iris

    iris_train, iris_train_labels, iris_test, iris_test_labels = load_datasets.load_iris_dataset(
        knn_train_ratio)
    iris_knn = Knn(distance_func=distanceFunc)
    iris_knn.train(iris_train,
                   iris_train_labels,
                   findBestKWithCrossValidation=findBestKWithCrossValidation)
    cm, _, _, _ = iris_knn.test(iris_test, iris_test_labels)
    ConfusionMatrixListKnn.append(cm)

    print(
        f"\n --- Elapse time: {1_000*(time.time() - startTime):.2f} ms --- \n")

    print('-' * 175)
    print(f"Congressional dataset classification: \n")
    startTime = time.time()

    #  Entrainement sur l'ensemble de données Congressional

    cong_train, cong_train_labels, cong_test, cong_test_labels = load_datasets.load_congressional_dataset(
        knn_train_ratio)
    cong_knn = Knn(distance_func=distanceFunc)
    cong_knn.train(cong_train,
print('MONK 2')
knn_monks_2.train(monks_train_2, monks_train_labels_2)
print('')
print('MONK 3')
knn_monks_3.train(monks_train_3, monks_train_labels_3)

# Testez votre classifieur KNN

print('--------------------')
print('IRIS DATASET TEST')
print('--------------------')
k_optimal = knn_iris.get_optimal_k(kmin=1, kmax=6)
#print('-------Performance générales sur les données de test---------')
knn_iris.set_nbNeighbors(k_optimal)
print('Running now on test data with k = ', k_optimal)
knn_iris.test(iris_test, iris_test_labels)

print('--------------------')
print('VOTE DATASET TEST')
print('--------------------')
k_optimal = knn_vote.get_optimal_k(kmin=1, kmax=6)
#print('-------Performance générales sur les données de test---------')
knn_vote.set_nbNeighbors(k_optimal)
print('Running now on test data with k = ', k_optimal)
knn_vote.test(congressional_test, congressional_test_labels)

print('--------------------')
print('MONKS DATASET TEST')
print('--------------------')
print('')
print('MONK 1')