{"metadata":{"kernelspec":{"language":"python","display_name":"Python 3","name":"python3"},"language_info":{"name":"python","version":"3.11.13","mimetype":"text/x-python","codemirror_mode":{"name":"ipython","version":3},"pygments_lexer":"ipython3","nbconvert_exporter":"python","file_extension":".py"},"kaggle":{"accelerator":"none","dataSources":[{"sourceId":43340,"databundleVersionId":4694702,"sourceType":"competition"}],"dockerImageVersionId":31089,"isInternetEnabled":true,"language":"python","sourceType":"notebook","isGpuEnabled":false}},"nbformat_minor":4,"nbformat":4,"cells":[{"cell_type":"code","source":"import os\nfor dirname, _, filenames in os.walk('/kaggle/input'):\n    for filename in filenames:\n        print(os.path.join(dirname, filename))","metadata":{"_uuid":"8f2839f25d086af736a60e9eeb907d3b93b6e0e5","_cell_guid":"b1076dfc-b9ad-4769-8c92-a6c4dae69d19","trusted":true,"execution":{"iopub.status.busy":"2025-09-20T14:51:43.533390Z","iopub.execute_input":"2025-09-20T14:51:43.533594Z","iopub.status.idle":"2025-09-20T14:51:43.543384Z","shell.execute_reply.started":"2025-09-20T14:51:43.533574Z","shell.execute_reply":"2025-09-20T14:51:43.542490Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"import pandas as pd\nimport numpy as np\nimport matplotlib.pyplot as plt\nimport seaborn as sns","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-09-20T14:51:43.544371Z","iopub.execute_input":"2025-09-20T14:51:43.544711Z","iopub.status.idle":"2025-09-20T14:51:48.101444Z","shell.execute_reply.started":"2025-09-20T14:51:43.544689Z","shell.execute_reply":"2025-09-20T14:51:48.100473Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"train_df = pd.read_csv(\"/kaggle/input/emsi-5iir-ds/train.csv\")","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-09-20T15:40:27.071571Z","iopub.execute_input":"2025-09-20T15:40:27.071913Z","iopub.status.idle":"2025-09-20T15:40:32.757366Z","shell.execute_reply.started":"2025-09-20T15:40:27.071887Z","shell.execute_reply":"2025-09-20T15:40:32.756150Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"train_df.info()","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-09-20T15:11:36.999792Z","iopub.execute_input":"2025-09-20T15:11:37.000121Z","iopub.status.idle":"2025-09-20T15:11:37.093636Z","shell.execute_reply.started":"2025-09-20T15:11:37.000096Z","shell.execute_reply":"2025-09-20T15:11:37.092595Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"train_df.describe().T","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-09-20T14:51:59.138515Z","iopub.execute_input":"2025-09-20T14:51:59.138843Z","iopub.status.idle":"2025-09-20T14:52:00.468211Z","shell.execute_reply.started":"2025-09-20T14:51:59.138813Z","shell.execute_reply":"2025-09-20T14:52:00.467229Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"train_df.T","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-09-20T14:52:00.469167Z","iopub.execute_input":"2025-09-20T14:52:00.469446Z","iopub.status.idle":"2025-09-20T14:52:00.620136Z","shell.execute_reply.started":"2025-09-20T14:52:00.469425Z","shell.execute_reply":"2025-09-20T14:52:00.619130Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"from sklearn.model_selection import train_test_split\nfrom sklearn.preprocessing import StandardScaler, RobustScaler\nfrom sklearn.linear_model import LogisticRegression\nfrom sklearn.metrics import classification_report, roc_auc_score\nfrom xgboost import XGBClassifier\nfrom lightgbm import LGBMClassifier","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-09-20T15:05:42.791239Z","iopub.execute_input":"2025-09-20T15:05:42.791636Z","iopub.status.idle":"2025-09-20T15:05:42.797157Z","shell.execute_reply.started":"2025-09-20T15:05:42.791613Z","shell.execute_reply":"2025-09-20T15:05:42.796158Z"}},"outputs":[],"execution_count":null},{"cell_type":"markdown","source":"### **Working on problem**","metadata":{"execution":{"iopub.status.busy":"2025-09-19T19:02:01.604784Z","iopub.execute_input":"2025-09-19T19:02:01.605162Z","iopub.status.idle":"2025-09-19T19:02:01.829908Z","shell.execute_reply.started":"2025-09-19T19:02:01.605130Z","shell.execute_reply":"2025-09-19T19:02:01.828664Z"}}},{"cell_type":"code","source":"def create_features(df):\n    df = df.copy()\n    df[\"f_27\"] = df[[\"f_27\"]].iloc[:, 0].apply(lambda x: len(set(x)))\n    return df\n        \n\ndef prepare_data(df):\n    df = create_features(df)\n    classic_attrs = [\"f_07\", \"f_08\", \"f_09\", \"f_10\", \"f_11\", \"f_12\", \"f_13\", \"f_14\", \"f_15\", \"f_16\", \"f_17\", \"f_18\", \"f_27\", \"f_29\", \"f_30\"]\n    num_attrs_df = df.drop(classic_attrs, axis=1)\n    classic_attrs_df = df[classic_attrs]\n\n    scaler = RobustScaler()\n    num_attrs_df_trf = scaler.fit_transform(num_attrs_df)\n    X = np.hstack((num_attrs_df_trf,  classic_attrs_df))\n    print(X.shape)\n\n    return X\n\n    ","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-09-20T15:45:40.841224Z","iopub.execute_input":"2025-09-20T15:45:40.841605Z","iopub.status.idle":"2025-09-20T15:45:40.848918Z","shell.execute_reply.started":"2025-09-20T15:45:40.841582Z","shell.execute_reply":"2025-09-20T15:45:40.847818Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"X, y =  prepare_data(train_df.drop([\"target\", \"id\"], axis=1)), train_df[[\"target\"]]\nX_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.33)","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-09-20T15:45:41.621075Z","iopub.execute_input":"2025-09-20T15:45:41.622118Z","iopub.status.idle":"2025-09-20T15:45:44.008475Z","shell.execute_reply.started":"2025-09-20T15:45:41.622079Z","shell.execute_reply":"2025-09-20T15:45:44.007418Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"model = LGBMClassifier(boosting_type=\"gbdt\", n_estimators=100, n_jobs=-1, random_state=42, learning_rate=0.2, num_leaves=40)\n# model = XGBClassifier(n_estimators=100, n_jobs=-1, random_state=10, num_parallel_tree=3)\nmodel.fit(X_train, y_train)\n\nprint(\" Reporting \".center(50, \"-\"))\ntrain_pred = model.predict(X_train)\nprint(f\"train report:\\n{classification_report(y_train, train_pred)} \\n roc_auc_score: {roc_auc_score(y_train, train_pred)}\")\n\ntest_pred =  model.predict(X_test)\nprint(f\"\\n\\ntest report:\\n{classification_report(y_test,test_pred)}\\n roc_auc_score: {roc_auc_score(y_test, test_pred)}\")\nprint(\"\".center(50, \"-\"))","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-09-20T15:45:44.010075Z","iopub.execute_input":"2025-09-20T15:45:44.010455Z","iopub.status.idle":"2025-09-20T15:45:55.138372Z","shell.execute_reply.started":"2025-09-20T15:45:44.010428Z","shell.execute_reply":"2025-09-20T15:45:55.137385Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"train_df[\"f_00\"].mean()","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-09-20T14:52:36.823710Z","iopub.execute_input":"2025-09-20T14:52:36.823973Z","iopub.status.idle":"2025-09-20T14:52:36.853013Z","shell.execute_reply.started":"2025-09-20T14:52:36.823950Z","shell.execute_reply":"2025-09-20T14:52:36.852149Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"test_df = pd.read_csv(\"/kaggle/input/emsi-5iir-ds/test.csv\")\ntest_X = prepare_data(test_df.drop([\"id\"], axis=1))\n\ntest_pred = model.predict_proba(test_X)[:, 1]","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-09-20T15:55:40.314843Z","iopub.execute_input":"2025-09-20T15:55:40.316226Z","iopub.status.idle":"2025-09-20T15:55:48.347239Z","shell.execute_reply.started":"2025-09-20T15:55:40.316191Z","shell.execute_reply":"2025-09-20T15:55:48.346273Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"sub_df = pd.DataFrame({\"id\":test_df[\"id\"].values.astype(int), \"target\":test_pred})","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-09-20T15:55:48.348717Z","iopub.execute_input":"2025-09-20T15:55:48.349000Z","iopub.status.idle":"2025-09-20T15:55:48.357751Z","shell.execute_reply.started":"2025-09-20T15:55:48.348979Z","shell.execute_reply":"2025-09-20T15:55:48.356683Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"sub_df","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-09-20T15:55:48.358685Z","iopub.execute_input":"2025-09-20T15:55:48.358960Z","iopub.status.idle":"2025-09-20T15:55:48.380261Z","shell.execute_reply.started":"2025-09-20T15:55:48.358939Z","shell.execute_reply":"2025-09-20T15:55:48.379031Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"sub_df.to_csv(\"submission.csv\", index=False)","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-09-20T15:55:48.382081Z","iopub.execute_input":"2025-09-20T15:55:48.382446Z","iopub.status.idle":"2025-09-20T15:55:50.038983Z","shell.execute_reply.started":"2025-09-20T15:55:48.382417Z","shell.execute_reply":"2025-09-20T15:55:50.037916Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"","metadata":{"trusted":true},"outputs":[],"execution_count":null}]}