{"metadata":{"kernelspec":{"language":"python","display_name":"Python 3","name":"python3"},"language_info":{"name":"python","version":"3.11.11","mimetype":"text/x-python","codemirror_mode":{"name":"ipython","version":3},"pygments_lexer":"ipython3","nbconvert_exporter":"python","file_extension":".py"},"kaggle":{"accelerator":"none","dataSources":[{"sourceId":93783,"databundleVersionId":11331308,"sourceType":"competition"}],"dockerImageVersionId":31040,"isInternetEnabled":true,"language":"python","sourceType":"notebook","isGpuEnabled":false}},"nbformat_minor":4,"nbformat":4,"cells":[{"cell_type":"markdown","source":"# install modules","metadata":{}},{"cell_type":"code","source":"!pip install imbalanced-learn==0.11.0 xgboost","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-05-26T09:08:46.482240Z","iopub.execute_input":"2025-05-26T09:08:46.482474Z","iopub.status.idle":"2025-05-26T09:08:50.789706Z","shell.execute_reply.started":"2025-05-26T09:08:46.482445Z","shell.execute_reply":"2025-05-26T09:08:50.787537Z"}},"outputs":[],"execution_count":null},{"cell_type":"markdown","source":"# Imports","metadata":{}},{"cell_type":"code","source":"import os\n\nimport numpy as np\nimport pandas as pd\n\nimport matplotlib.pyplot as plt\nimport seaborn as sns\n\nfrom sklearn.model_selection import train_test_split\nfrom sklearn.ensemble import RandomForestClassifier\nfrom sklearn.metrics import accuracy_score, f1_score, precision_score, recall_score, confusion_matrix\n\nfrom xgboost import XGBClassifier\n\nimport joblib\n","metadata":{"_uuid":"8f2839f25d086af736a60e9eeb907d3b93b6e0e5","_cell_guid":"b1076dfc-b9ad-4769-8c92-a6c4dae69d19","trusted":true,"execution":{"iopub.status.busy":"2025-05-26T09:08:50.791199Z","iopub.execute_input":"2025-05-26T09:08:50.792398Z","iopub.status.idle":"2025-05-26T09:08:53.628975Z","shell.execute_reply.started":"2025-05-26T09:08:50.792349Z","shell.execute_reply":"2025-05-26T09:08:53.628086Z"}},"outputs":[],"execution_count":null},{"cell_type":"markdown","source":"# Creating folders","metadata":{}},{"cell_type":"markdown","source":"## Models folder","metadata":{}},{"cell_type":"code","source":"os.mkdir('/kaggle/working/models')","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-05-26T09:08:53.630306Z","iopub.execute_input":"2025-05-26T09:08:53.630714Z","iopub.status.idle":"2025-05-26T09:08:53.636212Z","shell.execute_reply.started":"2025-05-26T09:08:53.630687Z","shell.execute_reply":"2025-05-26T09:08:53.635261Z"}},"outputs":[],"execution_count":null},{"cell_type":"markdown","source":"## Submission csv folder","metadata":{}},{"cell_type":"code","source":"os.mkdir('/kaggle/working/submission')","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-05-26T09:08:53.642158Z","iopub.execute_input":"2025-05-26T09:08:53.642589Z","iopub.status.idle":"2025-05-26T09:08:53.726093Z","shell.execute_reply.started":"2025-05-26T09:08:53.642564Z","shell.execute_reply":"2025-05-26T09:08:53.724906Z"}},"outputs":[],"execution_count":null},{"cell_type":"markdown","source":"# Paths","metadata":{}},{"cell_type":"code","source":"DATA_PATH = \"/kaggle/input/esa-adb-challenge/\"\nSAMPLE_SUBMISSION = f'{DATA_PATH}' + 'sample_submission.parquet'\nTARGET_CHANNELS = f'{DATA_PATH}' + 'target_channels.csv'\nTRAIN_DATA = f'{DATA_PATH}' + 'train.parquet'\nTEST_DATA = f'{DATA_PATH}' + 'test.parquet'","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-05-26T09:08:53.727321Z","iopub.execute_input":"2025-05-26T09:08:53.727600Z","iopub.status.idle":"2025-05-26T09:08:53.750912Z","shell.execute_reply.started":"2025-05-26T09:08:53.727578Z","shell.execute_reply":"2025-05-26T09:08:53.749381Z"}},"outputs":[],"execution_count":null},{"cell_type":"markdown","source":"# DataFrames analysis","metadata":{}},{"cell_type":"code","source":"sample_df = pd.read_parquet(SAMPLE_SUBMISSION)\ntrain_df = pd.read_parquet(TRAIN_DATA)\ntest_df = pd.read_parquet(TEST_DATA)\ntarget_df = pd.read_csv(TARGET_CHANNELS)","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-05-26T09:08:53.752465Z","iopub.execute_input":"2025-05-26T09:08:53.752835Z","iopub.status.idle":"2025-05-26T09:09:05.808187Z","shell.execute_reply.started":"2025-05-26T09:08:53.752808Z","shell.execute_reply":"2025-05-26T09:09:05.807167Z"}},"outputs":[],"execution_count":null},{"cell_type":"markdown","source":"## info about df","metadata":{}},{"cell_type":"code","source":"sample_df.head()","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-05-26T09:09:05.809525Z","iopub.execute_input":"2025-05-26T09:09:05.809953Z","iopub.status.idle":"2025-05-26T09:09:05.839551Z","shell.execute_reply.started":"2025-05-26T09:09:05.809924Z","shell.execute_reply":"2025-05-26T09:09:05.838541Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"train_df.describe()","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-05-22T07:16:03.366108Z","iopub.execute_input":"2025-05-22T07:16:03.366390Z","iopub.status.idle":"2025-05-22T07:16:39.681930Z","shell.execute_reply.started":"2025-05-22T07:16:03.366369Z","shell.execute_reply":"2025-05-22T07:16:39.680618Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"np.array(train_df.columns)","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-05-22T07:16:39.682915Z","iopub.execute_input":"2025-05-22T07:16:39.683260Z","iopub.status.idle":"2025-05-22T07:16:39.689536Z","shell.execute_reply.started":"2025-05-22T07:16:39.683239Z","shell.execute_reply":"2025-05-22T07:16:39.688674Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"len(train_df.columns)","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-05-22T07:16:39.690520Z","iopub.execute_input":"2025-05-22T07:16:39.690827Z","iopub.status.idle":"2025-05-22T07:16:39.709346Z","shell.execute_reply.started":"2025-05-22T07:16:39.690802Z","shell.execute_reply":"2025-05-22T07:16:39.708600Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"train_df.isnull().values.any()","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-05-22T07:16:39.712918Z","iopub.execute_input":"2025-05-22T07:16:39.713360Z","iopub.status.idle":"2025-05-22T07:16:42.262367Z","shell.execute_reply.started":"2025-05-22T07:16:39.713340Z","shell.execute_reply":"2025-05-22T07:16:42.261628Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"dropped_cols = []","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-05-22T07:16:42.263137Z","iopub.execute_input":"2025-05-22T07:16:42.263346Z","iopub.status.idle":"2025-05-22T07:16:42.267569Z","shell.execute_reply.started":"2025-05-22T07:16:42.263328Z","shell.execute_reply":"2025-05-22T07:16:42.266770Z"}},"outputs":[],"execution_count":null},{"cell_type":"markdown","source":"# test df","metadata":{}},{"cell_type":"code","source":"test_df.columns","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-05-22T07:16:42.268418Z","iopub.execute_input":"2025-05-22T07:16:42.268743Z","iopub.status.idle":"2025-05-22T07:16:42.297115Z","shell.execute_reply.started":"2025-05-22T07:16:42.268702Z","shell.execute_reply":"2025-05-22T07:16:42.296036Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"test_df.head()","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-05-22T07:16:42.298075Z","iopub.execute_input":"2025-05-22T07:16:42.298406Z","iopub.status.idle":"2025-05-22T07:16:42.334608Z","shell.execute_reply.started":"2025-05-22T07:16:42.298376Z","shell.execute_reply":"2025-05-22T07:16:42.333599Z"}},"outputs":[],"execution_count":null},{"cell_type":"markdown","source":"## Dropping columns with almost 0 standard deviation - values are almost this same","metadata":{}},{"cell_type":"code","source":"threshold = 1e-3\nstds = train_df.std(numeric_only=True)\nlow_devuation_cols = stds[stds <= threshold].index\n\nprint(f'Dropping columns: {np.array(low_devuation_cols)}')\ntrain_df.drop(columns=low_devuation_cols, inplace=True)\ntest_df.drop(columns=low_devuation_cols, inplace=True)","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-05-22T07:16:42.335526Z","iopub.execute_input":"2025-05-22T07:16:42.335850Z","iopub.status.idle":"2025-05-22T07:16:49.045393Z","shell.execute_reply.started":"2025-05-22T07:16:42.335822Z","shell.execute_reply":"2025-05-22T07:16:49.044368Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"len(train_df.columns)","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-05-22T07:16:49.051810Z","iopub.execute_input":"2025-05-22T07:16:49.052438Z","iopub.status.idle":"2025-05-22T07:16:49.070518Z","shell.execute_reply.started":"2025-05-22T07:16:49.052404Z","shell.execute_reply":"2025-05-22T07:16:49.069799Z"}},"outputs":[],"execution_count":null},{"cell_type":"markdown","source":"# Calculate enthropy for each column","metadata":{}},{"cell_type":"code","source":"def column_entropy(col: pd.Series, base: float = 2) -> float:\n    \n    counts = col.value_counts(dropna=False)\n    probs = counts / counts.sum()\n    \n    return -np.sum(probs * np.log2(probs))","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-05-22T07:16:49.071360Z","iopub.execute_input":"2025-05-22T07:16:49.071629Z","iopub.status.idle":"2025-05-22T07:16:49.087052Z","shell.execute_reply.started":"2025-05-22T07:16:49.071609Z","shell.execute_reply":"2025-05-22T07:16:49.086150Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"threshold = 0.1\nentropies = train_df.apply(column_entropy)\nlow_entropy_cols = entropies[entropies < threshold].index.tolist()\nprint(f'Columns to drop: {low_entropy_cols}')","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-05-22T07:16:49.088065Z","iopub.execute_input":"2025-05-22T07:16:49.088313Z","iopub.status.idle":"2025-05-22T07:17:03.536369Z","shell.execute_reply.started":"2025-05-22T07:16:49.088293Z","shell.execute_reply":"2025-05-22T07:17:03.535554Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"train_df.drop(columns=low_entropy_cols, inplace=True)\ntest_df.drop(columns=low_entropy_cols, inplace=True)","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-05-22T07:17:03.537275Z","iopub.execute_input":"2025-05-22T07:17:03.537552Z","iopub.status.idle":"2025-05-22T07:17:05.046497Z","shell.execute_reply.started":"2025-05-22T07:17:03.537520Z","shell.execute_reply":"2025-05-22T07:17:05.045775Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"len(train_df.columns)","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-05-22T07:17:05.052801Z","iopub.execute_input":"2025-05-22T07:17:05.053091Z","iopub.status.idle":"2025-05-22T07:17:05.069964Z","shell.execute_reply.started":"2025-05-22T07:17:05.053072Z","shell.execute_reply":"2025-05-22T07:17:05.069204Z"}},"outputs":[],"execution_count":null},{"cell_type":"markdown","source":"# Checking correlation between columns - if collumns are highly correlated (ex. 0.95) then we can drop one of them","metadata":{}},{"cell_type":"code","source":"corr_matrix = train_df.corr()","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-05-22T07:17:05.070840Z","iopub.execute_input":"2025-05-22T07:17:05.071140Z","iopub.status.idle":"2025-05-22T07:20:11.507528Z","shell.execute_reply.started":"2025-05-22T07:17:05.071120Z","shell.execute_reply":"2025-05-22T07:20:11.506694Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"plt.figure(figsize=(10, 7))\nsns.heatmap(corr_matrix, annot=False, cmap='coolwarm', fmt=\".2f\")\nplt.show()","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-05-22T07:20:11.508395Z","iopub.execute_input":"2025-05-22T07:20:11.508693Z","iopub.status.idle":"2025-05-22T07:20:12.145353Z","shell.execute_reply.started":"2025-05-22T07:20:11.508668Z","shell.execute_reply":"2025-05-22T07:20:12.144474Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"corr_matrix = corr_matrix.abs()\nmask = np.triu(np.ones(corr_matrix.shape), k=1).astype(bool)\nupper = corr_matrix.where(mask)\n\nthreshold = 0.90\nhigh_corr = (\n    upper.stack()\n         .loc[lambda x: x > threshold]\n         .sort_values(ascending=False)\n)\n\nprint(\"Highly correlated columns: (|corr| > 0.90):\")\nprint(high_corr)","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-05-22T07:20:12.146455Z","iopub.execute_input":"2025-05-22T07:20:12.147280Z","iopub.status.idle":"2025-05-22T07:20:12.169022Z","shell.execute_reply.started":"2025-05-22T07:20:12.147251Z","shell.execute_reply":"2025-05-22T07:20:12.167855Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"high_corellated_cols = []\nfor (col1, col2), corr_value in high_corr.items():\n    high_corellated_cols.append(col2)\n\ntrain_df.drop(columns=high_corellated_cols, inplace=True)\ntest_df.drop(columns=high_corellated_cols, inplace=True)","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-05-22T07:20:12.170132Z","iopub.execute_input":"2025-05-22T07:20:12.170379Z","iopub.status.idle":"2025-05-22T07:20:12.832031Z","shell.execute_reply.started":"2025-05-22T07:20:12.170360Z","shell.execute_reply":"2025-05-22T07:20:12.830961Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"dropped_cols.append(high_corellated_cols)","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-05-22T07:20:12.832996Z","iopub.execute_input":"2025-05-22T07:20:12.833322Z","iopub.status.idle":"2025-05-22T07:20:12.839038Z","shell.execute_reply.started":"2025-05-22T07:20:12.833292Z","shell.execute_reply":"2025-05-22T07:20:12.838027Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"len(train_df.columns)","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-05-22T07:20:12.839815Z","iopub.execute_input":"2025-05-22T07:20:12.840135Z","iopub.status.idle":"2025-05-22T07:20:12.857290Z","shell.execute_reply.started":"2025-05-22T07:20:12.840108Z","shell.execute_reply":"2025-05-22T07:20:12.856462Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"train_df.head()","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-05-22T07:20:12.862547Z","iopub.execute_input":"2025-05-22T07:20:12.862842Z","iopub.status.idle":"2025-05-22T07:20:12.886666Z","shell.execute_reply.started":"2025-05-22T07:20:12.862823Z","shell.execute_reply":"2025-05-22T07:20:12.885895Z"}},"outputs":[],"execution_count":null},{"cell_type":"markdown","source":"# Dropping id and predict","metadata":{}},{"cell_type":"code","source":"dataframe_no_id = train_df.drop(columns='id')\ntest_no_id = test_df.drop(columns='id')","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-05-22T07:20:12.887520Z","iopub.execute_input":"2025-05-22T07:20:12.887826Z","iopub.status.idle":"2025-05-22T07:20:13.428995Z","shell.execute_reply.started":"2025-05-22T07:20:12.887807Z","shell.execute_reply":"2025-05-22T07:20:13.428226Z"}},"outputs":[],"execution_count":null},{"cell_type":"markdown","source":"# Evaluate model function","metadata":{}},{"cell_type":"code","source":"def half_f1(precision, recall):\n    return (1+(0.5)^2 * precision * recall)/((0.5)^2 * precision + recall)\n\ndef half_f1(precision, recall):\n    beta = 0.5\n    return (1 + beta**2) * (precision * recall) / (beta**2 * precision + recall)\n","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-05-22T07:20:13.435400Z","iopub.execute_input":"2025-05-22T07:20:13.435670Z","iopub.status.idle":"2025-05-22T07:20:13.449181Z","shell.execute_reply.started":"2025-05-22T07:20:13.435652Z","shell.execute_reply":"2025-05-22T07:20:13.448352Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"def evaluate_model(y_test, y_pred, model_name):\n    precision = precision_score(y_test, y_pred, zero_division=0)\n    recall = recall_score(y_test, y_pred, zero_division=0)\n    f1 = f1_score(y_test, y_pred, zero_division=0)\n    accuracy = accuracy_score(y_test, y_pred)\n    f1_half = half_f1(precision, recall)\n\n    print(f\"\\nMetryki dla modelu: {model_name}\")\n    print(f\"Precision: {precision:.4f}\")\n    print(f\"Recall:    {recall:.4f}\")\n    print(f\"F1 score:  {f1:.4f}\")\n    print(f\"F1_0.5 score:  {f1_half:.4f}\")\n    print(f\"Accuracy:  {accuracy:.4f}\")\n\n    cm = confusion_matrix(y_test, y_pred)\n    plt.figure(figsize=(6, 4))\n    sns.heatmap(cm, annot=True, fmt='d', cmap='Blues', xticklabels=[0, 1], yticklabels=[0, 1])\n    plt.xlabel('Predicted')\n    plt.ylabel('Actual')\n    plt.title(f'Macierz pomyłek: {model_name}')\n    plt.tight_layout()\n    plt.show()","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-05-22T07:20:13.450025Z","iopub.execute_input":"2025-05-22T07:20:13.450303Z","iopub.status.idle":"2025-05-22T07:20:13.463765Z","shell.execute_reply.started":"2025-05-22T07:20:13.450283Z","shell.execute_reply":"2025-05-22T07:20:13.463008Z"}},"outputs":[],"execution_count":null},{"cell_type":"markdown","source":"# training model","metadata":{}},{"cell_type":"code","source":"X = dataframe_no_id.drop(columns='is_anomaly')\ny = dataframe_no_id['is_anomaly']","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-05-22T07:20:13.464792Z","iopub.execute_input":"2025-05-22T07:20:13.465089Z","iopub.status.idle":"2025-05-22T07:20:13.986068Z","shell.execute_reply.started":"2025-05-22T07:20:13.465066Z","shell.execute_reply":"2025-05-22T07:20:13.985305Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.2, random_state=42, stratify=y)","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-05-22T07:20:13.986919Z","iopub.execute_input":"2025-05-22T07:20:13.987267Z","iopub.status.idle":"2025-05-22T07:20:26.220915Z","shell.execute_reply.started":"2025-05-22T07:20:13.987243Z","shell.execute_reply":"2025-05-22T07:20:26.217804Z"}},"outputs":[],"execution_count":null},{"cell_type":"markdown","source":"## Random Forest","metadata":{}},{"cell_type":"code","source":"rf_model = RandomForestClassifier(n_estimators=100, random_state=42, verbose=1)\nrf_model.fit(X_train, y_train)\ny_pred_rf = rf_model.predict(X_test)\n\njoblib.dump(rf_model, '/kaggle/working/models/random_forest_model.pkl')","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-05-22T07:20:26.224514Z","iopub.execute_input":"2025-05-22T07:20:26.225455Z","iopub.status.idle":"2025-05-22T09:05:37.553607Z","shell.execute_reply.started":"2025-05-22T07:20:26.225344Z","shell.execute_reply":"2025-05-22T09:05:37.551506Z"}},"outputs":[],"execution_count":null},{"cell_type":"markdown","source":"# XGBoost","metadata":{}},{"cell_type":"code","source":"xgb_model = XGBClassifier(n_estimators=100, use_label_encoder=False, eval_metric='logloss', random_state=42, verbose=1)\nxgb_model.fit(X_train, y_train)\ny_pred_xgb = xgb_model.predict(X_test)\n\njoblib.dump(xgb_model, '/kaggle/working/models/xgboost_model.pkl')","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-05-22T09:05:37.556699Z","iopub.execute_input":"2025-05-22T09:05:37.557106Z","iopub.status.idle":"2025-05-22T09:06:55.763957Z","shell.execute_reply.started":"2025-05-22T09:05:37.557071Z","shell.execute_reply":"2025-05-22T09:06:55.763218Z"}},"outputs":[],"execution_count":null},{"cell_type":"markdown","source":"# Metrics and confusion matrix","metadata":{}},{"cell_type":"markdown","source":"## Random forest:","metadata":{}},{"cell_type":"code","source":"evaluate_model(y_test, y_pred_rf, \"Random Forest\")","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-05-22T09:06:55.764691Z","iopub.execute_input":"2025-05-22T09:06:55.764945Z","iopub.status.idle":"2025-05-22T09:07:00.157867Z","shell.execute_reply.started":"2025-05-22T09:06:55.764927Z","shell.execute_reply":"2025-05-22T09:07:00.156817Z"}},"outputs":[],"execution_count":null},{"cell_type":"markdown","source":"## XGBoost:","metadata":{}},{"cell_type":"code","source":"evaluate_model(y_test, y_pred_xgb, \"XGBoost\")","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-05-22T09:07:00.159146Z","iopub.execute_input":"2025-05-22T09:07:00.159508Z","iopub.status.idle":"2025-05-22T09:07:04.604854Z","shell.execute_reply.started":"2025-05-22T09:07:00.159480Z","shell.execute_reply":"2025-05-22T09:07:04.603849Z"}},"outputs":[],"execution_count":null},{"cell_type":"markdown","source":"# Predict model","metadata":{}},{"cell_type":"code","source":"y_test_rf = rf_model.predict(test_no_id)","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-05-22T09:07:04.756200Z","iopub.status.idle":"2025-05-22T09:07:04.756778Z","shell.execute_reply.started":"2025-05-22T09:07:04.756598Z","shell.execute_reply":"2025-05-22T09:07:04.756613Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"y_test_xgb = xgb_model.predict(test_no_id)","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-05-22T09:07:04.757697Z","iopub.status.idle":"2025-05-22T09:07:04.758119Z","shell.execute_reply.started":"2025-05-22T09:07:04.757913Z","shell.execute_reply":"2025-05-22T09:07:04.757941Z"}},"outputs":[],"execution_count":null},{"cell_type":"markdown","source":"# indexing and saving submission files","metadata":{}},{"cell_type":"markdown","source":"## Random forest","metadata":{}},{"cell_type":"code","source":"random_forest_submission = sample_df","metadata":{"trusted":true},"outputs":[],"execution_count":null},{"cell_type":"markdown","source":"### setting left column - id, right - is_anomaly","metadata":{}},{"cell_type":"code","source":"y_test_rf = pd.Series(y_test_rf, name='is_anomaly')\nrandom_forest_submission['is_anomaly'] = y_test_rf","metadata":{"trusted":true},"outputs":[],"execution_count":null},{"cell_type":"markdown","source":"### Submission Random Forest csv save","metadata":{}},{"cell_type":"code","source":"random_forest_submission.head()","metadata":{"trusted":true},"outputs":[],"execution_count":null},{"cell_type":"code","source":"random_forest_submission.to_csv('/kaggle/working/submission/random_forest_submission.csv')","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-05-22T09:07:04.760460Z","iopub.status.idle":"2025-05-22T09:07:04.760773Z","shell.execute_reply.started":"2025-05-22T09:07:04.760629Z","shell.execute_reply":"2025-05-22T09:07:04.760641Z"}},"outputs":[],"execution_count":null},{"cell_type":"markdown","source":"## XGBoost","metadata":{}},{"cell_type":"code","source":"xgboost_submission = sample_df","metadata":{"trusted":true},"outputs":[],"execution_count":null},{"cell_type":"markdown","source":"### setting left column - id, right - is_anomaly","metadata":{}},{"cell_type":"code","source":"y_test_xgb = pd.Series(y_test_xgb, name='is_anomaly')\nxgboost_submission['is_anomaly'] = y_test_xgb","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-05-22T09:07:04.762582Z","iopub.status.idle":"2025-05-22T09:07:04.762985Z","shell.execute_reply.started":"2025-05-22T09:07:04.762778Z","shell.execute_reply":"2025-05-22T09:07:04.762796Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"xgboost_submission.head()","metadata":{"trusted":true},"outputs":[],"execution_count":null},{"cell_type":"markdown","source":"### submission XGBoost csv save","metadata":{}},{"cell_type":"code","source":"xgboost_submission.to_csv('/kaggle/working/submission/xgb_submission.csv')","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-05-22T09:07:04.763572Z","iopub.status.idle":"2025-05-22T09:07:04.763916Z","shell.execute_reply.started":"2025-05-22T09:07:04.763780Z","shell.execute_reply":"2025-05-22T09:07:04.763796Z"}},"outputs":[],"execution_count":null}]}