From a4990be99025f31c0f7cf0a7c3013a0bbff82ffa Mon Sep 17 00:00:00 2001 From: Quentin Fortier Date: Fri, 15 Dec 2023 15:22:08 +0100 Subject: [PATCH] Add knn_iris.ipynb --- .../cours/knn/exemple/knn_iris.ipynb | 51 +++++++++++++++++++ 1 file changed, 51 insertions(+) diff --git a/files/dl/apprentissage/cours/knn/exemple/knn_iris.ipynb b/files/dl/apprentissage/cours/knn/exemple/knn_iris.ipynb index 2c650ff7..782d1646 100644 --- a/files/dl/apprentissage/cours/knn/exemple/knn_iris.ipynb +++ b/files/dl/apprentissage/cours/knn/exemple/knn_iris.ipynb @@ -30,6 +30,46 @@ "
" ] }, + { + "cell_type": "code", + "execution_count": 5, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "[0 0 1 2 1 2 1 0 0 0 2 0 0 0 0 1 0 0 1 1 0 0 1 1 0 1 1 0 0 1 2 0 1 0 2 0 1\n", + " 0 0 0 2 1 2 1 1 0 2 2 0 2 0 2 0 0 0 0 0 0 0 2 0 1 0 0 0 0 0 2 1 1 2 0 1 1\n", + " 2]\n" + ] + }, + { + "data": { + "text/plain": [ + "array([2, 1, 0, 2, 0, 2, 0, 1, 1, 1, 2, 1, 1, 1, 1, 0, 1, 1, 0, 0, 2, 1,\n", + " 0, 0, 2, 0, 0, 1, 1, 0, 2, 1, 0, 2, 2, 1, 0, 1, 1, 1, 2, 0, 2, 0,\n", + " 0, 1, 2, 2, 2, 2, 1, 2, 1, 1, 2, 2, 2, 2, 1, 2, 1, 0, 2, 1, 1, 1,\n", + " 1, 2, 0, 0, 2, 1, 0, 0, 1])" + ] + }, + "execution_count": 5, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "from sklearn.model_selection import train_test_split # pour séparer les données en train et test\n", + "\n", + "X_train, X_test, Y_train, Y_test = train_test_split(iris.data, iris.target, test_size=0.5, shuffle=True, random_state=0)\n", + "\n", + "from sklearn.cluster import KMeans\n", + "kmeans = KMeans(n_clusters=3, random_state=0).fit(X_train)\n", + "Y_pred = kmeans.predict(X_test)\n", + "print(Y_pred)\n", + "Y_test" + ] + }, { "attachments": {}, "cell_type": "markdown", @@ -183,6 +223,17 @@ "plt.show()\n" ] }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "from sklearn.model_selection import train_test_split # pour séparer les données en train et test\n", + "\n", + "X_train, X_test, Y_train, Y_test = train_test_split(iris.data, iris.target, test_size=0.5, shuffle=True, random_state=0)" + ] + }, { "cell_type": "markdown", "metadata": {},