From 044f875728a732c0d3ae4ba0656b0aba63721446 Mon Sep 17 00:00:00 2001 From: AntoninDurousseau Date: Tue, 3 Jun 2025 13:10:06 +0200 Subject: [PATCH] Change on cross validation --- knn.ipynb | 20 +++++++++----------- 1 file changed, 9 insertions(+), 11 deletions(-) diff --git a/knn.ipynb b/knn.ipynb index 0bb1d45..1846ab8 100644 --- a/knn.ipynb +++ b/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": [