{ "cells": [ { "cell_type": "code", "execution_count": 76, "id": "20554786", "metadata": {}, "outputs": [], "source": [ "import warnings\n", "warnings.filterwarnings('ignore')\n", "import numpy as np\n", "import pandas as pd\n", "from sklearn.metrics import classification_report,accuracy_score,confusion_matrix,f1_score,make_scorer\n", "from sklearn.tree import DecisionTreeClassifier\n", "from sklearn.ensemble import RandomForestClassifier,AdaBoostClassifier\n", "from sklearn.model_selection import train_test_split,RandomizedSearchCV,cross_val_score\n", "from sklearn.preprocessing import StandardScaler,MinMaxScaler\n", "from imblearn.combine import SMOTEENN\n", "from xgboost import XGBClassifier\n", "from imblearn.over_sampling import SMOTE,ADASYN\n", "from collections import Counter\n", "from catboost import CatBoostClassifier\n", "from lightgbm import LGBMClassifier\n", "import optuna\n", "import joblib\n" ] }, { "cell_type": "code", "execution_count": 63, "id": "dce34c3b", "metadata": {}, "outputs": [], "source": [ "model_dt=DecisionTreeClassifier()\n", "sc=StandardScaler()\n", "model_dt2=DecisionTreeClassifier()\n", "mms=MinMaxScaler()\n", "model_dt3=DecisionTreeClassifier()\n", "sm=SMOTEENN()\n", "model_dt_smotenn=DecisionTreeClassifier()\n", "model_rf_smoteenn=RandomForestClassifier(n_estimators=500)\n", "model_xgb=XGBClassifier(random_state=42)\n", "model_xgb_smoteenn=XGBClassifier(random_state=42)\n", "smote=SMOTE(random_state=42)\n", "model_xgb_smote=XGBClassifier(random_state=42)\n", "adasyn=ADASYN(random_state=42)\n", "model_xgb_adasyn=XGBClassifier(random_state=42)\n", "model_rf=RandomForestClassifier(\n", " class_weight='balanced',\n", " random_state=42,\n", " n_estimators=300,\n", " max_depth=6\n", ")\n", "model_cat=CatBoostClassifier(\n", " auto_class_weights='Balanced',\n", " verbose=0,\n", " random_state=42\n", ")\n", "model_ada_weighted=AdaBoostClassifier(\n", " n_estimators=50,\n", " random_state=42\n", ")" ] }, { "cell_type": "code", "execution_count": 3, "id": "61543d98", "metadata": {}, "outputs": [], "source": [ "df=pd.read_csv('../Data/Customer-Churn.csv')" ] }, { "cell_type": "code", "execution_count": 4, "id": "68c48dcd", "metadata": {}, "outputs": [ { "data": { "text/html": [ "
\n", "\n", "\n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", "
customerIDgenderSeniorCitizenPartnerDependentstenurePhoneServiceMultipleLinesInternetServiceOnlineSecurity...DeviceProtectionTechSupportStreamingTVStreamingMoviesContractPaperlessBillingPaymentMethodMonthlyChargesTotalChargesChurn
07590-VHVEGFemale0YesNo1NoNo phone serviceDSLNo...NoNoNoNoMonth-to-monthYesElectronic check29.8529.85No
15575-GNVDEMale0NoNo34YesNoDSLYes...YesNoNoNoOne yearNoMailed check56.951889.5No
23668-QPYBKMale0NoNo2YesNoDSLYes...NoNoNoNoMonth-to-monthYesMailed check53.85108.15Yes
37795-CFOCWMale0NoNo45NoNo phone serviceDSLYes...YesYesNoNoOne yearNoBank transfer (automatic)42.301840.75No
49237-HQITUFemale0NoNo2YesNoFiber opticNo...NoNoNoNoMonth-to-monthYesElectronic check70.70151.65Yes
\n", "

5 rows × 21 columns

\n", "
" ], "text/plain": [ " customerID gender SeniorCitizen Partner Dependents tenure PhoneService \\\n", "0 7590-VHVEG Female 0 Yes No 1 No \n", "1 5575-GNVDE Male 0 No No 34 Yes \n", "2 3668-QPYBK Male 0 No No 2 Yes \n", "3 7795-CFOCW Male 0 No No 45 No \n", "4 9237-HQITU Female 0 No No 2 Yes \n", "\n", " MultipleLines InternetService OnlineSecurity ... DeviceProtection \\\n", "0 No phone service DSL No ... No \n", "1 No DSL Yes ... Yes \n", "2 No DSL Yes ... No \n", "3 No phone service DSL Yes ... Yes \n", "4 No Fiber optic No ... No \n", "\n", " TechSupport StreamingTV StreamingMovies Contract PaperlessBilling \\\n", "0 No No No Month-to-month Yes \n", "1 No No No One year No \n", "2 No No No Month-to-month Yes \n", "3 Yes No No One year No \n", "4 No No No Month-to-month Yes \n", "\n", " PaymentMethod MonthlyCharges TotalCharges Churn \n", "0 Electronic check 29.85 29.85 No \n", "1 Mailed check 56.95 1889.5 No \n", "2 Mailed check 53.85 108.15 Yes \n", "3 Bank transfer (automatic) 42.30 1840.75 No \n", "4 Electronic check 70.70 151.65 Yes \n", "\n", "[5 rows x 21 columns]" ] }, "execution_count": 4, "metadata": {}, "output_type": "execute_result" } ], "source": [ "df.head(5)" ] }, { "cell_type": "code", "execution_count": 5, "id": "9d82e703", "metadata": {}, "outputs": [ { "data": { "text/plain": [ "Churn\n", "No 73.463013\n", "Yes 26.536987\n", "Name: count, dtype: float64" ] }, "execution_count": 5, "metadata": {}, "output_type": "execute_result" } ], "source": [ "df.Churn.value_counts()/len(df)*100" ] }, { "cell_type": "markdown", "id": "3787fcc0", "metadata": {}, "source": [ "## **Churn Rate**: 26.53%\n", "\n", "- Which means, 26.53% of the customers churn out of this telecom company" ] }, { "cell_type": "code", "execution_count": 6, "id": "71454c87", "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "Shape Of X: (7043, 19)\n", "Shape of Y : (7043,)\n" ] } ], "source": [ "y=df['Churn']\n", "\n", "x=df.drop(columns=['customerID','Churn'])\n", "\n", "print(\"Shape Of X:\",x.shape)\n", "print(\"Shape of Y : \",y.shape)" ] }, { "cell_type": "markdown", "id": "09c36144", "metadata": {}, "source": [ "## Train Test Split" ] }, { "cell_type": "code", "execution_count": 7, "id": "8e3cb313", "metadata": {}, "outputs": [], "source": [ "x=pd.get_dummies(x,drop_first=True)\n", "y=df['Churn'].map({'No':0,'Yes':1})" ] }, { "cell_type": "code", "execution_count": 8, "id": "0984dbe6", "metadata": {}, "outputs": [], "source": [ "x_train,x_test,y_train,y_test=train_test_split(x,y,test_size=0.2)" ] }, { "cell_type": "markdown", "id": "8540196a", "metadata": {}, "source": [ "## Model Building" ] }, { "cell_type": "code", "execution_count": 9, "id": "184952bb", "metadata": {}, "outputs": [ { "data": { "text/html": [ "
DecisionTreeClassifier()
In a Jupyter environment, please rerun this cell to show the HTML representation or trust the notebook.
On GitHub, the HTML representation is unable to render, please try loading this page with nbviewer.org.
" ], "text/plain": [ "DecisionTreeClassifier()" ] }, "execution_count": 9, "metadata": {}, "output_type": "execute_result" } ], "source": [ "model_dt.fit(x_train,y_train)" ] }, { "cell_type": "code", "execution_count": 10, "id": "9d630d95", "metadata": {}, "outputs": [], "source": [ "y_pred_dt=model_dt.predict(x_test)" ] }, { "cell_type": "code", "execution_count": 11, "id": "cac02be8", "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ " precision recall f1-score support\n", "\n", " 0 0.82 0.86 0.84 1013\n", " 1 0.59 0.51 0.55 396\n", "\n", " accuracy 0.76 1409\n", " macro avg 0.70 0.69 0.69 1409\n", "weighted avg 0.75 0.76 0.76 1409\n", "\n" ] } ], "source": [ "print(classification_report(y_test,y_pred_dt))" ] }, { "cell_type": "code", "execution_count": 12, "id": "05891ee2", "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "\n", "RangeIndex: 7043 entries, 0 to 7042\n", "Data columns (total 21 columns):\n", " # Column Non-Null Count Dtype \n", "--- ------ -------------- ----- \n", " 0 customerID 7043 non-null object \n", " 1 gender 7043 non-null object \n", " 2 SeniorCitizen 7043 non-null int64 \n", " 3 Partner 7043 non-null object \n", " 4 Dependents 7043 non-null object \n", " 5 tenure 7043 non-null int64 \n", " 6 PhoneService 7043 non-null object \n", " 7 MultipleLines 7043 non-null object \n", " 8 InternetService 7043 non-null object \n", " 9 OnlineSecurity 7043 non-null object \n", " 10 OnlineBackup 7043 non-null object \n", " 11 DeviceProtection 7043 non-null object \n", " 12 TechSupport 7043 non-null object \n", " 13 StreamingTV 7043 non-null object \n", " 14 StreamingMovies 7043 non-null object \n", " 15 Contract 7043 non-null object \n", " 16 PaperlessBilling 7043 non-null object \n", " 17 PaymentMethod 7043 non-null object \n", " 18 MonthlyCharges 7043 non-null float64\n", " 19 TotalCharges 7043 non-null object \n", " 20 Churn 7043 non-null object \n", "dtypes: float64(1), int64(2), object(18)\n", "memory usage: 1.1+ MB\n" ] } ], "source": [ "df.info()" ] }, { "cell_type": "markdown", "id": "cc1e5337", "metadata": {}, "source": [ "## Initial Insights\n", "\n", "- Base model has a accuracy of 76% which is not reliable because of the imbalanced dataset\n", "- TotalCharges needs to be a float/int type (Data Cleaning)\n", "- Need to perform Feature Scaling" ] }, { "cell_type": "markdown", "id": "03549cac", "metadata": {}, "source": [ "## Data Cleaning" ] }, { "cell_type": "code", "execution_count": 13, "id": "94323ad1", "metadata": {}, "outputs": [], "source": [ "telco_data=df.copy()" ] }, { "cell_type": "code", "execution_count": 14, "id": "4c230376", "metadata": {}, "outputs": [], "source": [ "telco_data.TotalCharges=pd.to_numeric(telco_data.TotalCharges,errors='coerce')" ] }, { "cell_type": "code", "execution_count": 15, "id": "0f351811", "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "\n", "RangeIndex: 7043 entries, 0 to 7042\n", "Data columns (total 21 columns):\n", " # Column Non-Null Count Dtype \n", "--- ------ -------------- ----- \n", " 0 customerID 7043 non-null object \n", " 1 gender 7043 non-null object \n", " 2 SeniorCitizen 7043 non-null int64 \n", " 3 Partner 7043 non-null object \n", " 4 Dependents 7043 non-null object \n", " 5 tenure 7043 non-null int64 \n", " 6 PhoneService 7043 non-null object \n", " 7 MultipleLines 7043 non-null object \n", " 8 InternetService 7043 non-null object \n", " 9 OnlineSecurity 7043 non-null object \n", " 10 OnlineBackup 7043 non-null object \n", " 11 DeviceProtection 7043 non-null object \n", " 12 TechSupport 7043 non-null object \n", " 13 StreamingTV 7043 non-null object \n", " 14 StreamingMovies 7043 non-null object \n", " 15 Contract 7043 non-null object \n", " 16 PaperlessBilling 7043 non-null object \n", " 17 PaymentMethod 7043 non-null object \n", " 18 MonthlyCharges 7043 non-null float64\n", " 19 TotalCharges 7032 non-null float64\n", " 20 Churn 7043 non-null object \n", "dtypes: float64(2), int64(2), object(17)\n", "memory usage: 1.1+ MB\n" ] } ], "source": [ "telco_data.info()" ] }, { "cell_type": "code", "execution_count": 16, "id": "54167917", "metadata": {}, "outputs": [ { "data": { "text/html": [ "
\n", "\n", "\n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", "
customerIDgenderSeniorCitizenPartnerDependentstenurePhoneServiceMultipleLinesInternetServiceOnlineSecurity...DeviceProtectionTechSupportStreamingTVStreamingMoviesContractPaperlessBillingPaymentMethodMonthlyChargesTotalChargesChurn
4884472-LVYGIFemale0YesYes0NoNo phone serviceDSLYes...YesYesYesNoTwo yearYesBank transfer (automatic)52.55NaNNo
7533115-CZMZDMale0NoYes0YesNoNoNo internet service...No internet serviceNo internet serviceNo internet serviceNo internet serviceTwo yearNoMailed check20.25NaNNo
9365709-LVOEQFemale0YesYes0YesNoDSLYes...YesNoYesYesTwo yearNoMailed check80.85NaNNo
10824367-NUYAOMale0YesYes0YesYesNoNo internet service...No internet serviceNo internet serviceNo internet serviceNo internet serviceTwo yearNoMailed check25.75NaNNo
13401371-DWPAZFemale0YesYes0NoNo phone serviceDSLYes...YesYesYesNoTwo yearNoCredit card (automatic)56.05NaNNo
33317644-OMVMYMale0YesYes0YesNoNoNo internet service...No internet serviceNo internet serviceNo internet serviceNo internet serviceTwo yearNoMailed check19.85NaNNo
38263213-VVOLGMale0YesYes0YesYesNoNo internet service...No internet serviceNo internet serviceNo internet serviceNo internet serviceTwo yearNoMailed check25.35NaNNo
43802520-SGTTAFemale0YesYes0YesNoNoNo internet service...No internet serviceNo internet serviceNo internet serviceNo internet serviceTwo yearNoMailed check20.00NaNNo
52182923-ARZLGMale0YesYes0YesNoNoNo internet service...No internet serviceNo internet serviceNo internet serviceNo internet serviceOne yearYesMailed check19.70NaNNo
66704075-WKNIUFemale0YesYes0YesYesDSLNo...YesYesYesNoTwo yearNoMailed check73.35NaNNo
67542775-SEFEEMale0NoYes0YesYesDSLYes...NoYesNoNoTwo yearYesBank transfer (automatic)61.90NaNNo
\n", "

11 rows × 21 columns

\n", "
" ], "text/plain": [ " customerID gender SeniorCitizen Partner Dependents tenure \\\n", "488 4472-LVYGI Female 0 Yes Yes 0 \n", "753 3115-CZMZD Male 0 No Yes 0 \n", "936 5709-LVOEQ Female 0 Yes Yes 0 \n", "1082 4367-NUYAO Male 0 Yes Yes 0 \n", "1340 1371-DWPAZ Female 0 Yes Yes 0 \n", "3331 7644-OMVMY Male 0 Yes Yes 0 \n", "3826 3213-VVOLG Male 0 Yes Yes 0 \n", "4380 2520-SGTTA Female 0 Yes Yes 0 \n", "5218 2923-ARZLG Male 0 Yes Yes 0 \n", "6670 4075-WKNIU Female 0 Yes Yes 0 \n", "6754 2775-SEFEE Male 0 No Yes 0 \n", "\n", " PhoneService MultipleLines InternetService OnlineSecurity ... \\\n", "488 No No phone service DSL Yes ... \n", "753 Yes No No No internet service ... \n", "936 Yes No DSL Yes ... \n", "1082 Yes Yes No No internet service ... \n", "1340 No No phone service DSL Yes ... \n", "3331 Yes No No No internet service ... \n", "3826 Yes Yes No No internet service ... \n", "4380 Yes No No No internet service ... \n", "5218 Yes No No No internet service ... \n", "6670 Yes Yes DSL No ... \n", "6754 Yes Yes DSL Yes ... \n", "\n", " DeviceProtection TechSupport StreamingTV \\\n", "488 Yes Yes Yes \n", "753 No internet service No internet service No internet service \n", "936 Yes No Yes \n", "1082 No internet service No internet service No internet service \n", "1340 Yes Yes Yes \n", "3331 No internet service No internet service No internet service \n", "3826 No internet service No internet service No internet service \n", "4380 No internet service No internet service No internet service \n", "5218 No internet service No internet service No internet service \n", "6670 Yes Yes Yes \n", "6754 No Yes No \n", "\n", " StreamingMovies Contract PaperlessBilling \\\n", "488 No Two year Yes \n", "753 No internet service Two year No \n", "936 Yes Two year No \n", "1082 No internet service Two year No \n", "1340 No Two year No \n", "3331 No internet service Two year No \n", "3826 No internet service Two year No \n", "4380 No internet service Two year No \n", "5218 No internet service One year Yes \n", "6670 No Two year No \n", "6754 No Two year Yes \n", "\n", " PaymentMethod MonthlyCharges TotalCharges Churn \n", "488 Bank transfer (automatic) 52.55 NaN No \n", "753 Mailed check 20.25 NaN No \n", "936 Mailed check 80.85 NaN No \n", "1082 Mailed check 25.75 NaN No \n", "1340 Credit card (automatic) 56.05 NaN No \n", "3331 Mailed check 19.85 NaN No \n", "3826 Mailed check 25.35 NaN No \n", "4380 Mailed check 20.00 NaN No \n", "5218 Mailed check 19.70 NaN No \n", "6670 Mailed check 73.35 NaN No \n", "6754 Bank transfer (automatic) 61.90 NaN No \n", "\n", "[11 rows x 21 columns]" ] }, "execution_count": 16, "metadata": {}, "output_type": "execute_result" } ], "source": [ "telco_data.loc[telco_data['TotalCharges'].isnull()==True]" ] }, { "cell_type": "code", "execution_count": 17, "id": "f13665a9", "metadata": {}, "outputs": [], "source": [ "telco_data.dropna(how='any',inplace=True)" ] }, { "cell_type": "code", "execution_count": 18, "id": "8c86c5f0", "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "\n", "Index: 7032 entries, 0 to 7042\n", "Data columns (total 21 columns):\n", " # Column Non-Null Count Dtype \n", "--- ------ -------------- ----- \n", " 0 customerID 7032 non-null object \n", " 1 gender 7032 non-null object \n", " 2 SeniorCitizen 7032 non-null int64 \n", " 3 Partner 7032 non-null object \n", " 4 Dependents 7032 non-null object \n", " 5 tenure 7032 non-null int64 \n", " 6 PhoneService 7032 non-null object \n", " 7 MultipleLines 7032 non-null object \n", " 8 InternetService 7032 non-null object \n", " 9 OnlineSecurity 7032 non-null object \n", " 10 OnlineBackup 7032 non-null object \n", " 11 DeviceProtection 7032 non-null object \n", " 12 TechSupport 7032 non-null object \n", " 13 StreamingTV 7032 non-null object \n", " 14 StreamingMovies 7032 non-null object \n", " 15 Contract 7032 non-null object \n", " 16 PaperlessBilling 7032 non-null object \n", " 17 PaymentMethod 7032 non-null object \n", " 18 MonthlyCharges 7032 non-null float64\n", " 19 TotalCharges 7032 non-null float64\n", " 20 Churn 7032 non-null object \n", "dtypes: float64(2), int64(2), object(17)\n", "memory usage: 1.2+ MB\n" ] } ], "source": [ "telco_data.info()" ] }, { "cell_type": "code", "execution_count": 19, "id": "46b88874", "metadata": {}, "outputs": [ { "data": { "text/html": [ "
\n", "\n", "\n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", "
customerIDgenderSeniorCitizenPartnerDependentstenurePhoneServiceMultipleLinesInternetServiceOnlineSecurity...DeviceProtectionTechSupportStreamingTVStreamingMoviesContractPaperlessBillingPaymentMethodMonthlyChargesTotalChargesChurn
07590-VHVEGFemale0YesNo1NoNo phone serviceDSLNo...NoNoNoNoMonth-to-monthYesElectronic check29.8529.85No
15575-GNVDEMale0NoNo34YesNoDSLYes...YesNoNoNoOne yearNoMailed check56.951889.50No
23668-QPYBKMale0NoNo2YesNoDSLYes...NoNoNoNoMonth-to-monthYesMailed check53.85108.15Yes
37795-CFOCWMale0NoNo45NoNo phone serviceDSLYes...YesYesNoNoOne yearNoBank transfer (automatic)42.301840.75No
49237-HQITUFemale0NoNo2YesNoFiber opticNo...NoNoNoNoMonth-to-monthYesElectronic check70.70151.65Yes
\n", "

5 rows × 21 columns

\n", "
" ], "text/plain": [ " customerID gender SeniorCitizen Partner Dependents tenure PhoneService \\\n", "0 7590-VHVEG Female 0 Yes No 1 No \n", "1 5575-GNVDE Male 0 No No 34 Yes \n", "2 3668-QPYBK Male 0 No No 2 Yes \n", "3 7795-CFOCW Male 0 No No 45 No \n", "4 9237-HQITU Female 0 No No 2 Yes \n", "\n", " MultipleLines InternetService OnlineSecurity ... DeviceProtection \\\n", "0 No phone service DSL No ... No \n", "1 No DSL Yes ... Yes \n", "2 No DSL Yes ... No \n", "3 No phone service DSL Yes ... Yes \n", "4 No Fiber optic No ... No \n", "\n", " TechSupport StreamingTV StreamingMovies Contract PaperlessBilling \\\n", "0 No No No Month-to-month Yes \n", "1 No No No One year No \n", "2 No No No Month-to-month Yes \n", "3 Yes No No One year No \n", "4 No No No Month-to-month Yes \n", "\n", " PaymentMethod MonthlyCharges TotalCharges Churn \n", "0 Electronic check 29.85 29.85 No \n", "1 Mailed check 56.95 1889.50 No \n", "2 Mailed check 53.85 108.15 Yes \n", "3 Bank transfer (automatic) 42.30 1840.75 No \n", "4 Electronic check 70.70 151.65 Yes \n", "\n", "[5 rows x 21 columns]" ] }, "execution_count": 19, "metadata": {}, "output_type": "execute_result" } ], "source": [ "telco_data.head(5)" ] }, { "cell_type": "code", "execution_count": 20, "id": "5b5a0e94", "metadata": {}, "outputs": [ { "data": { "text/plain": [ "72" ] }, "execution_count": 20, "metadata": {}, "output_type": "execute_result" } ], "source": [ "telco_data.tenure.max()" ] }, { "cell_type": "code", "execution_count": 21, "id": "5617b39d", "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ " tenure tenure_bin\n", "0 1 1-12\n", "1 34 25-36\n", "2 2 1-12\n", "3 45 37-48\n", "4 2 1-12\n", "5 8 1-12\n", "6 22 13-24\n", "7 10 1-12\n", "8 28 25-36\n", "9 62 61-72\n", "tenure_bin\n", "1-12 2175\n", "13-24 1024\n", "25-36 832\n", "37-48 762\n", "49-60 832\n", "61-72 1407\n", "Name: count, dtype: int64\n" ] } ], "source": [ "import pandas as pd\n", "\n", "bins=[0,12,24,36,48,60,72]\n", "\n", "labels=['1-12','13-24','25-36','37-48','49-60','61-72']\n", "\n", "telco_data['tenure_bin']=pd.cut(telco_data['tenure'],labels=labels,bins=bins,include_lowest=True)\n", "\n", "print(telco_data[['tenure','tenure_bin']].head(10))\n", "print(telco_data['tenure_bin'].value_counts().sort_index())" ] }, { "cell_type": "code", "execution_count": 22, "id": "60cc3b1f", "metadata": {}, "outputs": [ { "data": { "text/html": [ "
\n", "\n", "\n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", "
customerIDgenderSeniorCitizenPartnerDependentstenurePhoneServiceMultipleLinesInternetServiceOnlineSecurity...TechSupportStreamingTVStreamingMoviesContractPaperlessBillingPaymentMethodMonthlyChargesTotalChargesChurntenure_bin
07590-VHVEGFemale0YesNo1NoNo phone serviceDSLNo...NoNoNoMonth-to-monthYesElectronic check29.8529.85No1-12
15575-GNVDEMale0NoNo34YesNoDSLYes...NoNoNoOne yearNoMailed check56.951889.50No25-36
23668-QPYBKMale0NoNo2YesNoDSLYes...NoNoNoMonth-to-monthYesMailed check53.85108.15Yes1-12
37795-CFOCWMale0NoNo45NoNo phone serviceDSLYes...YesNoNoOne yearNoBank transfer (automatic)42.301840.75No37-48
49237-HQITUFemale0NoNo2YesNoFiber opticNo...NoNoNoMonth-to-monthYesElectronic check70.70151.65Yes1-12
\n", "

5 rows × 22 columns

\n", "
" ], "text/plain": [ " customerID gender SeniorCitizen Partner Dependents tenure PhoneService \\\n", "0 7590-VHVEG Female 0 Yes No 1 No \n", "1 5575-GNVDE Male 0 No No 34 Yes \n", "2 3668-QPYBK Male 0 No No 2 Yes \n", "3 7795-CFOCW Male 0 No No 45 No \n", "4 9237-HQITU Female 0 No No 2 Yes \n", "\n", " MultipleLines InternetService OnlineSecurity ... TechSupport \\\n", "0 No phone service DSL No ... No \n", "1 No DSL Yes ... No \n", "2 No DSL Yes ... No \n", "3 No phone service DSL Yes ... Yes \n", "4 No Fiber optic No ... No \n", "\n", " StreamingTV StreamingMovies Contract PaperlessBilling \\\n", "0 No No Month-to-month Yes \n", "1 No No One year No \n", "2 No No Month-to-month Yes \n", "3 No No One year No \n", "4 No No Month-to-month Yes \n", "\n", " PaymentMethod MonthlyCharges TotalCharges Churn tenure_bin \n", "0 Electronic check 29.85 29.85 No 1-12 \n", "1 Mailed check 56.95 1889.50 No 25-36 \n", "2 Mailed check 53.85 108.15 Yes 1-12 \n", "3 Bank transfer (automatic) 42.30 1840.75 No 37-48 \n", "4 Electronic check 70.70 151.65 Yes 1-12 \n", "\n", "[5 rows x 22 columns]" ] }, "execution_count": 22, "metadata": {}, "output_type": "execute_result" } ], "source": [ "telco_data.head(5)" ] }, { "cell_type": "code", "execution_count": 23, "id": "49a9143b", "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "Shape of X : (7032, 19)\n", "Shape of y : (7032,)\n" ] } ], "source": [ "y=telco_data['Churn']\n", "\n", "x=telco_data.drop(columns=['customerID','Churn','tenure'])\n", "\n", "print(\"Shape of X :\",x.shape)\n", "print(\"Shape of y :\",y.shape)" ] }, { "cell_type": "code", "execution_count": 24, "id": "6e39f724", "metadata": {}, "outputs": [ { "data": { "text/html": [ "
\n", "\n", "\n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", "
genderSeniorCitizenPartnerDependentsPhoneServiceMultipleLinesInternetServiceOnlineSecurityOnlineBackupDeviceProtectionTechSupportStreamingTVStreamingMoviesContractPaperlessBillingPaymentMethodMonthlyChargesTotalChargestenure_bin
0Female0YesNoNoNo phone serviceDSLNoYesNoNoNoNoMonth-to-monthYesElectronic check29.8529.851-12
1Male0NoNoYesNoDSLYesNoYesNoNoNoOne yearNoMailed check56.951889.5025-36
2Male0NoNoYesNoDSLYesYesNoNoNoNoMonth-to-monthYesMailed check53.85108.151-12
3Male0NoNoNoNo phone serviceDSLYesNoYesYesNoNoOne yearNoBank transfer (automatic)42.301840.7537-48
4Female0NoNoYesNoFiber opticNoNoNoNoNoNoMonth-to-monthYesElectronic check70.70151.651-12
............................................................
7038Male0YesYesYesYesDSLYesNoYesYesYesYesOne yearYesMailed check84.801990.5013-24
7039Female0YesYesYesYesFiber opticNoYesYesNoYesYesOne yearYesCredit card (automatic)103.207362.9061-72
7040Female0YesYesNoNo phone serviceDSLYesNoNoNoNoNoMonth-to-monthYesElectronic check29.60346.451-12
7041Male1YesNoYesYesFiber opticNoNoNoNoNoNoMonth-to-monthYesMailed check74.40306.601-12
7042Male0NoNoYesNoFiber opticYesNoYesYesYesYesTwo yearYesBank transfer (automatic)105.656844.5061-72
\n", "

7032 rows × 19 columns

\n", "
" ], "text/plain": [ " gender SeniorCitizen Partner Dependents PhoneService MultipleLines \\\n", "0 Female 0 Yes No No No phone service \n", "1 Male 0 No No Yes No \n", "2 Male 0 No No Yes No \n", "3 Male 0 No No No No phone service \n", "4 Female 0 No No Yes No \n", "... ... ... ... ... ... ... \n", "7038 Male 0 Yes Yes Yes Yes \n", "7039 Female 0 Yes Yes Yes Yes \n", "7040 Female 0 Yes Yes No No phone service \n", "7041 Male 1 Yes No Yes Yes \n", "7042 Male 0 No No Yes No \n", "\n", " InternetService OnlineSecurity OnlineBackup DeviceProtection TechSupport \\\n", "0 DSL No Yes No No \n", "1 DSL Yes No Yes No \n", "2 DSL Yes Yes No No \n", "3 DSL Yes No Yes Yes \n", "4 Fiber optic No No No No \n", "... ... ... ... ... ... \n", "7038 DSL Yes No Yes Yes \n", "7039 Fiber optic No Yes Yes No \n", "7040 DSL Yes No No No \n", "7041 Fiber optic No No No No \n", "7042 Fiber optic Yes No Yes Yes \n", "\n", " StreamingTV StreamingMovies Contract PaperlessBilling \\\n", "0 No No Month-to-month Yes \n", "1 No No One year No \n", "2 No No Month-to-month Yes \n", "3 No No One year No \n", "4 No No Month-to-month Yes \n", "... ... ... ... ... \n", "7038 Yes Yes One year Yes \n", "7039 Yes Yes One year Yes \n", "7040 No No Month-to-month Yes \n", "7041 No No Month-to-month Yes \n", "7042 Yes Yes Two year Yes \n", "\n", " PaymentMethod MonthlyCharges TotalCharges tenure_bin \n", "0 Electronic check 29.85 29.85 1-12 \n", "1 Mailed check 56.95 1889.50 25-36 \n", "2 Mailed check 53.85 108.15 1-12 \n", "3 Bank transfer (automatic) 42.30 1840.75 37-48 \n", "4 Electronic check 70.70 151.65 1-12 \n", "... ... ... ... ... \n", "7038 Mailed check 84.80 1990.50 13-24 \n", "7039 Credit card (automatic) 103.20 7362.90 61-72 \n", "7040 Electronic check 29.60 346.45 1-12 \n", "7041 Mailed check 74.40 306.60 1-12 \n", "7042 Bank transfer (automatic) 105.65 6844.50 61-72 \n", "\n", "[7032 rows x 19 columns]" ] }, "execution_count": 24, "metadata": {}, "output_type": "execute_result" } ], "source": [ "x" ] }, { "cell_type": "code", "execution_count": 25, "id": "cdf8f3d6", "metadata": {}, "outputs": [], "source": [ "x=pd.get_dummies(x,drop_first=True)\n", "y=telco_data['Churn'].map({'No':0,\"Yes\":1})" ] }, { "cell_type": "code", "execution_count": 26, "id": "66142d39", "metadata": {}, "outputs": [ { "data": { "text/html": [ "
\n", "\n", "\n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", "
SeniorCitizenMonthlyChargesTotalChargesgender_MalePartner_YesDependents_YesPhoneService_YesMultipleLines_No phone serviceMultipleLines_YesInternetService_Fiber optic...Contract_Two yearPaperlessBilling_YesPaymentMethod_Credit card (automatic)PaymentMethod_Electronic checkPaymentMethod_Mailed checktenure_bin_13-24tenure_bin_25-36tenure_bin_37-48tenure_bin_49-60tenure_bin_61-72
0029.8529.85FalseTrueFalseFalseTrueFalseFalse...FalseTrueFalseTrueFalseFalseFalseFalseFalseFalse
1056.951889.50TrueFalseFalseTrueFalseFalseFalse...FalseFalseFalseFalseTrueFalseTrueFalseFalseFalse
2053.85108.15TrueFalseFalseTrueFalseFalseFalse...FalseTrueFalseFalseTrueFalseFalseFalseFalseFalse
3042.301840.75TrueFalseFalseFalseTrueFalseFalse...FalseFalseFalseFalseFalseFalseFalseTrueFalseFalse
4070.70151.65FalseFalseFalseTrueFalseFalseTrue...FalseTrueFalseTrueFalseFalseFalseFalseFalseFalse
..................................................................
7038084.801990.50TrueTrueTrueTrueFalseTrueFalse...FalseTrueFalseFalseTrueTrueFalseFalseFalseFalse
70390103.207362.90FalseTrueTrueTrueFalseTrueTrue...FalseTrueTrueFalseFalseFalseFalseFalseFalseTrue
7040029.60346.45FalseTrueTrueFalseTrueFalseFalse...FalseTrueFalseTrueFalseFalseFalseFalseFalseFalse
7041174.40306.60TrueTrueFalseTrueFalseTrueTrue...FalseTrueFalseFalseTrueFalseFalseFalseFalseFalse
70420105.656844.50TrueFalseFalseTrueFalseFalseTrue...TrueTrueFalseFalseFalseFalseFalseFalseFalseTrue
\n", "

7032 rows × 34 columns

\n", "
" ], "text/plain": [ " SeniorCitizen MonthlyCharges TotalCharges gender_Male Partner_Yes \\\n", "0 0 29.85 29.85 False True \n", "1 0 56.95 1889.50 True False \n", "2 0 53.85 108.15 True False \n", "3 0 42.30 1840.75 True False \n", "4 0 70.70 151.65 False False \n", "... ... ... ... ... ... \n", "7038 0 84.80 1990.50 True True \n", "7039 0 103.20 7362.90 False True \n", "7040 0 29.60 346.45 False True \n", "7041 1 74.40 306.60 True True \n", "7042 0 105.65 6844.50 True False \n", "\n", " Dependents_Yes PhoneService_Yes MultipleLines_No phone service \\\n", "0 False False True \n", "1 False True False \n", "2 False True False \n", "3 False False True \n", "4 False True False \n", "... ... ... ... \n", "7038 True True False \n", "7039 True True False \n", "7040 True False True \n", "7041 False True False \n", "7042 False True False \n", "\n", " MultipleLines_Yes InternetService_Fiber optic ... Contract_Two year \\\n", "0 False False ... False \n", "1 False False ... False \n", "2 False False ... False \n", "3 False False ... False \n", "4 False True ... False \n", "... ... ... ... ... \n", "7038 True False ... False \n", "7039 True True ... False \n", "7040 False False ... False \n", "7041 True True ... False \n", "7042 False True ... True \n", "\n", " PaperlessBilling_Yes PaymentMethod_Credit card (automatic) \\\n", "0 True False \n", "1 False False \n", "2 True False \n", "3 False False \n", "4 True False \n", "... ... ... \n", "7038 True False \n", "7039 True True \n", "7040 True False \n", "7041 True False \n", "7042 True False \n", "\n", " PaymentMethod_Electronic check PaymentMethod_Mailed check \\\n", "0 True False \n", "1 False True \n", "2 False True \n", "3 False False \n", "4 True False \n", "... ... ... \n", "7038 False True \n", "7039 False False \n", "7040 True False \n", "7041 False True \n", "7042 False False \n", "\n", " tenure_bin_13-24 tenure_bin_25-36 tenure_bin_37-48 tenure_bin_49-60 \\\n", "0 False False False False \n", "1 False True False False \n", "2 False False False False \n", "3 False False True False \n", "4 False False False False \n", "... ... ... ... ... \n", "7038 True False False False \n", "7039 False False False False \n", "7040 False False False False \n", "7041 False False False False \n", "7042 False False False False \n", "\n", " tenure_bin_61-72 \n", "0 False \n", "1 False \n", "2 False \n", "3 False \n", "4 False \n", "... ... \n", "7038 False \n", "7039 True \n", "7040 False \n", "7041 False \n", "7042 True \n", "\n", "[7032 rows x 34 columns]" ] }, "execution_count": 26, "metadata": {}, "output_type": "execute_result" } ], "source": [ "x" ] }, { "cell_type": "code", "execution_count": 27, "id": "b42aa9c2", "metadata": {}, "outputs": [], "source": [ "x_train,x_test,y_train,y_test=train_test_split(x,y,test_size=0.2)" ] }, { "cell_type": "markdown", "id": "1e788837", "metadata": {}, "source": [ "## Feature Scaling" ] }, { "cell_type": "code", "execution_count": 28, "id": "6a680a36", "metadata": {}, "outputs": [], "source": [ "x_train=sc.fit_transform(x_train)\n", "x_test=sc.transform(x_test)" ] }, { "cell_type": "code", "execution_count": 29, "id": "f5e5a24d", "metadata": {}, "outputs": [], "source": [ "model_dt2.fit(x_train,y_train)\n", "y_pred_dt2=model_dt2.predict(x_test)" ] }, { "cell_type": "code", "execution_count": 30, "id": "d59218fa", "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ " precision recall f1-score support\n", "\n", " 0 0.80 0.79 0.80 1003\n", " 1 0.49 0.50 0.50 404\n", "\n", " accuracy 0.71 1407\n", " macro avg 0.64 0.65 0.65 1407\n", "weighted avg 0.71 0.71 0.71 1407\n", "\n" ] } ], "source": [ "print(classification_report(y_test,y_pred_dt2))" ] }, { "cell_type": "markdown", "id": "f5476f64", "metadata": {}, "source": [ "## Feature Scaling - MinMaxScaler" ] }, { "cell_type": "code", "execution_count": 31, "id": "519545a9", "metadata": {}, "outputs": [], "source": [ "x_train_mms=mms.fit_transform(x_train)\n", "x_test_mms=mms.transform(x_test)" ] }, { "cell_type": "code", "execution_count": 32, "id": "00136a29", "metadata": {}, "outputs": [], "source": [ "model_dt3.fit(x_train_mms,y_train)\n", "\n", "y_pred_dt3=model_dt3.predict(x_test_mms)" ] }, { "cell_type": "code", "execution_count": 33, "id": "3f139c0b", "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ " precision recall f1-score support\n", "\n", " 0 0.80 0.80 0.80 1003\n", " 1 0.51 0.50 0.51 404\n", "\n", " accuracy 0.72 1407\n", " macro avg 0.65 0.65 0.65 1407\n", "weighted avg 0.72 0.72 0.72 1407\n", "\n" ] } ], "source": [ "print(classification_report(y_test,y_pred_dt3))" ] }, { "cell_type": "markdown", "id": "0f628d86", "metadata": {}, "source": [ "## SMOTEENN () [UpSampling + ENN)" ] }, { "cell_type": "code", "execution_count": 34, "id": "497ce043", "metadata": {}, "outputs": [], "source": [ "x_train_resampled,y_train_resampled=sm.fit_resample(x_train,y_train)" ] }, { "cell_type": "code", "execution_count": 35, "id": "3e5b684f", "metadata": {}, "outputs": [], "source": [ "model_dt_smotenn.fit(x_train_resampled,y_train_resampled)\n", "\n", "y_pred_dt_smoteen=model_dt_smotenn.predict(x_test)" ] }, { "cell_type": "code", "execution_count": 36, "id": "815f4b74", "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ " precision recall f1-score support\n", "\n", " 0 0.89 0.69 0.78 1003\n", " 1 0.50 0.78 0.61 404\n", "\n", " accuracy 0.72 1407\n", " macro avg 0.70 0.74 0.70 1407\n", "weighted avg 0.78 0.72 0.73 1407\n", "\n" ] } ], "source": [ "print(classification_report(y_test,y_pred_dt_smoteen))" ] }, { "cell_type": "code", "execution_count": 37, "id": "6ddd16f9", "metadata": {}, "outputs": [], "source": [ "model_rf_smoteenn.fit(x_train_resampled,y_train_resampled)\n", "y_pred_rf_smoteenn=model_rf_smoteenn.predict(x_test)" ] }, { "cell_type": "code", "execution_count": 38, "id": "2e826af1", "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ " precision recall f1-score support\n", "\n", " 0 0.91 0.68 0.78 1003\n", " 1 0.51 0.82 0.63 404\n", "\n", " accuracy 0.72 1407\n", " macro avg 0.71 0.75 0.71 1407\n", "weighted avg 0.79 0.72 0.74 1407\n", "\n" ] } ], "source": [ "print(classification_report(y_test,y_pred_rf_smoteenn))" ] }, { "cell_type": "markdown", "id": "62576049", "metadata": {}, "source": [ "## XGBoost without SMOTEENN" ] }, { "cell_type": "code", "execution_count": 39, "id": "fc208662", "metadata": {}, "outputs": [], "source": [ "model_xgb.fit(x_train,y_train)\n", "\n", "y_pred_xgb=model_xgb.predict(x_test)" ] }, { "cell_type": "code", "execution_count": 40, "id": "24acf406", "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ " precision recall f1-score support\n", "\n", " 0 0.82 0.87 0.84 1003\n", " 1 0.61 0.53 0.57 404\n", "\n", " accuracy 0.77 1407\n", " macro avg 0.72 0.70 0.70 1407\n", "weighted avg 0.76 0.77 0.76 1407\n", "\n" ] } ], "source": [ "print(classification_report(y_test,y_pred_xgb))" ] }, { "cell_type": "markdown", "id": "39fa3269", "metadata": {}, "source": [ "## XGBoost with SMOTE" ] }, { "cell_type": "code", "execution_count": 41, "id": "2decf81a", "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "Before SMOTE : Counter({0: 4160, 1: 1465})\n", "After SMOTE : Counter({1: 4160, 0: 4160})\n" ] } ], "source": [ "print(\"Before SMOTE :\",Counter(y_train))\n", "\n", "x_train_smote,y_train_smote=smote.fit_resample(x_train,y_train)\n", "\n", "print(\"After SMOTE :\",Counter(y_train_smote))\n", "\n", "model_xgb_smote.fit(x_train_smote,y_train_smote)\n", "\n", "y_pred_xgb_smote=model_xgb_smote.predict(x_test)" ] }, { "cell_type": "code", "execution_count": 42, "id": "4af8fe60", "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ " precision recall f1-score support\n", "\n", " 0 0.84 0.85 0.85 1003\n", " 1 0.62 0.61 0.61 404\n", "\n", " accuracy 0.78 1407\n", " macro avg 0.73 0.73 0.73 1407\n", "weighted avg 0.78 0.78 0.78 1407\n", "\n" ] } ], "source": [ "print(classification_report(y_test,y_pred_xgb_smote))" ] }, { "cell_type": "code", "execution_count": 43, "id": "4685fbd3", "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "Before ADASYN : Counter({0: 4160, 1: 1465})\n", "After ADASYN : Counter({0: 4160, 1: 4035})\n", "Accuracy : 0.783226723525231\n", "Classification Report : \n", " precision recall f1-score support\n", "\n", " 0 0.84 0.85 0.85 1003\n", " 1 0.63 0.61 0.62 404\n", "\n", " accuracy 0.78 1407\n", " macro avg 0.74 0.73 0.73 1407\n", "weighted avg 0.78 0.78 0.78 1407\n", "\n", "Confusion Matrix :\n", " [[857 146]\n", " [159 245]]\n" ] } ], "source": [ "print(\"Before ADASYN :\",Counter(y_train))\n", "\n", "x_train_adasyn,y_train_adasyn=adasyn.fit_resample(x_train,y_train)\n", "\n", "print(\"After ADASYN :\",Counter(y_train_adasyn))\n", "\n", "model_xgb_adasyn.fit(x_train_adasyn,y_train_adasyn)\n", "\n", "y_pred_xgb_adasyn=model_xgb_adasyn.predict(x_test)\n", "\n", "print(\"Accuracy : \",accuracy_score(y_test,y_pred_xgb_adasyn))\n", "print(\"Classification Report : \\n\",classification_report(y_test,y_pred_xgb_adasyn))\n", "print(\"Confusion Matrix :\\n\",confusion_matrix(y_test,y_pred_xgb_adasyn))" ] }, { "cell_type": "code", "execution_count": 57, "id": "30fb6219", "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "Scale_pos_weight : 2.839590443686007\n", "Accuracy : 0.7604832977967306\n", "\n", "Classification Report :\n", " precision recall f1-score support\n", "\n", " 0 0.86 0.79 0.83 1003\n", " 1 0.57 0.68 0.62 404\n", "\n", " accuracy 0.76 1407\n", " macro avg 0.71 0.74 0.72 1407\n", "weighted avg 0.78 0.76 0.77 1407\n", "\n", "\n", " Confusion Matrix :\n", " [[797 206]\n", " [131 273]]\n" ] } ], "source": [ "scale_pos_weight=(y_train==0).sum()/(y_train==1).sum()\n", "print(f\"Scale_pos_weight : {scale_pos_weight}\")\n", "\n", "model_xgb_weighted=XGBClassifier(\n", " scale_pos_weight=scale_pos_weight,\n", " random_state=42,\n", " eval_metric='logloss'\n", ")\n", "\n", "model_xgb_weighted.fit(x_train,y_train)\n", "y_pred_weighted=model_xgb_weighted.predict(x_test)\n", "\n", "print(\"Accuracy :\",accuracy_score(y_test,y_pred_weighted))\n", "print(\"\\nClassification Report :\\n\",classification_report(y_test,y_pred_weighted))\n", "print(\"\\n Confusion Matrix :\\n\",confusion_matrix(y_test,y_pred_weighted))" ] }, { "cell_type": "code", "execution_count": 69, "id": "497ad113", "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "Negative Class Count : 4160\n", "Positive Class Count : 1465\n", "Weighted for positive Count 2.839590443686007\n", "Adaboost With Sample Weighting Accuracy 0.738450604122246\n", "\n", "Classification Report:\n", " precision recall f1-score support\n", "\n", " 0 0.91 0.70 0.79 1003\n", " 1 0.53 0.82 0.64 404\n", "\n", " accuracy 0.74 1407\n", " macro avg 0.72 0.76 0.72 1407\n", "weighted avg 0.80 0.74 0.75 1407\n", "\n", "\n", " Confusion Matrix:\n", " [[706 297]\n", " [ 71 333]]\n" ] } ], "source": [ "negative_count=(y_train==0).sum()\n", "positive_count=(y_train==1).sum()\n", "weighted_positive=negative_count/positive_count\n", "print(f\"Negative Class Count : \",negative_count)\n", "print(f\"Positive Class Count : \",positive_count)\n", "print(f\"Weighted for positive Count \",weighted_positive)\n", "\n", "sample_weight=np.where(y_train==1,weighted_positive,1.0)\n", "\n", "model_ada_weighted.fit(x_train,y_train,sample_weight=sample_weight)\n", "\n", "y_pred_ada_weighted=model_ada_weighted.predict(x_test)\n", "\n", "print(\"Adaboost With Sample Weighting Accuracy \",accuracy_score(y_test,y_pred_ada_weighted))\n", "print(\"\\nClassification Report:\\n\",classification_report(y_test,y_pred_ada_weighted))\n", "print(\"\\n Confusion Matrix:\\n\",confusion_matrix(y_test,y_pred_ada_weighted))" ] }, { "cell_type": "code", "execution_count": 71, "id": "7db6d6c9", "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "Best Parameters : {'subsample': 0.8, 'scale_pos_weight': 2.839590443686007, 'n_estimators': 400, 'min_child_weight': 5, 'max_depth': 4, 'learning_rate': 0.01, 'gamma': 0, 'colsample_bytree': 0.7}\n", "Best CV F1 Score : 0.6303995740741408\n", "\n", " Test Classification Report :\n", " precision recall f1-score support\n", "\n", " 0 0.90 0.71 0.80 1003\n", " 1 0.53 0.81 0.64 404\n", "\n", " accuracy 0.74 1407\n", " macro avg 0.72 0.76 0.72 1407\n", "weighted avg 0.80 0.74 0.75 1407\n", "\n" ] } ], "source": [ "param_grid={\n", " 'max_depth': [3, 4, 5, 6, 7],\n", " 'learning_rate': [0.01, 0.05, 0.1, 0.2],\n", " 'n_estimators': [100, 200, 300, 400],\n", " 'subsample': [0.7, 0.8, 0.9, 1.0],\n", " 'colsample_bytree': [0.7, 0.8, 0.9, 1.0],\n", " 'min_child_weight': [1, 3, 5],\n", " 'gamma': [0, 0.1, 0.2],\n", " 'scale_pos_weight': [1, scale_pos_weight] \n", " \n", "}\n", "xgb=XGBClassifier(random_state=42,eval_metric='logloss')\n", "\n", "search=RandomizedSearchCV(\n", " xgb,\n", " param_grid,\n", " n_iter=50,\n", " cv=5,\n", " scoring='f1',\n", " random_state=42,\n", " n_jobs=-1\n", ")\n", "search.fit(x_train,y_train)\n", "\n", "print(\"Best Parameters :\",search.best_params_)\n", "print(\"Best CV F1 Score :\",search.best_score_)\n", "\n", "best_model=search.best_estimator_\n", "y_pred_best=best_model.predict(x_test)\n", "print(\"\\n Test Classification Report :\\n\",classification_report(y_test,y_pred_best))" ] }, { "cell_type": "code", "execution_count": 72, "id": "306142ca", "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "Best Model succesfully saved as best_xgboost_churn_model.pkl\n" ] } ], "source": [ "joblib.dump(best_model,'../Models/best_xgboost_churn_model.pkl')\n", "print(\"Best Model succesfully saved as best_xgboost_churn_model.pkl\")" ] }, { "cell_type": "markdown", "id": "b03efca7", "metadata": {}, "source": [ "## Trying out few more techniques" ] }, { "cell_type": "code", "execution_count": 44, "id": "4dc84363", "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ " precision recall f1-score support\n", "\n", " 0 0.90 0.69 0.78 1003\n", " 1 0.51 0.80 0.62 404\n", "\n", " accuracy 0.72 1407\n", " macro avg 0.70 0.75 0.70 1407\n", "weighted avg 0.79 0.72 0.73 1407\n", "\n" ] } ], "source": [ "model_rf.fit(x_train,y_train)\n", "y_pred_rf=model_rf.predict(x_test)\n", "print(classification_report(y_test,y_pred_rf))" ] }, { "cell_type": "code", "execution_count": 49, "id": "be6b1990", "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ " precision recall f1-score support\n", "\n", " 0 0.88 0.75 0.81 1003\n", " 1 0.54 0.75 0.63 404\n", "\n", " accuracy 0.75 1407\n", " macro avg 0.71 0.75 0.72 1407\n", "weighted avg 0.79 0.75 0.76 1407\n", "\n" ] } ], "source": [ "model_cat.fit(x_train,y_train)\n", "y_pred_cat=model_cat.predict(x_test)\n", "print(classification_report(y_test,y_pred_cat))" ] }, { "cell_type": "code", "execution_count": 74, "id": "df57d1c7", "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ " precision recall f1-score support\n", "\n", " 0 0.89 0.75 0.81 1003\n", " 1 0.55 0.77 0.64 404\n", "\n", " accuracy 0.75 1407\n", " macro avg 0.72 0.76 0.73 1407\n", "weighted avg 0.79 0.75 0.76 1407\n", "\n" ] } ], "source": [ "model_lgb=LGBMClassifier(\n", " scale_pos_weight=scale_pos_weight,\n", " random_state=42\n", ")\n", "model_lgb.fit(x_train,y_train)\n", "y_pred_lgb=model_lgb.predict(x_test)\n", "print(classification_report(y_test,y_pred_lgb))" ] }, { "cell_type": "markdown", "id": "22080bb2", "metadata": {}, "source": [ "## **Optuna fine tuning**" ] }, { "cell_type": "code", "execution_count": 78, "id": "ac11ac90", "metadata": {}, "outputs": [ { "name": "stderr", "output_type": "stream", "text": [ "\u001b[32m[I 2026-07-04 01:42:38,612]\u001b[0m A new study created in memory with name: no-name-e3b71810-d8a7-403a-a957-a5c9ed0fff71\u001b[0m\n", "\u001b[32m[I 2026-07-04 01:42:40,255]\u001b[0m Trial 0 finished with value: 0.5660326680677066 and parameters: {'max_depth': 6, 'learning_rate': 0.24765382274333614, 'n_estimators': 838, 'subsample': 0.6297403143953141, 'colsample_bytree': 0.6595640913101503, 'min_child_weight': 7, 'gamma': 0.48986392846064875, 'reg_alpha': 0.9153000362388155, 'reg_lambda': 1.7294692474844489, 'scale_pos_weight': 2.839590443686007}. Best is trial 0 with value: 0.5660326680677066.\u001b[0m\n", "\u001b[32m[I 2026-07-04 01:42:42,051]\u001b[0m Trial 1 finished with value: 0.5471843433791479 and parameters: {'max_depth': 8, 'learning_rate': 0.08153355937028009, 'n_estimators': 963, 'subsample': 0.8893387094005796, 'colsample_bytree': 0.8439647385563188, 'min_child_weight': 9, 'gamma': 0.23376315172882633, 'reg_alpha': 0.9233427697668368, 'reg_lambda': 1.7272212013359125, 'scale_pos_weight': 1}. Best is trial 0 with value: 0.5660326680677066.\u001b[0m\n", "\u001b[32m[I 2026-07-04 01:42:42,928]\u001b[0m Trial 2 finished with value: 0.5634454251425065 and parameters: {'max_depth': 5, 'learning_rate': 0.0763535973211205, 'n_estimators': 406, 'subsample': 0.6637219623032498, 'colsample_bytree': 0.926363380524291, 'min_child_weight': 9, 'gamma': 0.19911943223209705, 'reg_alpha': 0.9501900600895146, 'reg_lambda': 1.1612578215408211, 'scale_pos_weight': 1}. Best is trial 0 with value: 0.5660326680677066.\u001b[0m\n", "\u001b[32m[I 2026-07-04 01:42:44,678]\u001b[0m Trial 3 finished with value: 0.6103358529403845 and parameters: {'max_depth': 9, 'learning_rate': 0.019044794882047498, 'n_estimators': 691, 'subsample': 0.9364283098891333, 'colsample_bytree': 0.8526429294275786, 'min_child_weight': 8, 'gamma': 0.08653773794788105, 'reg_alpha': 0.022608083781233912, 'reg_lambda': 1.308762866632753, 'scale_pos_weight': 2.839590443686007}. Best is trial 3 with value: 0.6103358529403845.\u001b[0m\n", "\u001b[32m[I 2026-07-04 01:42:45,329]\u001b[0m Trial 4 finished with value: 0.5779530921219661 and parameters: {'max_depth': 10, 'learning_rate': 0.2453682761022505, 'n_estimators': 178, 'subsample': 0.7761236648337454, 'colsample_bytree': 0.7582191537221528, 'min_child_weight': 9, 'gamma': 0.26788534701083716, 'reg_alpha': 0.344448991974864, 'reg_lambda': 0.8015908574936734, 'scale_pos_weight': 2.839590443686007}. Best is trial 3 with value: 0.6103358529403845.\u001b[0m\n", "\u001b[32m[I 2026-07-04 01:42:46,475]\u001b[0m Trial 5 finished with value: 0.5954782705741893 and parameters: {'max_depth': 4, 'learning_rate': 0.14675430699510167, 'n_estimators': 640, 'subsample': 0.8162279491589333, 'colsample_bytree': 0.7908622468717461, 'min_child_weight': 3, 'gamma': 0.26161218570696165, 'reg_alpha': 0.9526785416565647, 'reg_lambda': 1.6833511294113768, 'scale_pos_weight': 2.839590443686007}. Best is trial 3 with value: 0.6103358529403845.\u001b[0m\n", "\u001b[32m[I 2026-07-04 01:42:47,963]\u001b[0m Trial 6 finished with value: 0.5770934469291924 and parameters: {'max_depth': 5, 'learning_rate': 0.011135071593815313, 'n_estimators': 721, 'subsample': 0.9567564950370447, 'colsample_bytree': 0.9902241435276039, 'min_child_weight': 1, 'gamma': 0.08926284991575517, 'reg_alpha': 0.8835149227681423, 'reg_lambda': 0.5961687621029721, 'scale_pos_weight': 1}. Best is trial 3 with value: 0.6103358529403845.\u001b[0m\n", "\u001b[32m[I 2026-07-04 01:42:49,134]\u001b[0m Trial 7 finished with value: 0.5514586397490575 and parameters: {'max_depth': 10, 'learning_rate': 0.20349582904667818, 'n_estimators': 561, 'subsample': 0.7159422302875059, 'colsample_bytree': 0.709022962998488, 'min_child_weight': 1, 'gamma': 0.41086823947247897, 'reg_alpha': 0.3171579663806664, 'reg_lambda': 0.5279935076411995, 'scale_pos_weight': 2.839590443686007}. Best is trial 3 with value: 0.6103358529403845.\u001b[0m\n", "\u001b[32m[I 2026-07-04 01:42:49,932]\u001b[0m Trial 8 finished with value: 0.6058975927670817 and parameters: {'max_depth': 3, 'learning_rate': 0.1375707622636665, 'n_estimators': 457, 'subsample': 0.9751869551981783, 'colsample_bytree': 0.6638748201838587, 'min_child_weight': 3, 'gamma': 0.03588807629541202, 'reg_alpha': 0.27390638317066063, 'reg_lambda': 0.029726469182665527, 'scale_pos_weight': 2.839590443686007}. Best is trial 3 with value: 0.6103358529403845.\u001b[0m\n", "\u001b[32m[I 2026-07-04 01:42:50,779]\u001b[0m Trial 9 finished with value: 0.5700141195166232 and parameters: {'max_depth': 9, 'learning_rate': 0.018441413712343244, 'n_estimators': 229, 'subsample': 0.6986820647471449, 'colsample_bytree': 0.7298941440837479, 'min_child_weight': 3, 'gamma': 0.3598446787782062, 'reg_alpha': 0.6738128268245331, 'reg_lambda': 0.9516764511404041, 'scale_pos_weight': 1}. Best is trial 3 with value: 0.6103358529403845.\u001b[0m\n", "\u001b[32m[I 2026-07-04 01:42:52,747]\u001b[0m Trial 10 finished with value: 0.60144462989895 and parameters: {'max_depth': 8, 'learning_rate': 0.033000383652844044, 'n_estimators': 787, 'subsample': 0.8888122181127704, 'colsample_bytree': 0.8656230165410826, 'min_child_weight': 6, 'gamma': 0.11602521862228832, 'reg_alpha': 0.003168974341651705, 'reg_lambda': 1.3545842949073998, 'scale_pos_weight': 2.839590443686007}. Best is trial 3 with value: 0.6103358529403845.\u001b[0m\n", "\u001b[32m[I 2026-07-04 01:42:53,446]\u001b[0m Trial 11 finished with value: 0.6237456158481202 and parameters: {'max_depth': 3, 'learning_rate': 0.03717720798938069, 'n_estimators': 430, 'subsample': 0.9987712262566768, 'colsample_bytree': 0.6807845443502348, 'min_child_weight': 4, 'gamma': 0.0016857433734748517, 'reg_alpha': 0.02066660946247371, 'reg_lambda': 0.036190009978186666, 'scale_pos_weight': 2.839590443686007}. Best is trial 11 with value: 0.6237456158481202.\u001b[0m\n", "\u001b[32m[I 2026-07-04 01:42:54,365]\u001b[0m Trial 12 finished with value: 0.6157987221164285 and parameters: {'max_depth': 7, 'learning_rate': 0.031580717810388695, 'n_estimators': 363, 'subsample': 0.9130099131375795, 'colsample_bytree': 0.6013371793373713, 'min_child_weight': 7, 'gamma': 0.01566142665097949, 'reg_alpha': 0.06308768235368958, 'reg_lambda': 0.05960193127030211, 'scale_pos_weight': 2.839590443686007}. Best is trial 11 with value: 0.6237456158481202.\u001b[0m\n", "\u001b[32m[I 2026-07-04 01:42:55,260]\u001b[0m Trial 13 finished with value: 0.6096280606229172 and parameters: {'max_depth': 7, 'learning_rate': 0.039569373431234386, 'n_estimators': 327, 'subsample': 0.8834246917842706, 'colsample_bytree': 0.6101515782078707, 'min_child_weight': 5, 'gamma': 0.0008650239170498215, 'reg_alpha': 0.1763038816806753, 'reg_lambda': 0.009718166393977445, 'scale_pos_weight': 2.839590443686007}. Best is trial 11 with value: 0.6237456158481202.\u001b[0m\n", "\u001b[32m[I 2026-07-04 01:42:55,646]\u001b[0m Trial 14 finished with value: 0.6285237148974578 and parameters: {'max_depth': 3, 'learning_rate': 0.03197484073626387, 'n_estimators': 104, 'subsample': 0.9810469805621668, 'colsample_bytree': 0.6130421260223367, 'min_child_weight': 5, 'gamma': 0.14497600286736795, 'reg_alpha': 0.5336248230550522, 'reg_lambda': 0.35598435277694185, 'scale_pos_weight': 2.839590443686007}. Best is trial 14 with value: 0.6285237148974578.\u001b[0m\n", "\u001b[32m[I 2026-07-04 01:42:56,029]\u001b[0m Trial 15 finished with value: 0.6283527071959297 and parameters: {'max_depth': 3, 'learning_rate': 0.05319087011193726, 'n_estimators': 153, 'subsample': 0.9858781165314334, 'colsample_bytree': 0.6878633128651056, 'min_child_weight': 5, 'gamma': 0.1609019907219262, 'reg_alpha': 0.5253115420507704, 'reg_lambda': 0.35533726800491217, 'scale_pos_weight': 2.839590443686007}. Best is trial 14 with value: 0.6285237148974578.\u001b[0m\n", "\u001b[32m[I 2026-07-04 01:42:56,491]\u001b[0m Trial 16 finished with value: 0.6284586287925971 and parameters: {'max_depth': 4, 'learning_rate': 0.05944683447005423, 'n_estimators': 138, 'subsample': 0.829559440674205, 'colsample_bytree': 0.6393765930282056, 'min_child_weight': 5, 'gamma': 0.16968063013118498, 'reg_alpha': 0.54224531625143, 'reg_lambda': 0.3713792639294018, 'scale_pos_weight': 2.839590443686007}. Best is trial 14 with value: 0.6285237148974578.\u001b[0m\n", "\u001b[32m[I 2026-07-04 01:42:57,138]\u001b[0m Trial 17 finished with value: 0.6196363290360571 and parameters: {'max_depth': 4, 'learning_rate': 0.08131614518701663, 'n_estimators': 261, 'subsample': 0.806989213278229, 'colsample_bytree': 0.6426515620505964, 'min_child_weight': 6, 'gamma': 0.3228918014360117, 'reg_alpha': 0.5989013274648908, 'reg_lambda': 0.38995019204367853, 'scale_pos_weight': 2.839590443686007}. Best is trial 14 with value: 0.6285237148974578.\u001b[0m\n", "\u001b[32m[I 2026-07-04 01:42:57,542]\u001b[0m Trial 18 finished with value: 0.5327175931175872 and parameters: {'max_depth': 4, 'learning_rate': 0.021054034201955975, 'n_estimators': 109, 'subsample': 0.8543613997039883, 'colsample_bytree': 0.7517886275496535, 'min_child_weight': 4, 'gamma': 0.16271396289844064, 'reg_alpha': 0.7470857610108796, 'reg_lambda': 0.704087857323238, 'scale_pos_weight': 1}. Best is trial 14 with value: 0.6285237148974578.\u001b[0m\n", "\u001b[32m[I 2026-07-04 01:42:58,267]\u001b[0m Trial 19 finished with value: 0.6192113072755642 and parameters: {'max_depth': 5, 'learning_rate': 0.051510374544441885, 'n_estimators': 277, 'subsample': 0.7458634412954686, 'colsample_bytree': 0.6247029255463326, 'min_child_weight': 7, 'gamma': 0.14877595672631835, 'reg_alpha': 0.437806248147997, 'reg_lambda': 0.3611639336381548, 'scale_pos_weight': 2.839590443686007}. Best is trial 14 with value: 0.6285237148974578.\u001b[0m\n", "\u001b[32m[I 2026-07-04 01:42:59,565]\u001b[0m Trial 20 finished with value: 0.6201421968114824 and parameters: {'max_depth': 6, 'learning_rate': 0.011442282886891086, 'n_estimators': 508, 'subsample': 0.8434039216456987, 'colsample_bytree': 0.8073593312200747, 'min_child_weight': 2, 'gamma': 0.207816201852677, 'reg_alpha': 0.44892093233368624, 'reg_lambda': 0.8834861489076212, 'scale_pos_weight': 2.839590443686007}. Best is trial 14 with value: 0.6285237148974578.\u001b[0m\n", "\u001b[32m[I 2026-07-04 01:42:59,936]\u001b[0m Trial 21 finished with value: 0.627338680701481 and parameters: {'max_depth': 3, 'learning_rate': 0.05645235137254189, 'n_estimators': 101, 'subsample': 0.9358279985203606, 'colsample_bytree': 0.6964695635011785, 'min_child_weight': 5, 'gamma': 0.16502033241848765, 'reg_alpha': 0.5987978824013199, 'reg_lambda': 0.30008094845504707, 'scale_pos_weight': 2.839590443686007}. Best is trial 14 with value: 0.6285237148974578.\u001b[0m\n", "\u001b[32m[I 2026-07-04 01:43:00,384]\u001b[0m Trial 22 finished with value: 0.6211358243306963 and parameters: {'max_depth': 3, 'learning_rate': 0.06473338077079907, 'n_estimators': 187, 'subsample': 0.9913757604279658, 'colsample_bytree': 0.6495932648552286, 'min_child_weight': 4, 'gamma': 0.11575555510573785, 'reg_alpha': 0.5470905485230653, 'reg_lambda': 0.27938295514057365, 'scale_pos_weight': 2.839590443686007}. Best is trial 14 with value: 0.6285237148974578.\u001b[0m\n", "\u001b[32m[I 2026-07-04 01:43:00,827]\u001b[0m Trial 23 finished with value: 0.621637129701169 and parameters: {'max_depth': 4, 'learning_rate': 0.10939810262424786, 'n_estimators': 172, 'subsample': 0.9535118922581586, 'colsample_bytree': 0.7032907616744623, 'min_child_weight': 5, 'gamma': 0.2956962688638488, 'reg_alpha': 0.7594384809880144, 'reg_lambda': 0.5221755992976916, 'scale_pos_weight': 2.839590443686007}. Best is trial 14 with value: 0.6285237148974578.\u001b[0m\n", "\u001b[32m[I 2026-07-04 01:43:01,220]\u001b[0m Trial 24 finished with value: 0.6274846351410205 and parameters: {'max_depth': 3, 'learning_rate': 0.025333077415070997, 'n_estimators': 100, 'subsample': 0.7653662647900545, 'colsample_bytree': 0.6328939933510529, 'min_child_weight': 6, 'gamma': 0.06643032000866782, 'reg_alpha': 0.4760892665209822, 'reg_lambda': 0.16891743872759898, 'scale_pos_weight': 2.839590443686007}. Best is trial 14 with value: 0.6285237148974578.\u001b[0m\n", "\u001b[32m[I 2026-07-04 01:43:01,961]\u001b[0m Trial 25 finished with value: 0.6247371884268154 and parameters: {'max_depth': 4, 'learning_rate': 0.04005209016351726, 'n_estimators': 328, 'subsample': 0.9113731852670582, 'colsample_bytree': 0.6777683284526509, 'min_child_weight': 4, 'gamma': 0.21674829992893685, 'reg_alpha': 0.6768458720458135, 'reg_lambda': 0.704763761960918, 'scale_pos_weight': 2.839590443686007}. Best is trial 14 with value: 0.6285237148974578.\u001b[0m\n", "\u001b[32m[I 2026-07-04 01:43:02,502]\u001b[0m Trial 26 finished with value: 0.5735528936433585 and parameters: {'max_depth': 5, 'learning_rate': 0.046571425766176365, 'n_estimators': 216, 'subsample': 0.8416222336685127, 'colsample_bytree': 0.6012691972606975, 'min_child_weight': 5, 'gamma': 0.13630586639343667, 'reg_alpha': 0.5495631254159169, 'reg_lambda': 0.46161232261998797, 'scale_pos_weight': 1}. Best is trial 14 with value: 0.6285237148974578.\u001b[0m\n", "\u001b[32m[I 2026-07-04 01:43:03,051]\u001b[0m Trial 27 finished with value: 0.6325163751958598 and parameters: {'max_depth': 3, 'learning_rate': 0.02474886856052479, 'n_estimators': 280, 'subsample': 0.9615290994390482, 'colsample_bytree': 0.7401918869490528, 'min_child_weight': 10, 'gamma': 0.18246705572126054, 'reg_alpha': 0.3875590564709742, 'reg_lambda': 0.23184949924221615, 'scale_pos_weight': 2.839590443686007}. Best is trial 27 with value: 0.6325163751958598.\u001b[0m\n", "\u001b[32m[I 2026-07-04 01:43:03,689]\u001b[0m Trial 28 finished with value: 0.6294020340985529 and parameters: {'max_depth': 4, 'learning_rate': 0.01526860956854681, 'n_estimators': 259, 'subsample': 0.9201391071684076, 'colsample_bytree': 0.7359578157963235, 'min_child_weight': 10, 'gamma': 0.19286450563869703, 'reg_alpha': 0.364518098328463, 'reg_lambda': 0.2345043443282011, 'scale_pos_weight': 2.839590443686007}. Best is trial 27 with value: 0.6325163751958598.\u001b[0m\n", "\u001b[32m[I 2026-07-04 01:43:04,545]\u001b[0m Trial 29 finished with value: 0.6247638788906206 and parameters: {'max_depth': 6, 'learning_rate': 0.014524741225567538, 'n_estimators': 291, 'subsample': 0.9632487106372009, 'colsample_bytree': 0.7881036732316526, 'min_child_weight': 10, 'gamma': 0.19301520495036295, 'reg_alpha': 0.3877946071534199, 'reg_lambda': 0.2273140959449505, 'scale_pos_weight': 2.839590443686007}. Best is trial 27 with value: 0.6325163751958598.\u001b[0m\n", "\u001b[32m[I 2026-07-04 01:43:05,685]\u001b[0m Trial 30 finished with value: 0.6209512067989864 and parameters: {'max_depth': 5, 'learning_rate': 0.02544563327430672, 'n_estimators': 573, 'subsample': 0.9240779601387922, 'colsample_bytree': 0.7443184350489174, 'min_child_weight': 10, 'gamma': 0.3773352993637711, 'reg_alpha': 0.24355959368143376, 'reg_lambda': 1.106286582679266, 'scale_pos_weight': 2.839590443686007}. Best is trial 27 with value: 0.6325163751958598.\u001b[0m\n", "\u001b[32m[I 2026-07-04 01:43:06,293]\u001b[0m Trial 31 finished with value: 0.6268629916756235 and parameters: {'max_depth': 4, 'learning_rate': 0.014350719292550067, 'n_estimators': 230, 'subsample': 0.8728840151854369, 'colsample_bytree': 0.7211908183654944, 'min_child_weight': 8, 'gamma': 0.47635002959914274, 'reg_alpha': 0.39070946571551435, 'reg_lambda': 0.18869204369917625, 'scale_pos_weight': 2.839590443686007}. Best is trial 27 with value: 0.6325163751958598.\u001b[0m\n", "\u001b[32m[I 2026-07-04 01:43:07,707]\u001b[0m Trial 32 finished with value: 0.6211375911616732 and parameters: {'max_depth': 3, 'learning_rate': 0.027345619354852437, 'n_estimators': 954, 'subsample': 0.9047176252726, 'colsample_bytree': 0.7678222420963445, 'min_child_weight': 10, 'gamma': 0.23978051806808828, 'reg_alpha': 0.19596649704104518, 'reg_lambda': 0.2058934564128975, 'scale_pos_weight': 2.839590443686007}. Best is trial 27 with value: 0.6325163751958598.\u001b[0m\n", "\u001b[32m[I 2026-07-04 01:43:08,513]\u001b[0m Trial 33 finished with value: 0.6294347064264869 and parameters: {'max_depth': 4, 'learning_rate': 0.014397793356064751, 'n_estimators': 379, 'subsample': 0.9431974934387871, 'colsample_bytree': 0.6608121120208349, 'min_child_weight': 9, 'gamma': 0.20357887900892227, 'reg_alpha': 0.38783703375609146, 'reg_lambda': 1.9557541587362075, 'scale_pos_weight': 2.839590443686007}. Best is trial 27 with value: 0.6325163751958598.\u001b[0m\n", "\u001b[32m[I 2026-07-04 01:43:09,304]\u001b[0m Trial 34 finished with value: 0.5789150160769998 and parameters: {'max_depth': 3, 'learning_rate': 0.0150802384337825, 'n_estimators': 386, 'subsample': 0.9448542784233573, 'colsample_bytree': 0.8098690927638744, 'min_child_weight': 9, 'gamma': 0.2256955341965889, 'reg_alpha': 0.3926272808603945, 'reg_lambda': 1.5761748081226443, 'scale_pos_weight': 1}. Best is trial 27 with value: 0.6325163751958598.\u001b[0m\n", "\u001b[32m[I 2026-07-04 01:43:10,348]\u001b[0m Trial 35 finished with value: 0.6246331003510738 and parameters: {'max_depth': 5, 'learning_rate': 0.02071858076063333, 'n_estimators': 470, 'subsample': 0.6314049046612393, 'colsample_bytree': 0.6637223754913331, 'min_child_weight': 8, 'gamma': 0.1888536197224447, 'reg_alpha': 0.12387057036078986, 'reg_lambda': 1.909933529806811, 'scale_pos_weight': 2.839590443686007}. Best is trial 27 with value: 0.6325163751958598.\u001b[0m\n", "\u001b[32m[I 2026-07-04 01:43:11,099]\u001b[0m Trial 36 finished with value: 0.6318395177951386 and parameters: {'max_depth': 4, 'learning_rate': 0.017093095792146507, 'n_estimators': 330, 'subsample': 0.9686723539123118, 'colsample_bytree': 0.7765976962565332, 'min_child_weight': 9, 'gamma': 0.29600834047153785, 'reg_alpha': 0.30434865280381607, 'reg_lambda': 1.934864665485594, 'scale_pos_weight': 2.839590443686007}. Best is trial 27 with value: 0.6325163751958598.\u001b[0m\n", "\u001b[32m[I 2026-07-04 01:43:12,082]\u001b[0m Trial 37 finished with value: 0.5770257820595208 and parameters: {'max_depth': 6, 'learning_rate': 0.010384817548480588, 'n_estimators': 381, 'subsample': 0.9391977635986248, 'colsample_bytree': 0.8290507216880721, 'min_child_weight': 9, 'gamma': 0.2906704932798833, 'reg_alpha': 0.3155461349066874, 'reg_lambda': 1.9814383047505166, 'scale_pos_weight': 1}. Best is trial 27 with value: 0.6325163751958598.\u001b[0m\n", "\u001b[32m[I 2026-07-04 01:43:12,761]\u001b[0m Trial 38 finished with value: 0.6286244373136749 and parameters: {'max_depth': 4, 'learning_rate': 0.016833251907327797, 'n_estimators': 323, 'subsample': 0.8624184254733532, 'colsample_bytree': 0.8735220938261216, 'min_child_weight': 9, 'gamma': 0.27415717443417653, 'reg_alpha': 0.2510389588841075, 'reg_lambda': 1.8633703551577911, 'scale_pos_weight': 2.839590443686007}. Best is trial 27 with value: 0.6325163751958598.\u001b[0m\n", "\u001b[32m[I 2026-07-04 01:43:13,848]\u001b[0m Trial 39 finished with value: 0.6269802061806405 and parameters: {'max_depth': 5, 'learning_rate': 0.013215697388989082, 'n_estimators': 501, 'subsample': 0.9665332841921797, 'colsample_bytree': 0.7719218235008447, 'min_child_weight': 10, 'gamma': 0.3221484691978095, 'reg_alpha': 0.34793982975446536, 'reg_lambda': 1.4322419796784083, 'scale_pos_weight': 2.839590443686007}. Best is trial 27 with value: 0.6325163751958598.\u001b[0m\n", "\u001b[32m[I 2026-07-04 01:43:14,991]\u001b[0m Trial 40 finished with value: 0.6225658024189046 and parameters: {'max_depth': 4, 'learning_rate': 0.02246297598148952, 'n_estimators': 608, 'subsample': 0.8971082200999903, 'colsample_bytree': 0.9156304587904602, 'min_child_weight': 8, 'gamma': 0.24895092588884046, 'reg_alpha': 0.282973431954078, 'reg_lambda': 1.749255825056371, 'scale_pos_weight': 2.839590443686007}. Best is trial 27 with value: 0.6325163751958598.\u001b[0m\n", "\u001b[32m[I 2026-07-04 01:43:15,797]\u001b[0m Trial 41 finished with value: 0.6250820982924222 and parameters: {'max_depth': 4, 'learning_rate': 0.017295144593110545, 'n_estimators': 328, 'subsample': 0.8738725282580498, 'colsample_bytree': 0.8812792315630029, 'min_child_weight': 9, 'gamma': 0.27659434207590333, 'reg_alpha': 0.2438080812350463, 'reg_lambda': 1.7341588986524668, 'scale_pos_weight': 2.839590443686007}. Best is trial 27 with value: 0.6325163751958598.\u001b[0m\n", "\u001b[32m[I 2026-07-04 01:43:16,517]\u001b[0m Trial 42 finished with value: 0.627450539712426 and parameters: {'max_depth': 4, 'learning_rate': 0.016287656627190634, 'n_estimators': 297, 'subsample': 0.9255487295939864, 'colsample_bytree': 0.8967557512172009, 'min_child_weight': 9, 'gamma': 0.3211271639681522, 'reg_alpha': 0.18138156995134597, 'reg_lambda': 1.8579379451742364, 'scale_pos_weight': 2.839590443686007}. Best is trial 27 with value: 0.6325163751958598.\u001b[0m\n", "\u001b[32m[I 2026-07-04 01:43:17,563]\u001b[0m Trial 43 finished with value: 0.6254747522602739 and parameters: {'max_depth': 5, 'learning_rate': 0.01150557507975385, 'n_estimators': 418, 'subsample': 0.9548443016524054, 'colsample_bytree': 0.8306230968957797, 'min_child_weight': 10, 'gamma': 0.2651222104875728, 'reg_alpha': 0.34929685970873975, 'reg_lambda': 1.5605741902695212, 'scale_pos_weight': 2.839590443686007}. Best is trial 27 with value: 0.6325163751958598.\u001b[0m\n", "\u001b[32m[I 2026-07-04 01:43:18,219]\u001b[0m Trial 44 finished with value: 0.6299163405022393 and parameters: {'max_depth': 4, 'learning_rate': 0.012837683751191622, 'n_estimators': 255, 'subsample': 0.8684405555150344, 'colsample_bytree': 0.9658762395739916, 'min_child_weight': 8, 'gamma': 0.23292593753987814, 'reg_alpha': 0.4303339429165615, 'reg_lambda': 1.8635401004022272, 'scale_pos_weight': 2.839590443686007}. Best is trial 27 with value: 0.6325163751958598.\u001b[0m\n", "\u001b[32m[I 2026-07-04 01:43:18,887]\u001b[0m Trial 45 finished with value: 0.6262010339963899 and parameters: {'max_depth': 5, 'learning_rate': 0.012696229766874187, 'n_estimators': 224, 'subsample': 0.9197400612593227, 'colsample_bytree': 0.9962182518267642, 'min_child_weight': 7, 'gamma': 0.19330239204165156, 'reg_alpha': 0.4297748475052896, 'reg_lambda': 1.6407754851329008, 'scale_pos_weight': 2.839590443686007}. Best is trial 27 with value: 0.6325163751958598.\u001b[0m\n", "\u001b[32m[I 2026-07-04 01:43:19,823]\u001b[0m Trial 46 finished with value: 0.5711678156020424 and parameters: {'max_depth': 6, 'learning_rate': 0.01000980870392902, 'n_estimators': 361, 'subsample': 0.8971257530739752, 'colsample_bytree': 0.7285383866198568, 'min_child_weight': 8, 'gamma': 0.23782335461977072, 'reg_alpha': 0.3091293994551465, 'reg_lambda': 1.9940571183282982, 'scale_pos_weight': 1}. Best is trial 27 with value: 0.6325163751958598.\u001b[0m\n", "\u001b[32m[I 2026-07-04 01:43:20,402]\u001b[0m Trial 47 finished with value: 0.6308152863953684 and parameters: {'max_depth': 3, 'learning_rate': 0.01828487821698274, 'n_estimators': 272, 'subsample': 0.9728066919786282, 'colsample_bytree': 0.9697503070736115, 'min_child_weight': 10, 'gamma': 0.11340731578795553, 'reg_alpha': 0.3830101474165708, 'reg_lambda': 1.0660427701331574, 'scale_pos_weight': 2.839590443686007}. Best is trial 27 with value: 0.6325163751958598.\u001b[0m\n", "\u001b[32m[I 2026-07-04 01:43:21,303]\u001b[0m Trial 48 finished with value: 0.6295581937206994 and parameters: {'max_depth': 3, 'learning_rate': 0.020217032078369543, 'n_estimators': 440, 'subsample': 0.9736198337328096, 'colsample_bytree': 0.9653912061961147, 'min_child_weight': 8, 'gamma': 0.09100302638715473, 'reg_alpha': 0.4848808637202001, 'reg_lambda': 1.1526102733549228, 'scale_pos_weight': 2.839590443686007}. Best is trial 27 with value: 0.6325163751958598.\u001b[0m\n", "\u001b[32m[I 2026-07-04 01:43:22,097]\u001b[0m Trial 49 finished with value: 0.6309034452422712 and parameters: {'max_depth': 3, 'learning_rate': 0.018636565579212717, 'n_estimators': 425, 'subsample': 0.9985669672508172, 'colsample_bytree': 0.9675485459722054, 'min_child_weight': 8, 'gamma': 0.07990745010960057, 'reg_alpha': 0.46886625814122357, 'reg_lambda': 1.2802000895287358, 'scale_pos_weight': 2.839590443686007}. Best is trial 27 with value: 0.6325163751958598.\u001b[0m\n", "\u001b[32m[I 2026-07-04 01:43:22,944]\u001b[0m Trial 50 finished with value: 0.6236754074119608 and parameters: {'max_depth': 3, 'learning_rate': 0.028330708504712483, 'n_estimators': 509, 'subsample': 0.9955272072312099, 'colsample_bytree': 0.9516320283275076, 'min_child_weight': 7, 'gamma': 0.05718590372554848, 'reg_alpha': 0.5988140210990168, 'reg_lambda': 1.2612413156980204, 'scale_pos_weight': 2.839590443686007}. Best is trial 27 with value: 0.6325163751958598.\u001b[0m\n", "\u001b[32m[I 2026-07-04 01:43:23,759]\u001b[0m Trial 51 finished with value: 0.6298243186648581 and parameters: {'max_depth': 3, 'learning_rate': 0.0205749080550903, 'n_estimators': 440, 'subsample': 0.977024500174709, 'colsample_bytree': 0.9635480225897464, 'min_child_weight': 8, 'gamma': 0.09715300297015197, 'reg_alpha': 0.49288514502261904, 'reg_lambda': 1.0689744557117604, 'scale_pos_weight': 2.839590443686007}. Best is trial 27 with value: 0.6325163751958598.\u001b[0m\n", "\u001b[32m[I 2026-07-04 01:43:24,523]\u001b[0m Trial 52 finished with value: 0.6286929094408004 and parameters: {'max_depth': 3, 'learning_rate': 0.023200883458566093, 'n_estimators': 408, 'subsample': 0.9989246627935594, 'colsample_bytree': 0.9754426893344637, 'min_child_weight': 9, 'gamma': 0.10849758219797251, 'reg_alpha': 0.43847894267305243, 'reg_lambda': 1.0347176851067241, 'scale_pos_weight': 2.839590443686007}. Best is trial 27 with value: 0.6325163751958598.\u001b[0m\n", "\u001b[32m[I 2026-07-04 01:43:25,328]\u001b[0m Trial 53 finished with value: 0.6306715838981172 and parameters: {'max_depth': 3, 'learning_rate': 0.01836796386823701, 'n_estimators': 466, 'subsample': 0.9700426193197195, 'colsample_bytree': 0.9373385604901925, 'min_child_weight': 8, 'gamma': 0.05945123715184518, 'reg_alpha': 0.479643295528225, 'reg_lambda': 1.255013461045089, 'scale_pos_weight': 2.839590443686007}. Best is trial 27 with value: 0.6325163751958598.\u001b[0m\n", "\u001b[32m[I 2026-07-04 01:43:26,388]\u001b[0m Trial 54 finished with value: 0.6269077569241832 and parameters: {'max_depth': 3, 'learning_rate': 0.018486612009887278, 'n_estimators': 677, 'subsample': 0.9684978421018895, 'colsample_bytree': 0.9394150669240932, 'min_child_weight': 10, 'gamma': 0.04367180328944524, 'reg_alpha': 0.4207074382687725, 'reg_lambda': 1.248760936219933, 'scale_pos_weight': 2.839590443686007}. Best is trial 27 with value: 0.6325163751958598.\u001b[0m\n", "\u001b[32m[I 2026-07-04 01:43:27,255]\u001b[0m Trial 55 finished with value: 0.6275764148568463 and parameters: {'max_depth': 3, 'learning_rate': 0.01198372109711983, 'n_estimators': 478, 'subsample': 0.9817635084890041, 'colsample_bytree': 0.920801687024561, 'min_child_weight': 8, 'gamma': 0.07167451416897398, 'reg_alpha': 0.29308161090029594, 'reg_lambda': 1.4558707243777278, 'scale_pos_weight': 2.839590443686007}. Best is trial 27 with value: 0.6325163751958598.\u001b[0m\n", "\u001b[32m[I 2026-07-04 01:43:28,133]\u001b[0m Trial 56 finished with value: 0.6166147128011995 and parameters: {'max_depth': 9, 'learning_rate': 0.0178948226693593, 'n_estimators': 197, 'subsample': 0.9551749465666977, 'colsample_bytree': 0.9805123348710029, 'min_child_weight': 7, 'gamma': 0.13239540342150874, 'reg_alpha': 0.46785886131810145, 'reg_lambda': 0.9499911300709225, 'scale_pos_weight': 2.839590443686007}. Best is trial 27 with value: 0.6325163751958598.\u001b[0m\n", "\u001b[32m[I 2026-07-04 01:43:28,672]\u001b[0m Trial 57 finished with value: 0.5824008478251563 and parameters: {'max_depth': 3, 'learning_rate': 0.02969170790449411, 'n_estimators': 251, 'subsample': 0.9790484485447365, 'colsample_bytree': 0.9438054034655704, 'min_child_weight': 9, 'gamma': 0.027691369233869015, 'reg_alpha': 0.6403968640978296, 'reg_lambda': 1.3693039936594575, 'scale_pos_weight': 1}. Best is trial 27 with value: 0.6325163751958598.\u001b[0m\n", "\u001b[32m[I 2026-07-04 01:43:29,425]\u001b[0m Trial 58 finished with value: 0.6268375258781302 and parameters: {'max_depth': 3, 'learning_rate': 0.024191005281609956, 'n_estimators': 351, 'subsample': 0.9998516698534451, 'colsample_bytree': 0.9056670504812955, 'min_child_weight': 10, 'gamma': 0.04875188087109246, 'reg_alpha': 0.5206113312709858, 'reg_lambda': 0.8341377238960581, 'scale_pos_weight': 2.839590443686007}. Best is trial 27 with value: 0.6325163751958598.\u001b[0m\n", "\u001b[32m[I 2026-07-04 01:43:30,467]\u001b[0m Trial 59 finished with value: 0.6182577622580451 and parameters: {'max_depth': 8, 'learning_rate': 0.03448294869616284, 'n_estimators': 302, 'subsample': 0.6807382903636798, 'colsample_bytree': 0.9833850699092014, 'min_child_weight': 6, 'gamma': 0.08461489650277378, 'reg_alpha': 0.3337929926351392, 'reg_lambda': 1.2146587820780406, 'scale_pos_weight': 2.839590443686007}. Best is trial 27 with value: 0.6325163751958598.\u001b[0m\n", "\u001b[32m[I 2026-07-04 01:43:31,557]\u001b[0m Trial 60 finished with value: 0.6290793842309428 and parameters: {'max_depth': 4, 'learning_rate': 0.012894454334901091, 'n_estimators': 539, 'subsample': 0.9303329601519085, 'colsample_bytree': 0.9666690909428726, 'min_child_weight': 7, 'gamma': 0.11922414792754218, 'reg_alpha': 0.4122188922355722, 'reg_lambda': 1.7915103927774836, 'scale_pos_weight': 2.839590443686007}. Best is trial 27 with value: 0.6325163751958598.\u001b[0m\n", "\u001b[32m[I 2026-07-04 01:43:32,392]\u001b[0m Trial 61 finished with value: 0.6322494804663179 and parameters: {'max_depth': 3, 'learning_rate': 0.019470387632702608, 'n_estimators': 457, 'subsample': 0.794119764352456, 'colsample_bytree': 0.9567521300623514, 'min_child_weight': 8, 'gamma': 0.10742663244059122, 'reg_alpha': 0.5001107339020756, 'reg_lambda': 1.0273575207538594, 'scale_pos_weight': 2.839590443686007}. Best is trial 27 with value: 0.6325163751958598.\u001b[0m\n", "\u001b[32m[I 2026-07-04 01:43:33,212]\u001b[0m Trial 62 finished with value: 0.6026840445235211 and parameters: {'max_depth': 3, 'learning_rate': 0.2823100803735873, 'n_estimators': 411, 'subsample': 0.7968008989978732, 'colsample_bytree': 0.9316145578903378, 'min_child_weight': 8, 'gamma': 0.01936385865679923, 'reg_alpha': 0.5819890809301851, 'reg_lambda': 0.9827209996455736, 'scale_pos_weight': 2.839590443686007}. Best is trial 27 with value: 0.6325163751958598.\u001b[0m\n", "\u001b[32m[I 2026-07-04 01:43:34,992]\u001b[0m Trial 63 finished with value: 0.6135497625631334 and parameters: {'max_depth': 10, 'learning_rate': 0.016313695239227575, 'n_estimators': 553, 'subsample': 0.77412960068241, 'colsample_bytree': 0.9999615547398215, 'min_child_weight': 9, 'gamma': 0.06798593205310408, 'reg_alpha': 0.5212264086806804, 'reg_lambda': 0.7599622765153544, 'scale_pos_weight': 2.839590443686007}. Best is trial 27 with value: 0.6325163751958598.\u001b[0m\n", "\u001b[32m[I 2026-07-04 01:43:35,677]\u001b[0m Trial 64 finished with value: 0.6314818137952951 and parameters: {'max_depth': 3, 'learning_rate': 0.01881734398583274, 'n_estimators': 352, 'subsample': 0.7920746143103404, 'colsample_bytree': 0.9571377631036787, 'min_child_weight': 9, 'gamma': 0.13154026413822642, 'reg_alpha': 0.4665997117177509, 'reg_lambda': 0.8857956195926995, 'scale_pos_weight': 2.839590443686007}. Best is trial 27 with value: 0.6325163751958598.\u001b[0m\n", "\u001b[32m[I 2026-07-04 01:43:36,352]\u001b[0m Trial 65 finished with value: 0.6287929100124103 and parameters: {'max_depth': 3, 'learning_rate': 0.02265301278151405, 'n_estimators': 333, 'subsample': 0.7435634558057671, 'colsample_bytree': 0.9512049137489096, 'min_child_weight': 10, 'gamma': 0.17611329366969897, 'reg_alpha': 0.45998647377287877, 'reg_lambda': 0.8756756232027909, 'scale_pos_weight': 2.839590443686007}. Best is trial 27 with value: 0.6325163751958598.\u001b[0m\n", "\u001b[32m[I 2026-07-04 01:43:37,158]\u001b[0m Trial 66 finished with value: 0.6310314632582347 and parameters: {'max_depth': 3, 'learning_rate': 0.018997217480698773, 'n_estimators': 453, 'subsample': 0.793957790487743, 'colsample_bytree': 0.9275357267040488, 'min_child_weight': 9, 'gamma': 0.12938544967870164, 'reg_alpha': 0.4891150549693567, 'reg_lambda': 0.6083336408048847, 'scale_pos_weight': 2.839590443686007}. Best is trial 27 with value: 0.6325163751958598.\u001b[0m\n", "\u001b[32m[I 2026-07-04 01:43:37,934]\u001b[0m Trial 67 finished with value: 0.619321023876657 and parameters: {'max_depth': 3, 'learning_rate': 0.09600307171668618, 'n_estimators': 391, 'subsample': 0.795195287622123, 'colsample_bytree': 0.7789118116156617, 'min_child_weight': 9, 'gamma': 0.1515550829002592, 'reg_alpha': 0.5628978400757831, 'reg_lambda': 0.5989385986636185, 'scale_pos_weight': 2.839590443686007}. Best is trial 27 with value: 0.6325163751958598.\u001b[0m\n", "\u001b[32m[I 2026-07-04 01:43:39,348]\u001b[0m Trial 68 finished with value: 0.6133674886355427 and parameters: {'max_depth': 7, 'learning_rate': 0.02638827225879779, 'n_estimators': 593, 'subsample': 0.8124071957455522, 'colsample_bytree': 0.8931032281557565, 'min_child_weight': 10, 'gamma': 0.12384254195743076, 'reg_alpha': 0.6548706262862657, 'reg_lambda': 0.6429401566778397, 'scale_pos_weight': 2.839590443686007}. Best is trial 27 with value: 0.6325163751958598.\u001b[0m\n", "\u001b[32m[I 2026-07-04 01:43:40,216]\u001b[0m Trial 69 finished with value: 0.5776853298584683 and parameters: {'max_depth': 3, 'learning_rate': 0.019498711079593653, 'n_estimators': 496, 'subsample': 0.82995590490217, 'colsample_bytree': 0.7546926940586809, 'min_child_weight': 10, 'gamma': 0.10083319541655587, 'reg_alpha': 0.3756158447725527, 'reg_lambda': 0.4384084126038019, 'scale_pos_weight': 1}. Best is trial 27 with value: 0.6325163751958598.\u001b[0m\n", "\u001b[32m[I 2026-07-04 01:43:41,171]\u001b[0m Trial 70 finished with value: 0.6228077370575741 and parameters: {'max_depth': 3, 'learning_rate': 0.030740481207986586, 'n_estimators': 528, 'subsample': 0.7828952971397559, 'colsample_bytree': 0.8519811784256984, 'min_child_weight': 9, 'gamma': 0.13257014544262877, 'reg_alpha': 0.7301079854498176, 'reg_lambda': 0.934708141708916, 'scale_pos_weight': 2.839590443686007}. Best is trial 27 with value: 0.6325163751958598.\u001b[0m\n", "\u001b[32m[I 2026-07-04 01:43:42,002]\u001b[0m Trial 71 finished with value: 0.6321341759409684 and parameters: {'max_depth': 3, 'learning_rate': 0.01882242448042738, 'n_estimators': 453, 'subsample': 0.744858860118279, 'colsample_bytree': 0.9298330178126452, 'min_child_weight': 8, 'gamma': 0.0814476650394488, 'reg_alpha': 0.49569729051306993, 'reg_lambda': 1.1477885313998448, 'scale_pos_weight': 2.839590443686007}. Best is trial 27 with value: 0.6325163751958598.\u001b[0m\n", "\u001b[32m[I 2026-07-04 01:43:42,807]\u001b[0m Trial 72 finished with value: 0.6309492629770226 and parameters: {'max_depth': 3, 'learning_rate': 0.022062254953832267, 'n_estimators': 444, 'subsample': 0.7476568808652531, 'colsample_bytree': 0.9524905885445596, 'min_child_weight': 9, 'gamma': 0.07743122844614149, 'reg_alpha': 0.4994291828904674, 'reg_lambda': 1.070326933961579, 'scale_pos_weight': 2.839590443686007}. Best is trial 27 with value: 0.6325163751958598.\u001b[0m\n", "\u001b[32m[I 2026-07-04 01:43:43,674]\u001b[0m Trial 73 finished with value: 0.6291265430173324 and parameters: {'max_depth': 4, 'learning_rate': 0.015870781904961308, 'n_estimators': 444, 'subsample': 0.7286332751310706, 'colsample_bytree': 0.9537598604639638, 'min_child_weight': 9, 'gamma': 0.08044430994222516, 'reg_alpha': 0.49931409845291996, 'reg_lambda': 0.12109257517199057, 'scale_pos_weight': 2.839590443686007}. Best is trial 27 with value: 0.6325163751958598.\u001b[0m\n", "\u001b[32m[I 2026-07-04 01:43:44,688]\u001b[0m Trial 74 finished with value: 0.6317642601298364 and parameters: {'max_depth': 3, 'learning_rate': 0.02210891803045756, 'n_estimators': 480, 'subsample': 0.7554643783373941, 'colsample_bytree': 0.9209474266074326, 'min_child_weight': 8, 'gamma': 0.14971707331659428, 'reg_alpha': 0.5133145623387348, 'reg_lambda': 0.799491172747513, 'scale_pos_weight': 2.839590443686007}. Best is trial 27 with value: 0.6325163751958598.\u001b[0m\n", "\u001b[32m[I 2026-07-04 01:43:45,600]\u001b[0m Trial 75 finished with value: 0.6305968188652608 and parameters: {'max_depth': 3, 'learning_rate': 0.021607542972110684, 'n_estimators': 483, 'subsample': 0.7511031883185688, 'colsample_bytree': 0.9164360530419347, 'min_child_weight': 9, 'gamma': 0.1511386506851963, 'reg_alpha': 0.5241111415872278, 'reg_lambda': 0.7541499992870131, 'scale_pos_weight': 2.839590443686007}. Best is trial 27 with value: 0.6325163751958598.\u001b[0m\n", "\u001b[32m[I 2026-07-04 01:43:46,337]\u001b[0m Trial 76 finished with value: 0.6235975841419907 and parameters: {'max_depth': 4, 'learning_rate': 0.03711806790906562, 'n_estimators': 356, 'subsample': 0.708482634903817, 'colsample_bytree': 0.9023838685085119, 'min_child_weight': 9, 'gamma': 0.17991648068859337, 'reg_alpha': 0.6320404694205175, 'reg_lambda': 1.1682266549841809, 'scale_pos_weight': 2.839590443686007}. Best is trial 27 with value: 0.6325163751958598.\u001b[0m\n", "\u001b[32m[I 2026-07-04 01:43:47,259]\u001b[0m Trial 77 finished with value: 0.6254548532277784 and parameters: {'max_depth': 4, 'learning_rate': 0.02439816042302239, 'n_estimators': 465, 'subsample': 0.7623965700535905, 'colsample_bytree': 0.9323879594122115, 'min_child_weight': 7, 'gamma': 0.14927363709465655, 'reg_alpha': 0.5717637281799537, 'reg_lambda': 0.9115794489392373, 'scale_pos_weight': 2.839590443686007}. Best is trial 27 with value: 0.6325163751958598.\u001b[0m\n", "\u001b[32m[I 2026-07-04 01:43:48,425]\u001b[0m Trial 78 finished with value: 0.6024540688199179 and parameters: {'max_depth': 3, 'learning_rate': 0.2028919623945348, 'n_estimators': 577, 'subsample': 0.7324764864719263, 'colsample_bytree': 0.7977737844612349, 'min_child_weight': 8, 'gamma': 0.1023811849646529, 'reg_alpha': 0.6222882170817399, 'reg_lambda': 1.0175438321227923, 'scale_pos_weight': 2.839590443686007}. Best is trial 27 with value: 0.6325163751958598.\u001b[0m\n", "\u001b[32m[I 2026-07-04 01:43:49,378]\u001b[0m Trial 79 finished with value: 0.631434027714475 and parameters: {'max_depth': 3, 'learning_rate': 0.014268771630575036, 'n_estimators': 524, 'subsample': 0.7853084372987779, 'colsample_bytree': 0.8861860896857362, 'min_child_weight': 9, 'gamma': 0.16309847416291018, 'reg_alpha': 0.5076437756740007, 'reg_lambda': 0.8356660303492766, 'scale_pos_weight': 2.839590443686007}. Best is trial 27 with value: 0.6325163751958598.\u001b[0m\n", "\u001b[32m[I 2026-07-04 01:43:50,785]\u001b[0m Trial 80 finished with value: 0.6232285013177586 and parameters: {'max_depth': 4, 'learning_rate': 0.013674563888360414, 'n_estimators': 755, 'subsample': 0.7634167450078894, 'colsample_bytree': 0.9104191783491885, 'min_child_weight': 8, 'gamma': 0.16472410183859765, 'reg_alpha': 0.5441476441824513, 'reg_lambda': 0.8106148427789703, 'scale_pos_weight': 2.839590443686007}. Best is trial 27 with value: 0.6325163751958598.\u001b[0m\n", "\u001b[32m[I 2026-07-04 01:43:51,813]\u001b[0m Trial 81 finished with value: 0.6307153149286808 and parameters: {'max_depth': 3, 'learning_rate': 0.02182276643389551, 'n_estimators': 516, 'subsample': 0.7890879502181929, 'colsample_bytree': 0.9266529057268603, 'min_child_weight': 9, 'gamma': 0.13754445997328255, 'reg_alpha': 0.5142757468603877, 'reg_lambda': 0.7720076037375054, 'scale_pos_weight': 2.839590443686007}. Best is trial 27 with value: 0.6325163751958598.\u001b[0m\n", "\u001b[32m[I 2026-07-04 01:43:52,599]\u001b[0m Trial 82 finished with value: 0.6295820675661943 and parameters: {'max_depth': 3, 'learning_rate': 0.016390199513203602, 'n_estimators': 400, 'subsample': 0.8052949376393256, 'colsample_bytree': 0.885722475726747, 'min_child_weight': 9, 'gamma': 0.21439979125927927, 'reg_alpha': 0.4989525849821872, 'reg_lambda': 0.6733769100544952, 'scale_pos_weight': 2.839590443686007}. Best is trial 27 with value: 0.6325163751958598.\u001b[0m\n", "\u001b[32m[I 2026-07-04 01:43:53,667]\u001b[0m Trial 83 finished with value: 0.6304459360424051 and parameters: {'max_depth': 3, 'learning_rate': 0.014756150440301064, 'n_estimators': 652, 'subsample': 0.7770295064768832, 'colsample_bytree': 0.9450525630625354, 'min_child_weight': 9, 'gamma': 0.34197155045248895, 'reg_alpha': 0.41113833807810163, 'reg_lambda': 0.5466455177092915, 'scale_pos_weight': 2.839590443686007}. Best is trial 27 with value: 0.6325163751958598.\u001b[0m\n", "\u001b[32m[I 2026-07-04 01:43:54,530]\u001b[0m Trial 84 finished with value: 0.6246346235583854 and parameters: {'max_depth': 3, 'learning_rate': 0.02830781938635519, 'n_estimators': 537, 'subsample': 0.8184379818506294, 'colsample_bytree': 0.9553174566452385, 'min_child_weight': 9, 'gamma': 0.12233214567640766, 'reg_alpha': 0.44446118640556503, 'reg_lambda': 0.8902422709042423, 'scale_pos_weight': 2.839590443686007}. Best is trial 27 with value: 0.6325163751958598.\u001b[0m\n", "\u001b[32m[I 2026-07-04 01:43:55,450]\u001b[0m Trial 85 finished with value: 0.628518388381819 and parameters: {'max_depth': 4, 'learning_rate': 0.019880259122541835, 'n_estimators': 449, 'subsample': 0.752414411477313, 'colsample_bytree': 0.8670936254827964, 'min_child_weight': 10, 'gamma': 0.18113025883206163, 'reg_alpha': 0.5604714160972599, 'reg_lambda': 1.103742225840092, 'scale_pos_weight': 2.839590443686007}. Best is trial 27 with value: 0.6325163751958598.\u001b[0m\n", "\u001b[32m[I 2026-07-04 01:43:56,815]\u001b[0m Trial 86 finished with value: 0.5640356228793024 and parameters: {'max_depth': 3, 'learning_rate': 0.04371501520733904, 'n_estimators': 881, 'subsample': 0.823801231277905, 'colsample_bytree': 0.7137013723039602, 'min_child_weight': 8, 'gamma': 0.160376872301931, 'reg_alpha': 0.5900083907252642, 'reg_lambda': 0.8423016518819466, 'scale_pos_weight': 1}. Best is trial 27 with value: 0.6325163751958598.\u001b[0m\n", "\u001b[32m[I 2026-07-04 01:43:57,949]\u001b[0m Trial 87 finished with value: 0.6335426701708246 and parameters: {'max_depth': 3, 'learning_rate': 0.017015318359525567, 'n_estimators': 627, 'subsample': 0.7295758405266288, 'colsample_bytree': 0.7459064174464416, 'min_child_weight': 10, 'gamma': 0.1362440638789693, 'reg_alpha': 0.9069637219423553, 'reg_lambda': 0.7304480128259802, 'scale_pos_weight': 2.839590443686007}. Best is trial 87 with value: 0.6335426701708246.\u001b[0m\n", "\u001b[32m[I 2026-07-04 01:43:59,135]\u001b[0m Trial 88 finished with value: 0.6291766333070222 and parameters: {'max_depth': 4, 'learning_rate': 0.013920889281633547, 'n_estimators': 609, 'subsample': 0.7254602658309548, 'colsample_bytree': 0.7665252432379809, 'min_child_weight': 10, 'gamma': 0.13909465948145153, 'reg_alpha': 0.919480317351701, 'reg_lambda': 0.687966895599273, 'scale_pos_weight': 2.839590443686007}. Best is trial 87 with value: 0.6335426701708246.\u001b[0m\n", "\u001b[32m[I 2026-07-04 01:44:00,155]\u001b[0m Trial 89 finished with value: 0.6320649427658658 and parameters: {'max_depth': 3, 'learning_rate': 0.017077568253944155, 'n_estimators': 623, 'subsample': 0.7708784135592411, 'colsample_bytree': 0.745973240976159, 'min_child_weight': 10, 'gamma': 0.4596267960267673, 'reg_alpha': 0.8237508317886764, 'reg_lambda': 0.5931472704011783, 'scale_pos_weight': 2.839590443686007}. Best is trial 87 with value: 0.6335426701708246.\u001b[0m\n", "\u001b[32m[I 2026-07-04 01:44:01,271]\u001b[0m Trial 90 finished with value: 0.6292504882974582 and parameters: {'max_depth': 3, 'learning_rate': 0.011027429233346321, 'n_estimators': 642, 'subsample': 0.6857843145839766, 'colsample_bytree': 0.7416866718463596, 'min_child_weight': 2, 'gamma': 0.4864464337811501, 'reg_alpha': 0.8769795077403493, 'reg_lambda': 0.736579190120106, 'scale_pos_weight': 2.839590443686007}. Best is trial 87 with value: 0.6335426701708246.\u001b[0m\n", "\u001b[32m[I 2026-07-04 01:44:02,470]\u001b[0m Trial 91 finished with value: 0.6313037726319802 and parameters: {'max_depth': 3, 'learning_rate': 0.015520962181479862, 'n_estimators': 711, 'subsample': 0.7691301023962323, 'colsample_bytree': 0.7438732956369571, 'min_child_weight': 10, 'gamma': 0.41810302695575263, 'reg_alpha': 0.9584939592137178, 'reg_lambda': 0.6212601349069151, 'scale_pos_weight': 2.839590443686007}. Best is trial 87 with value: 0.6335426701708246.\u001b[0m\n", "\u001b[32m[I 2026-07-04 01:44:03,642]\u001b[0m Trial 92 finished with value: 0.6293424288862965 and parameters: {'max_depth': 3, 'learning_rate': 0.017212772728295415, 'n_estimators': 726, 'subsample': 0.7697447525517687, 'colsample_bytree': 0.7247947672314926, 'min_child_weight': 10, 'gamma': 0.4339330070769268, 'reg_alpha': 0.9525220434123788, 'reg_lambda': 0.5413501794395839, 'scale_pos_weight': 2.839590443686007}. Best is trial 87 with value: 0.6335426701708246.\u001b[0m\n", "\u001b[32m[I 2026-07-04 01:44:04,759]\u001b[0m Trial 93 finished with value: 0.6304824634620104 and parameters: {'max_depth': 3, 'learning_rate': 0.01573271329882548, 'n_estimators': 673, 'subsample': 0.7841442445332585, 'colsample_bytree': 0.7494145683948273, 'min_child_weight': 10, 'gamma': 0.45296006047847903, 'reg_alpha': 0.8614519959677756, 'reg_lambda': 0.2842644794455195, 'scale_pos_weight': 2.839590443686007}. Best is trial 87 with value: 0.6335426701708246.\u001b[0m\n", "\u001b[32m[I 2026-07-04 01:44:05,904]\u001b[0m Trial 94 finished with value: 0.6323420276519868 and parameters: {'max_depth': 3, 'learning_rate': 0.015374859138072024, 'n_estimators': 704, 'subsample': 0.7375644345836402, 'colsample_bytree': 0.7609355559847963, 'min_child_weight': 10, 'gamma': 0.39544607807501886, 'reg_alpha': 0.986513509026849, 'reg_lambda': 0.47252173264977315, 'scale_pos_weight': 2.839590443686007}. Best is trial 87 with value: 0.6335426701708246.\u001b[0m\n", "\u001b[32m[I 2026-07-04 01:44:07,093]\u001b[0m Trial 95 finished with value: 0.6295050068371351 and parameters: {'max_depth': 4, 'learning_rate': 0.01377957668534696, 'n_estimators': 621, 'subsample': 0.711738752950559, 'colsample_bytree': 0.7838809017899038, 'min_child_weight': 10, 'gamma': 0.49753098613211383, 'reg_alpha': 0.9813993930788928, 'reg_lambda': 0.4338559883267411, 'scale_pos_weight': 2.839590443686007}. Best is trial 87 with value: 0.6335426701708246.\u001b[0m\n", "\u001b[32m[I 2026-07-04 01:44:08,310]\u001b[0m Trial 96 finished with value: 0.6310342428784304 and parameters: {'max_depth': 3, 'learning_rate': 0.011986448257823629, 'n_estimators': 801, 'subsample': 0.7360771467653938, 'colsample_bytree': 0.7604455387840648, 'min_child_weight': 10, 'gamma': 0.369006618551011, 'reg_alpha': 0.9047411117098411, 'reg_lambda': 0.4982345040477056, 'scale_pos_weight': 2.839590443686007}. Best is trial 87 with value: 0.6335426701708246.\u001b[0m\n", "\u001b[32m[I 2026-07-04 01:44:09,284]\u001b[0m Trial 97 finished with value: 0.6159059388803241 and parameters: {'max_depth': 3, 'learning_rate': 0.0697804822702569, 'n_estimators': 566, 'subsample': 0.7205384515653657, 'colsample_bytree': 0.8119060796125295, 'min_child_weight': 10, 'gamma': 0.39423824566179, 'reg_alpha': 0.8021266982673076, 'reg_lambda': 0.10032991187370605, 'scale_pos_weight': 2.839590443686007}. Best is trial 87 with value: 0.6335426701708246.\u001b[0m\n", "\u001b[32m[I 2026-07-04 01:44:10,346]\u001b[0m Trial 98 finished with value: 0.6305571396942321 and parameters: {'max_depth': 4, 'learning_rate': 0.017323520493718596, 'n_estimators': 587, 'subsample': 0.7594041620115869, 'colsample_bytree': 0.7738375685765383, 'min_child_weight': 10, 'gamma': 0.34320677785408604, 'reg_alpha': 0.8534352166930692, 'reg_lambda': 0.9863000749166858, 'scale_pos_weight': 2.839590443686007}. Best is trial 87 with value: 0.6335426701708246.\u001b[0m\n", "\u001b[32m[I 2026-07-04 01:44:11,683]\u001b[0m Trial 99 finished with value: 0.5779919516643396 and parameters: {'max_depth': 3, 'learning_rate': 0.02008326809044712, 'n_estimators': 626, 'subsample': 0.6929772469417467, 'colsample_bytree': 0.6999441552074822, 'min_child_weight': 10, 'gamma': 0.11191595251579314, 'reg_alpha': 0.9886156761596717, 'reg_lambda': 0.7165161951447678, 'scale_pos_weight': 1}. Best is trial 87 with value: 0.6335426701708246.\u001b[0m\n" ] }, { "name": "stdout", "output_type": "stream", "text": [ "Best Parameters : {'max_depth': 3, 'learning_rate': 0.017015318359525567, 'n_estimators': 627, 'subsample': 0.7295758405266288, 'colsample_bytree': 0.7459064174464416, 'min_child_weight': 10, 'gamma': 0.1362440638789693, 'reg_alpha': 0.9069637219423553, 'reg_lambda': 0.7304480128259802, 'scale_pos_weight': 2.839590443686007}\n", "Best CV F1 Score : 0.6335426701708246\n", " precision recall f1-score support\n", "\n", " 0 0.90 0.71 0.80 1003\n", " 1 0.53 0.81 0.64 404\n", "\n", " accuracy 0.74 1407\n", " macro avg 0.72 0.76 0.72 1407\n", "weighted avg 0.80 0.74 0.75 1407\n", "\n" ] } ], "source": [ "def objective(trial):\n", " params = {\n", " 'max_depth': trial.suggest_int('max_depth', 3, 10),\n", " 'learning_rate': trial.suggest_float('learning_rate', 0.01, 0.3, log=True),\n", " 'n_estimators': trial.suggest_int('n_estimators', 100, 1000),\n", " 'subsample': trial.suggest_float('subsample', 0.6, 1.0),\n", " 'colsample_bytree': trial.suggest_float('colsample_bytree', 0.6, 1.0),\n", " 'min_child_weight': trial.suggest_int('min_child_weight', 1, 10),\n", " 'gamma': trial.suggest_float('gamma', 0, 0.5),\n", " 'reg_alpha': trial.suggest_float('reg_alpha', 0, 1), # L1 regularization\n", " 'reg_lambda': trial.suggest_float('reg_lambda', 0, 2), # L2 regularization\n", " 'scale_pos_weight': trial.suggest_categorical('scale_pos_weight', [1, scale_pos_weight]),\n", " 'random_state': 42,\n", " 'eval_metric': 'logloss'\n", " }\n", " model=XGBClassifier(**params)\n", "\n", " f1_scorer=make_scorer(f1_score,average='binary',pos_label=1)\n", " score=cross_val_score(model,x_train,y_train,cv=5,scoring=f1_scorer,n_jobs=-1).mean()\n", "\n", " return score\n", "study=optuna.create_study(direction='maximize')\n", "study.optimize(objective,n_trials=100)\n", "\n", "print(\"Best Parameters : \",study.best_params)\n", "print(\"Best CV F1 Score : \",study.best_value)\n", "\n", "best_model_optuna=XGBClassifier(**study.best_params)\n", "best_model_optuna.fit(x_train,y_train)\n", "y_pred_optuna=best_model_optuna.predict(x_test)\n", "print(classification_report(y_test,y_pred_optuna))" ] }, { "cell_type": "code", "execution_count": 79, "id": "012644ef", "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "Best Model is saved as Best_optuna_churn_model.pkl\n" ] } ], "source": [ "joblib.dump(best_model_optuna,'../Models/Best_optuna_churn_model.pkl')\n", "print(\"Best Model is saved as Best_optuna_churn_model.pkl\")" ] }, { "cell_type": "code", "execution_count": 80, "id": "d28376cf", "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "Best Model succesfully saved as Ada_boost_churn_model.pkl\n" ] } ], "source": [ "joblib.dump(model_ada_weighted,'../Models/Ada_boost_churn_model.pkl')\n", "print(\"Best Model succesfully saved as Ada_boost_churn_model.pkl\")" ] } ], "metadata": { "kernelspec": { "display_name": "ai-ml", "language": "python", "name": "python3" }, "language_info": { "codemirror_mode": { "name": "ipython", "version": 3 }, "file_extension": ".py", "mimetype": "text/x-python", "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", "version": "3.11.15" } }, "nbformat": 4, "nbformat_minor": 5 }