mirror of
https://github.com/ArthurDanjou/breast-cancer-detection.git
synced 2026-01-14 15:54:14 +01:00
Add files via upload
This commit is contained in:
18
knn.ipynb
18
knn.ipynb
@@ -62,7 +62,7 @@
|
||||
" \n",
|
||||
"# data (as pandas dataframes) \n",
|
||||
"X = data.drop(columns='Classification')\n",
|
||||
"y = data['Classification'].map({2: 1, 1: 0}) # Map 2 to 1 and 1 to 0, 1 = pacient healthy, 0 = pacient sick\n",
|
||||
"y = data['Classification'].map({2: 1, 1: 0}) # Map 2 to 1 and 1 to 0, 1 = sick patient, 0 = healthy patient\n",
|
||||
" \n",
|
||||
"print(\"Dataset shape:\", data.shape)\n",
|
||||
"print(data.head())"
|
||||
@@ -81,7 +81,7 @@
|
||||
"id": "082c143b",
|
||||
"metadata": {},
|
||||
"source": [
|
||||
"### 1) No curse of dimention "
|
||||
"### 1) No curse of dimension "
|
||||
]
|
||||
},
|
||||
{
|
||||
@@ -111,7 +111,7 @@
|
||||
"id": "01bb817a",
|
||||
"metadata": {},
|
||||
"source": [
|
||||
"Then d is small enough to insure that we are not in the curse of dimention"
|
||||
"Then d is small enough to ensure that we do not suffer under the curse of dimension"
|
||||
]
|
||||
},
|
||||
{
|
||||
@@ -138,7 +138,7 @@
|
||||
],
|
||||
"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 ) # considering 1/4 of the samples as neighbors is large enough for k-NN not to overfit\n",
|
||||
"\n",
|
||||
"\n",
|
||||
"for k in K_list:\n",
|
||||
@@ -167,7 +167,7 @@
|
||||
"id": "9f74eaee",
|
||||
"metadata": {},
|
||||
"source": [
|
||||
"### 3) train-test split and rescaling of the feature "
|
||||
"### 3) train-test split and rescaling of the features"
|
||||
]
|
||||
},
|
||||
{
|
||||
@@ -205,7 +205,7 @@
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 7,
|
||||
"execution_count": 10,
|
||||
"id": "064a5aa7",
|
||||
"metadata": {},
|
||||
"outputs": [
|
||||
@@ -250,7 +250,7 @@
|
||||
}
|
||||
],
|
||||
"source": [
|
||||
"knn = KNeighborsClassifier(n_neighbors=k_optimal) # using the best k founded earlier\n",
|
||||
"knn = KNeighborsClassifier(n_neighbors=k_optimal) # using the best k found earlier\n",
|
||||
"knn.fit(X_train_scaled, y_train)\n",
|
||||
"\n",
|
||||
"y_pred = knn.predict(X_test_scaled)\n",
|
||||
@@ -267,7 +267,7 @@
|
||||
"print(\"Classification Report:\\n\", class_report)\n",
|
||||
"\n",
|
||||
"# Plotting the confusion matrix\n",
|
||||
"cm = confusion_matrix(y_test, y_pred)\n",
|
||||
"cm = confusion_matrix(y_true=y_test,y_pred= y_pred)\n",
|
||||
"plt.figure(figsize=(8, 6))\n",
|
||||
"plt.imshow(cm, interpolation='nearest', cmap=plt.cm.Blues)\n",
|
||||
"plt.title('Confusion Matrix')\n",
|
||||
@@ -321,7 +321,7 @@
|
||||
"name": "python",
|
||||
"nbconvert_exporter": "python",
|
||||
"pygments_lexer": "ipython3",
|
||||
"version": "3.11.9"
|
||||
"version": "3.9.6"
|
||||
}
|
||||
},
|
||||
"nbformat": 4,
|
||||
|
||||
Reference in New Issue
Block a user