--- /dev/null
+#!/usr/bin/env python3
+
+# -*- coding: utf-8 -*-
+from sklearn.cross_validation import KFold
+from sklearn import neighbors
+from sklearn.datasets import load_iris
+
+irisData = load_iris()
+X = irisData.data
+Y = irisData.target
+
+kf = KFold(len(X), n_folds=10, shuffle=True)
+
+scores = []
+for k in range(1, 30):
+ score = 0
+ clf = neighbors.KNeighborsClassifier(k)
+ for learn, test in kf:
+ X_train = [X[i] for i in learn]
+ Y_train = [Y[i] for i in learn]
+ clf.fit(X_train, Y_train)
+ X_test = [X[i] for i in test]
+ Y_test = [Y[i] for i in test]
+ score = score + clf.score(X_test, Y_test)
+ scores.append(score)
+
+print(scores)
+print("meilleure valeur pour k : ", scores.index(max(scores)) + 1)