mirror of
https://github.com/ArthurDanjou/breast-cancer-detection.git
synced 2026-01-14 11:54:10 +01:00
Change on cross validation
This commit is contained in:
20
knn.ipynb
20
knn.ipynb
@@ -2,7 +2,7 @@
|
||||
"cells": [
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 26,
|
||||
"execution_count": 35,
|
||||
"id": "4e6f6cb1",
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
@@ -20,7 +20,7 @@
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 3,
|
||||
"execution_count": 36,
|
||||
"id": "4dd5223b",
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
@@ -31,7 +31,7 @@
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 29,
|
||||
"execution_count": 37,
|
||||
"id": "c1ab7ec9",
|
||||
"metadata": {},
|
||||
"outputs": [
|
||||
@@ -89,7 +89,7 @@
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 30,
|
||||
"execution_count": 38,
|
||||
"id": "754dce9b",
|
||||
"metadata": {},
|
||||
"outputs": [
|
||||
@@ -117,7 +117,7 @@
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 31,
|
||||
"execution_count": 43,
|
||||
"id": "feb42adf",
|
||||
"metadata": {},
|
||||
"outputs": [
|
||||
@@ -125,19 +125,17 @@
|
||||
"name": "stdout",
|
||||
"output_type": "stream",
|
||||
"text": [
|
||||
"The best k for k-NN is k = 5\n"
|
||||
"The best k for k-NN is k = 6\n"
|
||||
]
|
||||
}
|
||||
],
|
||||
"source": [
|
||||
"k_scores = []\n",
|
||||
"K_list = np.arange(1, X.shape[0] // 4) # concidering 1/4 of the samples as neaighbors is large enough for k-NN to don't overfit\n",
|
||||
"K_list = np.arange(1, X.shape[0] // 4 ) # concidering 1/4 of the samples as neaighbors is large enough for k-NN to don't overfit\n",
|
||||
"\n",
|
||||
"for k in K_list:\n",
|
||||
" knn = KNeighborsClassifier(n_neighbors=k)\n",
|
||||
" score_acc = cross_val_score(knn, X, y, cv=5, scoring='accuracy')\n",
|
||||
" score_f1 = cross_val_score(knn, X, y, cv=5, scoring='f1')\n",
|
||||
" score = (score_acc + score_f1) / 2 \n",
|
||||
" score = cross_val_score(knn, X, y, cv=5, scoring='accuracy')\n",
|
||||
" k_scores.append(score.mean())\n",
|
||||
"\n",
|
||||
"k_scores = np.array(k_scores)\n",
|
||||
@@ -147,7 +145,7 @@
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 34,
|
||||
"execution_count": 40,
|
||||
"id": "fa8a7166",
|
||||
"metadata": {},
|
||||
"outputs": [
|
||||
|
||||
Reference in New Issue
Block a user