From 7761b8335d3b0f141697ea48ab1c39a1b644880a Mon Sep 17 00:00:00 2001 From: =?utf8?q?J=C3=A9r=C3=B4me=20Benoit?= Date: Tue, 13 Nov 2018 21:46:59 +0100 Subject: [PATCH] Add TP1 exo2 implementation (question 1). MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit Signed-off-by: Jérôme Benoit --- TP1/exo2/TP1prog2.py | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) create mode 100755 TP1/exo2/TP1prog2.py diff --git a/TP1/exo2/TP1prog2.py b/TP1/exo2/TP1prog2.py new file mode 100755 index 0000000..7808974 --- /dev/null +++ b/TP1/exo2/TP1prog2.py @@ -0,0 +1,24 @@ +#!/usr/bin/env python3 + +# -*- coding: utf-8 -*- +from sklearn import neighbors +from sklearn.datasets import load_iris +irisData = load_iris() + +X = irisData.data +Y = irisData.target + +colors = ["red", "green", "blue"] + +nb_voisins = 15 +clf = neighbors.KNeighborsClassifier(nb_voisins) +clf.fit(X, Y) +print("kNN prediction on [5.4, 3.2, 1.6, 0.4]:") +print(clf.predict([[5.4, 3.2, 1.6, 0.4]])) +print("kNN probability prediction on [5.4, 3.2, 1.6, 0.4]:") +print(clf.predict_proba([[5.4, 3.2, 1.6, 0.4]])) +print("kNN score on Iris data:") +print(clf.score(X, Y)) +print("kNN prediction error(s) on Iris data:") +Z = clf.predict(X) +print(X[Z != Y]) -- 2.34.1