diff --git a/TP1/knn_vrai.py b/TP1/KNN.py similarity index 67% rename from TP1/knn_vrai.py rename to TP1/KNN.py index 0b18ce1..2c859f2 100644 --- a/TP1/knn_vrai.py +++ b/TP1/KNN.py @@ -1,11 +1,13 @@ #!/usr/bin/env python3 # -*- coding: utf-8 -*- """ -Created on Sat Dec 11 15:40:46 2021 +Created on Wed Dec 15 19:07:59 2021 @author: chouiya """ + + from time import time import numpy as np @@ -105,52 +107,4 @@ for s in change_percent: - - - - - - -#*******************Variation de la taille de l'echantillon training ***************** - -tab_sample=[5000,6000,8000,10000,20000,50000,70000] -for x in range(len(tab_sample)): - index= np.random.randint(70000, size=tab_sample[x]) - data = mnist.data[index] - target = mnist.target[index] - clf = neighbors.KNeighborsClassifier(10) - xtrain, xtest, ytrain, ytest = train_test_split(data, target, train_size=0.8) - clf.fit(xtrain,ytrain) - prediction = clf.predict(xtest) - score = clf.score(xtest, ytest) - - print("sample size= {} , accuracy = {} ".format(tab_sample[x], score)) - -#*****************Variation du type de la distance p ******* -xtrain, xtest, ytrain, ytest = train_test_split(data, target, train_size=0.8, test_size=0.2) - -for i in range(0,3): - - tab_dist=["manhattan","euclidean", "minkowski"] - - - clf = neighbors.KNeighborsClassifier(10, p=(i+1)) - clf.fit(xtrain,ytrain) - prediction = clf.predict(xtrain) - score = clf.score(xtrain, ytrain) - print("type de distance : {}, Score: {}".format(tab_dist[i], score)) - - -# ************** fixer n_jobs à 1 puis à -1 ********** - - -for i in [-1,1]: - clf = neighbors.KNeighborsClassifier(5,n_jobs=i) - clf.fit(xtrain, ytrain) - time_start = time() - prediction = clf.predict(xtest) - time_stop = time() - score = clf.score(xtest, ytest) - print("n_jobs : {}, Temps total : {}".format(i,time_stop-time_start)) - - + \ No newline at end of file diff --git a/np b/np new file mode 100644 index 0000000..e69de29