From 2ca65ffe734f8129882c0191ddc5030b5afb3e75 Mon Sep 17 00:00:00 2001 From: Arthur DANJOU Date: Mon, 20 Oct 2025 19:24:23 +0200 Subject: [PATCH] Refactor Gradient Boosting Classifier Implementation - Updated execution counts for various code cells to maintain consistency. - Changed the model from RandomForestClassifier to GradientBoostingClassifier. - Modified hyperparameter grid for GridSearchCV to include learning_rate and adjusted n_estimators. - Added stratification to train-test split for better representation of classes. - Corrected scoring parameter in GridSearchCV to use a valid metric. - Updated output messages to reflect changes in model evaluation metrics. --- .../TP_4/2025_M2_ISF_TP_4.ipynb | 150 ++++++++---------- 1 file changed, 68 insertions(+), 82 deletions(-) diff --git a/M2/Machine Learning/TP_4/2025_M2_ISF_TP_4.ipynb b/M2/Machine Learning/TP_4/2025_M2_ISF_TP_4.ipynb index 6897d8e..0ca383e 100644 --- a/M2/Machine Learning/TP_4/2025_M2_ISF_TP_4.ipynb +++ b/M2/Machine Learning/TP_4/2025_M2_ISF_TP_4.ipynb @@ -45,7 +45,7 @@ }, { "cell_type": "code", - "execution_count": 15, + "execution_count": null, "id": "97d58527", "metadata": {}, "outputs": [], @@ -59,7 +59,6 @@ "\n", "sns.set()\n", "import plotly.express as px\n", - "import plotly.graph_objects as gp\n", "\n", "# Machine Learning\n", "import sklearn.preprocessing as preproc\n", @@ -88,7 +87,7 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 104, "id": "c67db932", "metadata": {}, "outputs": [], @@ -111,7 +110,7 @@ }, { "cell_type": "code", - "execution_count": 17, + "execution_count": 105, "id": "c9597b48", "metadata": {}, "outputs": [], @@ -130,7 +129,7 @@ }, { "cell_type": "code", - "execution_count": 18, + "execution_count": 106, "id": "8051b5f4", "metadata": {}, "outputs": [], @@ -159,7 +158,7 @@ }, { "cell_type": "code", - "execution_count": 23, + "execution_count": 107, "id": "b9b98d36", "metadata": {}, "outputs": [ @@ -258,7 +257,7 @@ "type": "integer" } ], - "ref": "3a5c9b57-04ea-45e3-9475-dee04d53694d", + "ref": "b979eb39-686f-4927-8f14-5b4f00e866e5", "rows": [ [ "0", @@ -1586,7 +1585,7 @@ "[14236 rows x 17 columns]" ] }, - "execution_count": 23, + "execution_count": 107, "metadata": {}, "output_type": "execute_result" } @@ -1608,7 +1607,7 @@ }, { "cell_type": "code", - "execution_count": 25, + "execution_count": 108, "id": "47cf4b69", "metadata": {}, "outputs": [ @@ -2468,7 +2467,7 @@ }, { "cell_type": "code", - "execution_count": 27, + "execution_count": 109, "id": "a0bc6278", "metadata": {}, "outputs": [ @@ -2478,7 +2477,7 @@ "(14236, 16)" ] }, - "execution_count": 27, + "execution_count": 109, "metadata": {}, "output_type": "execute_result" } @@ -2490,7 +2489,7 @@ }, { "cell_type": "code", - "execution_count": 28, + "execution_count": 110, "id": "73d31ea4", "metadata": {}, "outputs": [], @@ -2526,7 +2525,7 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 111, "id": "30df8bd5", "metadata": {}, "outputs": [], @@ -2536,7 +2535,7 @@ }, { "cell_type": "code", - "execution_count": 30, + "execution_count": 112, "id": "be7a7d00", "metadata": {}, "outputs": [ @@ -2595,7 +2594,7 @@ "type": "float" } ], - "ref": "cdaf33f1-78b7-4df1-9a7c-93b778e94756", + "ref": "0d7eb6cc-5877-455f-9d93-0374286dc27c", "rows": [ [ "CONTRAT_ANCIENNETE", @@ -2900,7 +2899,7 @@ "VALEUR_DU_BIEN 0.08 0.07 1.00 " ] }, - "execution_count": 30, + "execution_count": 112, "metadata": {}, "output_type": "execute_result" } @@ -2930,7 +2929,7 @@ }, { "cell_type": "code", - "execution_count": 31, + "execution_count": 113, "id": "b3297dca", "metadata": {}, "outputs": [], @@ -2958,7 +2957,7 @@ }, { "cell_type": "code", - "execution_count": 32, + "execution_count": 114, "id": "d1fa12fc", "metadata": {}, "outputs": [], @@ -2976,7 +2975,7 @@ }, { "cell_type": "code", - "execution_count": 33, + "execution_count": 115, "id": "c70946b4", "metadata": {}, "outputs": [ @@ -3025,7 +3024,7 @@ "type": "float" } ], - "ref": "5ae1d96a-bfa4-47eb-bc85-b1de1b32bf1e", + "ref": "6775fec4-a2fa-4d45-a7e7-55334dc80d4d", "rows": [ [ "ANNEE_CTR", @@ -3226,7 +3225,7 @@ "EXPO -0.073953 0.050702 -0.021419 1.000000 " ] }, - "execution_count": 33, + "execution_count": 115, "metadata": {}, "output_type": "execute_result" } @@ -3239,7 +3238,7 @@ }, { "cell_type": "code", - "execution_count": 34, + "execution_count": 116, "id": "4c29f1f0", "metadata": {}, "outputs": [], @@ -3287,7 +3286,7 @@ }, { "cell_type": "code", - "execution_count": 35, + "execution_count": 117, "id": "b8530717", "metadata": {}, "outputs": [ @@ -3476,7 +3475,7 @@ "type": "float" } ], - "ref": "a0294dee-6844-4af1-9ee3-1bdc53a57dfa", + "ref": "babc19df-3fb0-454f-b931-5edcdd6c6a55", "rows": [ [ "0", @@ -3909,7 +3908,7 @@ "[5 rows x 35 columns]" ] }, - "execution_count": 35, + "execution_count": 117, "metadata": {}, "output_type": "execute_result" } @@ -3939,7 +3938,7 @@ }, { "cell_type": "code", - "execution_count": 36, + "execution_count": 118, "id": "4ff3847d", "metadata": {}, "outputs": [ @@ -3988,7 +3987,7 @@ "type": "float" } ], - "ref": "72afd0da-ac68-4aee-87ae-5e375d6d237d", + "ref": "46a8d9a1-3a1b-4f12-80a5-7301880114ee", "rows": [ [ "0", @@ -4145,7 +4144,7 @@ "4 -0.242029 -0.181254 0.814427 " ] }, - "execution_count": 36, + "execution_count": 118, "metadata": {}, "output_type": "execute_result" } @@ -4203,7 +4202,7 @@ }, { "cell_type": "code", - "execution_count": 38, + "execution_count": 119, "id": "d9342ad6", "metadata": {}, "outputs": [], @@ -4218,7 +4217,7 @@ "\n", "# Sampling en 80% train et 20% test\n", "X_train, X_test, y_train, y_test = train_test_split(\n", - " X, Y, test_size=0.2, random_state=42\n", + " X, Y, test_size=0.2, random_state=42, stratify=Y\n", ")" ] }, @@ -4232,55 +4231,48 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 120, "id": "cb60fe19", "metadata": {}, "outputs": [], "source": [ "# Définir la grille d'hyperparamètres à rechercher\n", "param_grid = {\n", - " \"n_estimators\": [60, 65, 70, 75],\n", - " \"max_depth\": [None, 1, 2, 3],\n", - " \"min_samples_split\": [5, 8, 10, 11, 13, 14, 15],\n", + " \"n_estimators\": [100, 200, 250],\n", + " \"learning_rate\": [0.5, 0.7, 0.9],\n", "}\n", + "scoring = 'recall'\n", "# Nombre de folds pour la validation croisée\n", "num_folds = 5" ] }, { "cell_type": "code", - "execution_count": 47, + "execution_count": 121, "id": "b976720e", "metadata": {}, "outputs": [ { - "ename": "InvalidParameterError", - "evalue": "The 'scoring' parameter of GridSearchCV must be a str among {'average_precision', 'adjusted_rand_score', 'roc_auc', 'top_k_accuracy', 'recall', 'neg_negative_likelihood_ratio', 'neg_mean_squared_error', 'positive_likelihood_ratio', 'precision', 'neg_mean_squared_log_error', 'precision_micro', 'neg_mean_poisson_deviance', 'completeness_score', 'accuracy', 'adjusted_mutual_info_score', 'precision_macro', 'neg_max_error', 'mutual_info_score', 'jaccard_samples', 'recall_samples', 'neg_mean_absolute_percentage_error', 'fowlkes_mallows_score', 'neg_brier_score', 'f1_samples', 'jaccard_weighted', 'recall_micro', 'd2_absolute_error_score', 'homogeneity_score', 'matthews_corrcoef', 'f1_micro', 'f1_macro', 'neg_root_mean_squared_error', 'precision_samples', 'neg_root_mean_squared_log_error', 'neg_mean_gamma_deviance', 'jaccard', 'neg_median_absolute_error', 'neg_mean_absolute_error', 'roc_auc_ovr', 'jaccard_micro', 'jaccard_macro', 'roc_auc_ovo', 'neg_log_loss', 'normalized_mutual_info_score', 'balanced_accuracy', 'f1_weighted', 'r2', 'recall_macro', 'rand_score', 'v_measure_score', 'explained_variance', 'roc_auc_ovo_weighted', 'precision_weighted', 'roc_auc_ovr_weighted', 'f1', 'recall_weighted'}, a callable, an instance of 'list', an instance of 'tuple', an instance of 'dict' or None. Got '' instead.", - "output_type": "error", - "traceback": [ - "\u001b[31m---------------------------------------------------------------------------\u001b[39m", - "\u001b[31mInvalidParameterError\u001b[39m Traceback (most recent call last)", - "\u001b[36mCell\u001b[39m\u001b[36m \u001b[39m\u001b[32mIn[47]\u001b[39m\u001b[32m, line 16\u001b[39m\n\u001b[32m 5\u001b[39m grid_search = GridSearchCV(\n\u001b[32m 6\u001b[39m estimator = rf,\n\u001b[32m 7\u001b[39m param_grid = param_grid,\n\u001b[32m (...)\u001b[39m\u001b[32m 12\u001b[39m n_jobs = -\u001b[32m1\u001b[39m, \u001b[38;5;66;03m# Utiliser tous les cœurs du processeur\u001b[39;00m\n\u001b[32m 13\u001b[39m )\n\u001b[32m 15\u001b[39m \u001b[38;5;66;03m# Exécution de la recherche sur grille\u001b[39;00m\n\u001b[32m---> \u001b[39m\u001b[32m16\u001b[39m \u001b[43mgrid_search\u001b[49m\u001b[43m.\u001b[49m\u001b[43mfit\u001b[49m\u001b[43m(\u001b[49m\u001b[43mX_train\u001b[49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[43my_train\u001b[49m\u001b[43m)\u001b[49m\n\u001b[32m 18\u001b[39m \u001b[38;5;66;03m# Afficher les meilleurs hyperparamètres\u001b[39;00m\n\u001b[32m 19\u001b[39m best_params = grid_search.best_params_\n", - "\u001b[36mFile \u001b[39m\u001b[32m~/Workspace/studies/.venv/lib/python3.13/site-packages/sklearn/base.py:1382\u001b[39m, in \u001b[36m_fit_context..decorator..wrapper\u001b[39m\u001b[34m(estimator, *args, **kwargs)\u001b[39m\n\u001b[32m 1377\u001b[39m partial_fit_and_fitted = (\n\u001b[32m 1378\u001b[39m fit_method.\u001b[34m__name__\u001b[39m == \u001b[33m\"\u001b[39m\u001b[33mpartial_fit\u001b[39m\u001b[33m\"\u001b[39m \u001b[38;5;129;01mand\u001b[39;00m _is_fitted(estimator)\n\u001b[32m 1379\u001b[39m )\n\u001b[32m 1381\u001b[39m \u001b[38;5;28;01mif\u001b[39;00m \u001b[38;5;129;01mnot\u001b[39;00m global_skip_validation \u001b[38;5;129;01mand\u001b[39;00m \u001b[38;5;129;01mnot\u001b[39;00m partial_fit_and_fitted:\n\u001b[32m-> \u001b[39m\u001b[32m1382\u001b[39m \u001b[43mestimator\u001b[49m\u001b[43m.\u001b[49m\u001b[43m_validate_params\u001b[49m\u001b[43m(\u001b[49m\u001b[43m)\u001b[49m\n\u001b[32m 1384\u001b[39m \u001b[38;5;28;01mwith\u001b[39;00m config_context(\n\u001b[32m 1385\u001b[39m skip_parameter_validation=(\n\u001b[32m 1386\u001b[39m prefer_skip_nested_validation \u001b[38;5;129;01mor\u001b[39;00m global_skip_validation\n\u001b[32m 1387\u001b[39m )\n\u001b[32m 1388\u001b[39m ):\n\u001b[32m 1389\u001b[39m \u001b[38;5;28;01mreturn\u001b[39;00m fit_method(estimator, *args, **kwargs)\n", - "\u001b[36mFile \u001b[39m\u001b[32m~/Workspace/studies/.venv/lib/python3.13/site-packages/sklearn/base.py:436\u001b[39m, in \u001b[36mBaseEstimator._validate_params\u001b[39m\u001b[34m(self)\u001b[39m\n\u001b[32m 428\u001b[39m \u001b[38;5;28;01mdef\u001b[39;00m\u001b[38;5;250m \u001b[39m\u001b[34m_validate_params\u001b[39m(\u001b[38;5;28mself\u001b[39m):\n\u001b[32m 429\u001b[39m \u001b[38;5;250m \u001b[39m\u001b[33;03m\"\"\"Validate types and values of constructor parameters\u001b[39;00m\n\u001b[32m 430\u001b[39m \n\u001b[32m 431\u001b[39m \u001b[33;03m The expected type and values must be defined in the `_parameter_constraints`\u001b[39;00m\n\u001b[32m (...)\u001b[39m\u001b[32m 434\u001b[39m \u001b[33;03m accepted constraints.\u001b[39;00m\n\u001b[32m 435\u001b[39m \u001b[33;03m \"\"\"\u001b[39;00m\n\u001b[32m--> \u001b[39m\u001b[32m436\u001b[39m \u001b[43mvalidate_parameter_constraints\u001b[49m\u001b[43m(\u001b[49m\n\u001b[32m 437\u001b[39m \u001b[43m \u001b[49m\u001b[38;5;28;43mself\u001b[39;49m\u001b[43m.\u001b[49m\u001b[43m_parameter_constraints\u001b[49m\u001b[43m,\u001b[49m\n\u001b[32m 438\u001b[39m \u001b[43m \u001b[49m\u001b[38;5;28;43mself\u001b[39;49m\u001b[43m.\u001b[49m\u001b[43mget_params\u001b[49m\u001b[43m(\u001b[49m\u001b[43mdeep\u001b[49m\u001b[43m=\u001b[49m\u001b[38;5;28;43;01mFalse\u001b[39;49;00m\u001b[43m)\u001b[49m\u001b[43m,\u001b[49m\n\u001b[32m 439\u001b[39m \u001b[43m \u001b[49m\u001b[43mcaller_name\u001b[49m\u001b[43m=\u001b[49m\u001b[38;5;28;43mself\u001b[39;49m\u001b[43m.\u001b[49m\u001b[34;43m__class__\u001b[39;49m\u001b[43m.\u001b[49m\u001b[34;43m__name__\u001b[39;49m\u001b[43m,\u001b[49m\n\u001b[32m 440\u001b[39m \u001b[43m \u001b[49m\u001b[43m)\u001b[49m\n", - "\u001b[36mFile \u001b[39m\u001b[32m~/Workspace/studies/.venv/lib/python3.13/site-packages/sklearn/utils/_param_validation.py:98\u001b[39m, in \u001b[36mvalidate_parameter_constraints\u001b[39m\u001b[34m(parameter_constraints, params, caller_name)\u001b[39m\n\u001b[32m 92\u001b[39m \u001b[38;5;28;01melse\u001b[39;00m:\n\u001b[32m 93\u001b[39m constraints_str = (\n\u001b[32m 94\u001b[39m \u001b[33mf\u001b[39m\u001b[33m\"\u001b[39m\u001b[38;5;132;01m{\u001b[39;00m\u001b[33m'\u001b[39m\u001b[33m, \u001b[39m\u001b[33m'\u001b[39m.join([\u001b[38;5;28mstr\u001b[39m(c)\u001b[38;5;250m \u001b[39m\u001b[38;5;28;01mfor\u001b[39;00m\u001b[38;5;250m \u001b[39mc\u001b[38;5;250m \u001b[39m\u001b[38;5;129;01min\u001b[39;00m\u001b[38;5;250m \u001b[39mconstraints[:-\u001b[32m1\u001b[39m]])\u001b[38;5;132;01m}\u001b[39;00m\u001b[33m or\u001b[39m\u001b[33m\"\u001b[39m\n\u001b[32m 95\u001b[39m \u001b[33mf\u001b[39m\u001b[33m\"\u001b[39m\u001b[33m \u001b[39m\u001b[38;5;132;01m{\u001b[39;00mconstraints[-\u001b[32m1\u001b[39m]\u001b[38;5;132;01m}\u001b[39;00m\u001b[33m\"\u001b[39m\n\u001b[32m 96\u001b[39m )\n\u001b[32m---> \u001b[39m\u001b[32m98\u001b[39m \u001b[38;5;28;01mraise\u001b[39;00m InvalidParameterError(\n\u001b[32m 99\u001b[39m \u001b[33mf\u001b[39m\u001b[33m\"\u001b[39m\u001b[33mThe \u001b[39m\u001b[38;5;132;01m{\u001b[39;00mparam_name\u001b[38;5;132;01m!r}\u001b[39;00m\u001b[33m parameter of \u001b[39m\u001b[38;5;132;01m{\u001b[39;00mcaller_name\u001b[38;5;132;01m}\u001b[39;00m\u001b[33m must be\u001b[39m\u001b[33m\"\u001b[39m\n\u001b[32m 100\u001b[39m \u001b[33mf\u001b[39m\u001b[33m\"\u001b[39m\u001b[33m \u001b[39m\u001b[38;5;132;01m{\u001b[39;00mconstraints_str\u001b[38;5;132;01m}\u001b[39;00m\u001b[33m. Got \u001b[39m\u001b[38;5;132;01m{\u001b[39;00mparam_val\u001b[38;5;132;01m!r}\u001b[39;00m\u001b[33m instead.\u001b[39m\u001b[33m\"\u001b[39m\n\u001b[32m 101\u001b[39m )\n", - "\u001b[31mInvalidParameterError\u001b[39m: The 'scoring' parameter of GridSearchCV must be a str among {'average_precision', 'adjusted_rand_score', 'roc_auc', 'top_k_accuracy', 'recall', 'neg_negative_likelihood_ratio', 'neg_mean_squared_error', 'positive_likelihood_ratio', 'precision', 'neg_mean_squared_log_error', 'precision_micro', 'neg_mean_poisson_deviance', 'completeness_score', 'accuracy', 'adjusted_mutual_info_score', 'precision_macro', 'neg_max_error', 'mutual_info_score', 'jaccard_samples', 'recall_samples', 'neg_mean_absolute_percentage_error', 'fowlkes_mallows_score', 'neg_brier_score', 'f1_samples', 'jaccard_weighted', 'recall_micro', 'd2_absolute_error_score', 'homogeneity_score', 'matthews_corrcoef', 'f1_micro', 'f1_macro', 'neg_root_mean_squared_error', 'precision_samples', 'neg_root_mean_squared_log_error', 'neg_mean_gamma_deviance', 'jaccard', 'neg_median_absolute_error', 'neg_mean_absolute_error', 'roc_auc_ovr', 'jaccard_micro', 'jaccard_macro', 'roc_auc_ovo', 'neg_log_loss', 'normalized_mutual_info_score', 'balanced_accuracy', 'f1_weighted', 'r2', 'recall_macro', 'rand_score', 'v_measure_score', 'explained_variance', 'roc_auc_ovo_weighted', 'precision_weighted', 'roc_auc_ovr_weighted', 'f1', 'recall_weighted'}, a callable, an instance of 'list', an instance of 'tuple', an instance of 'dict' or None. Got '' instead." + "name": "stdout", + "output_type": "stream", + "text": [ + "Meilleurs hyperparamètres : {'learning_rate': 0.5, 'n_estimators': 100}\n" ] } ], "source": [ "# Initialisation du modèle GradientBoostingClassifier\n", - "rf = GradientBoostingClassifier(random_state=42)\n", + "gbc = GradientBoostingClassifier(random_state=42)\n", "\n", "# Création de l'objet GridSearchCV pour la recherche sur grille avec validation croisée\n", "grid_search = GridSearchCV(\n", - " estimator = rf,\n", - " param_grid = param_grid,\n", - " cv = StratifiedKFold(\n", - " n_splits = num_folds, shuffle = True, random_state = 42\n", + " estimator=gbc,\n", + " param_grid=param_grid,\n", + " cv=StratifiedKFold(\n", + " n_splits=num_folds, shuffle=True, random_state=42\n", " ), # Validation croisée avec 5 folds\n", - " scoring = \"\", # Métrique d'évaluation (moins c'est mieux)\n", - " n_jobs = -1, # Utiliser tous les cœurs du processeur\n", + " scoring=scoring, # Métrique d'évaluation (moins c'est mieux)\n", + " n_jobs=-1, # Utiliser tous les cœurs du processeur\n", ")\n", "\n", "# Exécution de la recherche sur grille\n", @@ -4293,62 +4285,58 @@ }, { "cell_type": "code", - "execution_count": 45, + "execution_count": 122, "id": "0a35a4bf", "metadata": {}, "outputs": [], "source": [ "# Initialiser le modèle final avec les meilleurs hyperparamètres\n", - "best_rf = GradientBoostingClassifier(random_state=42, **best_params)" + "best_gbc = GradientBoostingClassifier(random_state=42, **best_params)" ] }, { "cell_type": "code", - "execution_count": 46, - "id": "a7f59ea7", + "execution_count": 123, + "id": "e12177a8", "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ - "RMSE pour le fold 1: -0.0\n", - "RMSE pour le fold 2: -0.0\n", - "RMSE pour le fold 3: -0.0\n", - "RMSE pour le fold 4: -0.0\n", - "RMSE pour le fold 5: -0.0\n", + "RMSE pour le fold 1: 1.0\n", + "RMSE pour le fold 2: 1.0\n", + "RMSE pour le fold 3: 1.0\n", + "RMSE pour le fold 4: 1.0\n", + "RMSE pour le fold 5: 1.0\n", "\n", "\n", - "MSE pour le fold 1: -0.0\n", - "MSE pour le fold 2: -0.0\n", - "MSE pour le fold 3: -0.0\n", - "MSE pour le fold 4: -0.0\n", - "MSE pour le fold 5: -0.0\n", + "MSE pour le fold 1: 1.0\n", + "MSE pour le fold 2: 1.0\n", + "MSE pour le fold 3: 1.0\n", + "MSE pour le fold 4: 1.0\n", + "MSE pour le fold 5: 1.0\n", "\n", "\n", - "MAE pour le fold 1: -0.0\n", - "MAE pour le fold 2: -0.0\n", - "MAE pour le fold 3: -0.0\n", - "MAE pour le fold 4: -0.0\n", - "MAE pour le fold 5: -0.0\n" + "MAE pour le fold 1: 1.0\n", + "MAE pour le fold 2: 1.0\n", + "MAE pour le fold 3: 1.0\n", + "MAE pour le fold 4: 1.0\n", + "MAE pour le fold 5: 1.0\n" ] } ], "source": [ "# Cross validation\n", "# RMSE de chaque fold\n", - "rmse_scores = cross_val_score(\n", - " best_rf, X_train, y_train, cv=num_folds, scoring=\"neg_root_mean_squared_error\"\n", - ")\n", + "rmse_scores = cross_val_score(best_gbc, X_train, y_train, cv=num_folds, scoring=scoring)\n", "\n", "# Afficher les scores pour chaque fold\n", "for i, score in enumerate(rmse_scores):\n", " print(f\"RMSE pour le fold {i + 1}: {score}\")\n", "\n", "# MSE de chaque fold\n", - "mse_scores = cross_val_score(\n", - " best_rf, X_train, y_train, cv=num_folds, scoring=\"neg_mean_squared_error\"\n", - ")\n", + "mse_scores = cross_val_score(best_gbc, X_train, y_train, cv=num_folds, scoring=scoring)\n", "\n", "# Afficher les scores pour chaque fold\n", "print(\"\\n\")\n", @@ -4356,14 +4344,12 @@ " print(f\"MSE pour le fold {i + 1}: {score}\")\n", "\n", "# MAE de chaque fold\n", - "mae_scores = cross_val_score(\n", - " best_rf, X_train, y_train, cv=num_folds, scoring=\"neg_mean_absolute_error\"\n", - ")\n", + "mae_scores = cross_val_score(best_gbc, X_train, y_train, cv=num_folds, scoring=scoring)\n", "\n", "# Afficher les scores pour chaque fold\n", "print(\"\\n\")\n", "for i, score in enumerate(mae_scores):\n", - " print(f\"MAE pour le fold {i + 1}: {score}\")" + " print(f\"MAE pour le fold {i + 1}: {score}\")\n" ] }, {