maalouf imad commited on
Update notebooks/TP1_Titanic_Survival.ipynb
Browse files
notebooks/TP1_Titanic_Survival.ipynb
CHANGED
|
@@ -4,7 +4,7 @@
|
|
| 4 |
"cell_type": "markdown",
|
| 5 |
"metadata": {},
|
| 6 |
"source": [
|
| 7 |
-
"#
|
| 8 |
"\n",
|
| 9 |
"**Objectif** : Prédire la survie des passagers du Titanic à partir de leurs caractéristiques.\n",
|
| 10 |
"\n",
|
|
@@ -21,7 +21,7 @@
|
|
| 21 |
"cell_type": "markdown",
|
| 22 |
"metadata": {},
|
| 23 |
"source": [
|
| 24 |
-
"##
|
| 25 |
"\n",
|
| 26 |
"1. [Import des bibliothèques](#section-1)\n",
|
| 27 |
"2. [Chargement et exploration des données](#section-2)\n",
|
|
@@ -86,7 +86,7 @@
|
|
| 86 |
"train_df = pd.read_csv('https://raw.githubusercontent.com/datasciencedojo/datasets/master/titanic.csv')\n",
|
| 87 |
"\n",
|
| 88 |
"print(f\"📊 Dimensions du dataset : {train_df.shape}\")\n",
|
| 89 |
-
"print(f\"\\n
|
| 90 |
]
|
| 91 |
},
|
| 92 |
{
|
|
@@ -134,7 +134,7 @@
|
|
| 134 |
" 'Pourcentage': missing_percent\n",
|
| 135 |
"}).sort_values('Pourcentage', ascending=False)\n",
|
| 136 |
"\n",
|
| 137 |
-
"print(\"
|
| 138 |
"print(missing_df[missing_df['Valeurs manquantes'] > 0])"
|
| 139 |
]
|
| 140 |
},
|
|
@@ -332,7 +332,7 @@
|
|
| 332 |
"lr_pred = lr_model.predict(X_test)\n",
|
| 333 |
"lr_accuracy = accuracy_score(y_test, lr_pred)\n",
|
| 334 |
"\n",
|
| 335 |
-
"print(f\"
|
| 336 |
]
|
| 337 |
},
|
| 338 |
{
|
|
@@ -377,7 +377,7 @@
|
|
| 377 |
" n_jobs=-1\n",
|
| 378 |
")\n",
|
| 379 |
"\n",
|
| 380 |
-
"print(\"
|
| 381 |
"grid_search.fit(X_train, y_train)\n",
|
| 382 |
"\n",
|
| 383 |
"print(f\"\\n✅ Meilleurs paramètres : {grid_search.best_params_}\")\n",
|
|
@@ -402,7 +402,7 @@
|
|
| 402 |
"best_model = grid_search.best_estimator_\n",
|
| 403 |
"best_pred = best_model.predict(X_test)\n",
|
| 404 |
"\n",
|
| 405 |
-
"print(\"
|
| 406 |
"print(classification_report(y_test, best_pred, target_names=['Non survécu', 'Survécu']))"
|
| 407 |
]
|
| 408 |
},
|
|
@@ -454,7 +454,7 @@
|
|
| 454 |
"# Cross-validation finale\n",
|
| 455 |
"cv_scores = cross_val_score(best_model, X, y, cv=5, scoring='accuracy')\n",
|
| 456 |
"\n",
|
| 457 |
-
"print(f\"
|
| 458 |
"print(f\" Mean accuracy : {cv_scores.mean():.4f}\")\n",
|
| 459 |
"print(f\" Std accuracy : {cv_scores.std():.4f}\")\n",
|
| 460 |
"print(f\" Scores : {cv_scores}\")"
|
|
@@ -464,7 +464,7 @@
|
|
| 464 |
"cell_type": "markdown",
|
| 465 |
"metadata": {},
|
| 466 |
"source": [
|
| 467 |
-
"##
|
| 468 |
"\n",
|
| 469 |
"Dans ce TP, nous avons :\n",
|
| 470 |
"\n",
|
|
|
|
| 4 |
"cell_type": "markdown",
|
| 5 |
"metadata": {},
|
| 6 |
"source": [
|
| 7 |
+
"# TP-1 : Survie sur le Titanic — Classification\n",
|
| 8 |
"\n",
|
| 9 |
"**Objectif** : Prédire la survie des passagers du Titanic à partir de leurs caractéristiques.\n",
|
| 10 |
"\n",
|
|
|
|
| 21 |
"cell_type": "markdown",
|
| 22 |
"metadata": {},
|
| 23 |
"source": [
|
| 24 |
+
"## Table des matières\n",
|
| 25 |
"\n",
|
| 26 |
"1. [Import des bibliothèques](#section-1)\n",
|
| 27 |
"2. [Chargement et exploration des données](#section-2)\n",
|
|
|
|
| 86 |
"train_df = pd.read_csv('https://raw.githubusercontent.com/datasciencedojo/datasets/master/titanic.csv')\n",
|
| 87 |
"\n",
|
| 88 |
"print(f\"📊 Dimensions du dataset : {train_df.shape}\")\n",
|
| 89 |
+
"print(f\"\\n Colonnes : {list(train_df.columns)}\")"
|
| 90 |
]
|
| 91 |
},
|
| 92 |
{
|
|
|
|
| 134 |
" 'Pourcentage': missing_percent\n",
|
| 135 |
"}).sort_values('Pourcentage', ascending=False)\n",
|
| 136 |
"\n",
|
| 137 |
+
"print(\"Valeurs manquantes :\")\n",
|
| 138 |
"print(missing_df[missing_df['Valeurs manquantes'] > 0])"
|
| 139 |
]
|
| 140 |
},
|
|
|
|
| 332 |
"lr_pred = lr_model.predict(X_test)\n",
|
| 333 |
"lr_accuracy = accuracy_score(y_test, lr_pred)\n",
|
| 334 |
"\n",
|
| 335 |
+
"print(f\" Régression Logistique - Accuracy : {lr_accuracy:.4f}\")"
|
| 336 |
]
|
| 337 |
},
|
| 338 |
{
|
|
|
|
| 377 |
" n_jobs=-1\n",
|
| 378 |
")\n",
|
| 379 |
"\n",
|
| 380 |
+
"print(\" Optimisation en cours...\")\n",
|
| 381 |
"grid_search.fit(X_train, y_train)\n",
|
| 382 |
"\n",
|
| 383 |
"print(f\"\\n✅ Meilleurs paramètres : {grid_search.best_params_}\")\n",
|
|
|
|
| 402 |
"best_model = grid_search.best_estimator_\n",
|
| 403 |
"best_pred = best_model.predict(X_test)\n",
|
| 404 |
"\n",
|
| 405 |
+
"print(\" Rapport de classification :\")\n",
|
| 406 |
"print(classification_report(y_test, best_pred, target_names=['Non survécu', 'Survécu']))"
|
| 407 |
]
|
| 408 |
},
|
|
|
|
| 454 |
"# Cross-validation finale\n",
|
| 455 |
"cv_scores = cross_val_score(best_model, X, y, cv=5, scoring='accuracy')\n",
|
| 456 |
"\n",
|
| 457 |
+
"print(f\" Cross-validation (5-fold) :\")\n",
|
| 458 |
"print(f\" Mean accuracy : {cv_scores.mean():.4f}\")\n",
|
| 459 |
"print(f\" Std accuracy : {cv_scores.std():.4f}\")\n",
|
| 460 |
"print(f\" Scores : {cv_scores}\")"
|
|
|
|
| 464 |
"cell_type": "markdown",
|
| 465 |
"metadata": {},
|
| 466 |
"source": [
|
| 467 |
+
"## Conclusion\n",
|
| 468 |
"\n",
|
| 469 |
"Dans ce TP, nous avons :\n",
|
| 470 |
"\n",
|