Skip to content

Commit

Permalink
Add knn_iris.ipynb
Browse files Browse the repository at this point in the history
  • Loading branch information
fortierq committed Dec 15, 2023
1 parent 45f1393 commit a4990be
Showing 1 changed file with 51 additions and 0 deletions.
51 changes: 51 additions & 0 deletions files/dl/apprentissage/cours/knn/exemple/knn_iris.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,46 @@
"<center><img src=https://raw.githubusercontent.com/cpge-itc/bcpst2/main/files/5_iris/iris.png width=60%></center>"
]
},
{
"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",
Expand Down Expand Up @@ -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": {},
Expand Down

0 comments on commit a4990be

Please sign in to comment.