{"metadata":{"kernelspec":{"language":"python","display_name":"Python 3","name":"python3"},"language_info":{"name":"python","version":"3.10.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":74571,"databundleVersionId":8671431,"sourceType":"competition"}],"dockerImageVersionId":30673,"isInternetEnabled":true,"language":"python","sourceType":"notebook","isGpuEnabled":false}},"nbformat_minor":4,"nbformat":4,"cells":[{"cell_type":"code","source":"# Taehun Koo\n# 2024.6.27 15:26\n\n#완료 데이터 탐색 - 신용카드 학습과 데이터 데이터셋의 특성\n# 데이터 전처리 - 결측치, 이상치 확인 및 처리\n# 모델 선택과정 - 로지스틱 회귀와 LightBGM을 오버샘플링한 것과 아닌 것으로 각각 선택했습니다.\n# 성능 평가 - 매트릭스, 정확도, 정밀도, 재현율, F1, AUC를 적용했습니다.\n# 회고 - 모델을 오류없이 돌리는데만 해도 많은 오류들을 겪었습니다.\n","metadata":{"execution":{"iopub.status.busy":"2024-06-27T09:23:27.341205Z","iopub.execute_input":"2024-06-27T09:23:27.341751Z","iopub.status.idle":"2024-06-27T09:23:27.348025Z","shell.execute_reply.started":"2024-06-27T09:23:27.341714Z","shell.execute_reply":"2024-06-27T09:23:27.346588Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"import pandas as pd\nimport numpy as np\nimport matplotlib.pyplot as plt\nimport seaborn as sns\n\nfrom sklearn.model_selection import train_test_split\nfrom sklearn.linear_model import LogisticRegression\nfrom sklearn.metrics import accuracy_score, precision_score, recall_score, confusion_matrix, f1_score, roc_auc_score\n\nfrom lightgbm import LGBMClassifier\nfrom imblearn.over_sampling import SMOTE","metadata":{"execution":{"iopub.status.busy":"2024-06-27T09:23:27.350402Z","iopub.execute_input":"2024-06-27T09:23:27.350830Z","iopub.status.idle":"2024-06-27T09:23:27.364286Z","shell.execute_reply.started":"2024-06-27T09:23:27.350788Z","shell.execute_reply":"2024-06-27T09:23:27.362319Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"","metadata":{},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# 데이터 탐색 - 신용카드 학습과 데이터 데이터셋의 특성","metadata":{"execution":{"iopub.status.busy":"2024-06-27T09:23:27.366325Z","iopub.execute_input":"2024-06-27T09:23:27.366848Z","iopub.status.idle":"2024-06-27T09:23:27.384515Z","shell.execute_reply.started":"2024-06-27T09:23:27.366801Z","shell.execute_reply":"2024-06-27T09:23:27.383108Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# 학습할 데이터셋 입니다.\n\ntrain = pd.read_csv(\"/kaggle/input/affel-ds2-credit-card/train.csv\")\ntest = pd.read_csv(\"/kaggle/input/affel-ds2-credit-card/test.csv\")","metadata":{"execution":{"iopub.status.busy":"2024-06-27T09:23:27.387430Z","iopub.execute_input":"2024-06-27T09:23:27.388628Z","iopub.status.idle":"2024-06-27T09:23:30.397504Z","shell.execute_reply.started":"2024-06-27T09:23:27.388569Z","shell.execute_reply":"2024-06-27T09:23:30.395914Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"\n# V1~V28의 피처는 내용을 알 수 없는 머신러닝의 대상이 되는 데이터입니다.\n# Amount는 신용카드 트랜잭션 금액입니다.\n# Class의 0이 정상 트랜잭션, 1이 사기를 나타내는 트랜잭션입니다.\n\ntrain.head()","metadata":{"execution":{"iopub.status.busy":"2024-06-27T09:23:30.399442Z","iopub.execute_input":"2024-06-27T09:23:30.399858Z","iopub.status.idle":"2024-06-27T09:23:30.433638Z","shell.execute_reply.started":"2024-06-27T09:23:30.399825Z","shell.execute_reply":"2024-06-27T09:23:30.431830Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# 학습 데이터는 170883개의 행과 32개의 피처가 있습니다.\n# 학습 사기 데이터인 Class가 여기만 있습니다.\n\ntrain.shape","metadata":{"execution":{"iopub.status.busy":"2024-06-27T09:23:30.435722Z","iopub.execute_input":"2024-06-27T09:23:30.436287Z","iopub.status.idle":"2024-06-27T09:23:30.447135Z","shell.execute_reply.started":"2024-06-27T09:23:30.436239Z","shell.execute_reply":"2024-06-27T09:23:30.445451Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# 테스트 데이터는 113923개의 행과 31개의 피처가 있습니다.\ntest.shape","metadata":{"execution":{"iopub.status.busy":"2024-06-27T09:23:30.449259Z","iopub.execute_input":"2024-06-27T09:23:30.449771Z","iopub.status.idle":"2024-06-27T09:23:30.463438Z","shell.execute_reply.started":"2024-06-27T09:23:30.449728Z","shell.execute_reply":"2024-06-27T09:23:30.461841Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# 학습 데이터에는 결측치가 없습니다.\n# Time이 머신러닝에 불필요하고, V1~V28과 Amount를 학습 데이터로 사용할 예정입니다.\n\ntrain.info()","metadata":{"execution":{"iopub.status.busy":"2024-06-27T09:23:30.465627Z","iopub.execute_input":"2024-06-27T09:23:30.466203Z","iopub.status.idle":"2024-06-27T09:23:30.499561Z","shell.execute_reply.started":"2024-06-27T09:23:30.466155Z","shell.execute_reply":"2024-06-27T09:23:30.497802Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# 학습 데이터의 0과 1 레이블 값이 극도로 불균형함을 보입니다.\n\ntrain[\"Class\"].value_counts(normalize=True)*100","metadata":{"execution":{"iopub.status.busy":"2024-06-27T09:23:30.501648Z","iopub.execute_input":"2024-06-27T09:23:30.502203Z","iopub.status.idle":"2024-06-27T09:23:30.517807Z","shell.execute_reply.started":"2024-06-27T09:23:30.502157Z","shell.execute_reply":"2024-06-27T09:23:30.516101Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# 테스트 데이터에도 결측치가 없습니다.\n\ntest.info()","metadata":{"execution":{"iopub.status.busy":"2024-06-27T09:23:30.524575Z","iopub.execute_input":"2024-06-27T09:23:30.525171Z","iopub.status.idle":"2024-06-27T09:23:30.556657Z","shell.execute_reply.started":"2024-06-27T09:23:30.525123Z","shell.execute_reply":"2024-06-27T09:23:30.554824Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"","metadata":{},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# 데이터 전처리 - 결측치, 이상치 확인 및 처리","metadata":{"execution":{"iopub.status.busy":"2024-06-27T09:23:30.558565Z","iopub.execute_input":"2024-06-27T09:23:30.559036Z","iopub.status.idle":"2024-06-27T09:23:30.565873Z","shell.execute_reply.started":"2024-06-27T09:23:30.558982Z","shell.execute_reply":"2024-06-27T09:23:30.564046Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# Amount 피처가 정규분포가 아닙니다. 정규분포로 만들어서 피처를 amount_n으로 변경합니다. \n# 이상치를 제거하기 위해 아래 IQR 히트맵 시각화 결과 V14 피처를 삭제합니다.\n\ndef get_preprocessed_df(df=None, train=True):\n    df_copy = df.copy()\n    amount_n = np.log1p(df_copy[\"Amount\"])\n    df_copy.insert(0, \"Amount_Scaled\", amount_n)\n    df_copy. drop([\"Time\", \"Amount\"], axis=1, inplace=True)\n    \n    outlier_index = get_outlier(df=df_copy, column=\"V14\", weight=1.5)\n    df_copy.drop(outlier_index, axis=0, inplace=True)\n    \n    return df_copy","metadata":{"execution":{"iopub.status.busy":"2024-06-27T09:23:30.567949Z","iopub.execute_input":"2024-06-27T09:23:30.568458Z","iopub.status.idle":"2024-06-27T09:23:30.581974Z","shell.execute_reply.started":"2024-06-27T09:23:30.568420Z","shell.execute_reply":"2024-06-27T09:23:30.580028Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# 전처리 후에 학습과 테스트 데이터를 분리해서 반환하는 함수입니다.\n\ndef get_train_test_dataset(df=None):\n    df_copy = get_preprocessed_df(df)\n    \n    X_features = df_copy.iloc[:, :-1]\n    y_target = df_copy.iloc[:, -1]\n    \n    X_train, X_test, y_train, y_test = train_test_split(\n        X_features, y_target,test_size=0.3, random_state=0, stratify=y_target)\n\n    return X_train, X_test, y_train, y_test","metadata":{"execution":{"iopub.status.busy":"2024-06-27T09:23:30.584274Z","iopub.execute_input":"2024-06-27T09:23:30.584728Z","iopub.status.idle":"2024-06-27T09:23:30.603491Z","shell.execute_reply.started":"2024-06-27T09:23:30.584692Z","shell.execute_reply":"2024-06-27T09:23:30.601685Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# 평가 함수입니다.\n\ndef get_clf_eval(y_test, pred, pred_proba=None):\n    confusion = confusion_matrix(y_test, pred)\n    accuracy = accuracy_score(y_test, pred)\n    precison = precision_score(y_test, pred)\n    recall = recall_score(y_test, pred)\n    f1 = f1_score(y_test, pred)\n    \n    roc_auc = roc_auc_score(y_test, pred_proba)\n    \n    print(\"오차 행렬\")\n    print(confusion)\n    print(f\"정확도: {accuracy: .4f}, 정밀도: {precison: .4}, 재현율: {recall: .4f}, f1스코어: {f1: .4f}, roc-auc: {roc_auc: .4f}\")","metadata":{"execution":{"iopub.status.busy":"2024-06-27T09:23:30.605292Z","iopub.execute_input":"2024-06-27T09:23:30.605753Z","iopub.status.idle":"2024-06-27T09:23:30.618682Z","shell.execute_reply.started":"2024-06-27T09:23:30.605718Z","shell.execute_reply":"2024-06-27T09:23:30.617101Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# 모델 별로 학습과 데이터 세트를 받아서 학습과 예측과 평가를 실행하는 함수입니다.\n\ndef get_model_train_eval(model, ftr_train=None, ftr_test=None, tgt_train=None, tgt_test=None):\n    model.fit(ftr_train, tgt_train)\n    pred = model.predict(ftr_test)\n    pred_proba = model.predict_proba(ftr_test)[:, 1]\n    get_clf_eval(tgt_test, pred, pred_proba)","metadata":{"execution":{"iopub.status.busy":"2024-06-27T09:23:30.620856Z","iopub.execute_input":"2024-06-27T09:23:30.621300Z","iopub.status.idle":"2024-06-27T09:23:30.635889Z","shell.execute_reply.started":"2024-06-27T09:23:30.621265Z","shell.execute_reply":"2024-06-27T09:23:30.634121Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# 이상치 데이터를 얻기 위해 사기 데이터를 추출해서 IQR 의 바깥 데이터를 추출합니다.\n\ndef get_outlier(df=None, column=None, weight=1.5):\n    fraud = df[df['Class']==1][column]\n    quantile_25 = np.percentile(fraud.values, 25)\n    quantile_75 = np.percentile(fraud.values, 75)\n    \n    iqr = quantile_75 - quantile_25\n    iqr_weight = iqr * weight\n    lowest_val = quantile_25 - iqr_weight\n    highest_val = quantile_75 + iqr_weight\n    \n    outlier_index = fraud[(fraud < lowest_val) | (fraud > highest_val)].index\n    return outlier_index","metadata":{"execution":{"iopub.status.busy":"2024-06-27T09:23:30.638218Z","iopub.execute_input":"2024-06-27T09:23:30.638793Z","iopub.status.idle":"2024-06-27T09:23:30.653788Z","shell.execute_reply.started":"2024-06-27T09:23:30.638745Z","shell.execute_reply":"2024-06-27T09:23:30.652126Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# 전처리 후에 학습과 테스트 데이터를 분리해서 반환하는 함수를 호출합니다.\n\n\nX_train, X_test, y_train, y_test = get_train_test_dataset(train)","metadata":{"execution":{"iopub.status.busy":"2024-06-27T09:23:30.655538Z","iopub.execute_input":"2024-06-27T09:23:30.656195Z","iopub.status.idle":"2024-06-27T09:23:30.932428Z","shell.execute_reply.started":"2024-06-27T09:23:30.656058Z","shell.execute_reply":"2024-06-27T09:23:30.930920Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# 학습과 테스트 데이터 세트의 레이블 값 비율을 백분율로 확인합니다.\n# 레이블 값이 비슷한 비율로 출력된 것을 확인했습니다.\n\nprint(\"학습 데이터 레이블 값 비율\")\nprint(y_train.value_counts() / y_train.shape[0] * 100)\nprint()\nprint(\"테스트 데이터 레이블 값 비율\")\nprint(y_test.value_counts() / y_test.shape[0] * 100)","metadata":{"execution":{"iopub.status.busy":"2024-06-27T09:23:30.934407Z","iopub.execute_input":"2024-06-27T09:23:30.934825Z","iopub.status.idle":"2024-06-27T09:23:30.949471Z","shell.execute_reply.started":"2024-06-27T09:23:30.934789Z","shell.execute_reply":"2024-06-27T09:23:30.947843Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# 오버 샘플링된 SMOTE를 적용합니다.\n\nsmote = SMOTE(random_state=0)\n\nX_train_over, y_train_over = smote.fit_resample(X_train, y_train)","metadata":{"execution":{"iopub.status.busy":"2024-06-27T09:23:30.951684Z","iopub.execute_input":"2024-06-27T09:23:30.952110Z","iopub.status.idle":"2024-06-27T09:23:31.300771Z","shell.execute_reply.started":"2024-06-27T09:23:30.952076Z","shell.execute_reply":"2024-06-27T09:23:31.299269Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# SMOTE 적용 후 레이블 값이 동등한 비율로 변화했습니다.\n\nprint(\"SMOTE 적용 전 학습용 피처/레이블 데이터 세트: \", X_train.shape, y_train.shape)\nprint(\"\\nSMOTE 적용 후 학습용 피처/레이블 데이터 세트: \", X_train_over.shape, y_train_over.shape)\nprint(\"\\nSMOTE 적용 후 레이블 값 분포: \\n\",pd.Series(y_train_over).value_counts(normalize=True))","metadata":{"execution":{"iopub.status.busy":"2024-06-27T09:23:31.303029Z","iopub.execute_input":"2024-06-27T09:23:31.303472Z","iopub.status.idle":"2024-06-27T09:23:31.317761Z","shell.execute_reply.started":"2024-06-27T09:23:31.303437Z","shell.execute_reply":"2024-06-27T09:23:31.315914Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# 로지스틱회귀와 LigbtGBM을 사용하기 위해 변수화합니다.\n\nlr_clf = LogisticRegression(max_iter=1000)\nlgbm_clf = LGBMClassifier(n_estimators=1000, num_leaves=64, n_jobs=-1, boost_from_average=False)","metadata":{"execution":{"iopub.status.busy":"2024-06-27T09:23:31.319641Z","iopub.execute_input":"2024-06-27T09:23:31.320091Z","iopub.status.idle":"2024-06-27T09:23:31.332732Z","shell.execute_reply.started":"2024-06-27T09:23:31.320055Z","shell.execute_reply":"2024-06-27T09:23:31.331115Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# 로지스틱 회귀를 실행합니다.\n\nget_model_train_eval(model = lr_clf, ftr_train=X_train, ftr_test=X_test, tgt_train=y_train, tgt_test=y_test)","metadata":{"execution":{"iopub.status.busy":"2024-06-27T09:23:31.334654Z","iopub.execute_input":"2024-06-27T09:23:31.335088Z","iopub.status.idle":"2024-06-27T09:23:34.131095Z","shell.execute_reply.started":"2024-06-27T09:23:31.335054Z","shell.execute_reply":"2024-06-27T09:23:34.129061Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# 오버 샘플링된 로지스틱 회귀를 실행합니다.\n\nget_model_train_eval(model = lr_clf, ftr_train=X_train_over, ftr_test=X_test, tgt_train=y_train_over, tgt_test=y_test)","metadata":{"execution":{"iopub.status.busy":"2024-06-27T09:23:34.133105Z","iopub.execute_input":"2024-06-27T09:23:34.133647Z","iopub.status.idle":"2024-06-27T09:23:36.240286Z","shell.execute_reply.started":"2024-06-27T09:23:34.133593Z","shell.execute_reply":"2024-06-27T09:23:36.238514Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# LightGBM 모델을 실행합니다.\n\nget_model_train_eval(model = lgbm_clf, ftr_train=X_train, ftr_test=X_test, tgt_train=y_train, tgt_test=y_test)","metadata":{"execution":{"iopub.status.busy":"2024-06-27T09:23:36.242782Z","iopub.execute_input":"2024-06-27T09:23:36.243381Z","iopub.status.idle":"2024-06-27T09:24:18.359782Z","shell.execute_reply.started":"2024-06-27T09:23:36.243330Z","shell.execute_reply":"2024-06-27T09:24:18.358149Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# 오버 샘플링된 LightGBM 모델을 실행합니다.\n\nget_model_train_eval(model = lgbm_clf, ftr_train=X_train, ftr_test=X_test, tgt_train=y_train, tgt_test=y_test)","metadata":{"execution":{"iopub.status.busy":"2024-06-27T09:24:18.361509Z","iopub.execute_input":"2024-06-27T09:24:18.361894Z","iopub.status.idle":"2024-06-27T09:24:59.726747Z","shell.execute_reply.started":"2024-06-27T09:24:18.361862Z","shell.execute_reply":"2024-06-27T09:24:59.724819Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# 2개의 모델을 오버 샘플링 적용 전후로 비교했습니다.\n#","metadata":{"execution":{"iopub.status.busy":"2024-06-27T09:24:59.728521Z","iopub.execute_input":"2024-06-27T09:24:59.728900Z","iopub.status.idle":"2024-06-27T09:24:59.735072Z","shell.execute_reply.started":"2024-06-27T09:24:59.728870Z","shell.execute_reply":"2024-06-27T09:24:59.733411Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# submission 데이터셋을 읽어옵니다.\n\nsubmission = pd.read_csv(\"/kaggle/input/affel-ds2-credit-card/sample_submission.csv\")","metadata":{"execution":{"iopub.status.busy":"2024-06-27T09:31:17.825667Z","iopub.execute_input":"2024-06-27T09:31:17.826184Z","iopub.status.idle":"2024-06-27T09:31:17.868448Z","shell.execute_reply.started":"2024-06-27T09:31:17.826149Z","shell.execute_reply":"2024-06-27T09:31:17.867058Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"submission.info()","metadata":{"execution":{"iopub.status.busy":"2024-06-27T09:31:27.387683Z","iopub.execute_input":"2024-06-27T09:31:27.388096Z","iopub.status.idle":"2024-06-27T09:31:27.402502Z","shell.execute_reply.started":"2024-06-27T09:31:27.388066Z","shell.execute_reply":"2024-06-27T09:31:27.400897Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"","metadata":{},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"test.info()","metadata":{"execution":{"iopub.status.busy":"2024-06-27T09:24:59.818029Z","iopub.execute_input":"2024-06-27T09:24:59.818535Z","iopub.status.idle":"2024-06-27T09:24:59.845954Z","shell.execute_reply.started":"2024-06-27T09:24:59.818498Z","shell.execute_reply":"2024-06-27T09:24:59.844021Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"test.head()","metadata":{"execution":{"iopub.status.busy":"2024-06-27T09:24:59.848713Z","iopub.execute_input":"2024-06-27T09:24:59.849288Z","iopub.status.idle":"2024-06-27T09:24:59.887172Z","shell.execute_reply.started":"2024-06-27T09:24:59.849242Z","shell.execute_reply":"2024-06-27T09:24:59.885525Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# 예측을 위해 test 의 Time과 Amount 피처를 삭제 합니다.\n\ntest[\"Amount_Scaled\"] = np.log1p(test[\"Amount\"])\ntest.drop([\"Time\", \"Amount\"], axis=1, inplace=True)","metadata":{"execution":{"iopub.status.busy":"2024-06-27T09:31:59.251662Z","iopub.execute_input":"2024-06-27T09:31:59.252090Z","iopub.status.idle":"2024-06-27T09:31:59.396876Z","shell.execute_reply.started":"2024-06-27T09:31:59.252053Z","shell.execute_reply":"2024-06-27T09:31:59.394052Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"","metadata":{},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# LightBGM으로 예측값을 호출합니다.\n\nlgbm_pred = lgbm_clf.predict(test)","metadata":{"execution":{"iopub.status.busy":"2024-06-27T09:24:59.913776Z","iopub.execute_input":"2024-06-27T09:24:59.914336Z","iopub.status.idle":"2024-06-27T09:25:05.076280Z","shell.execute_reply.started":"2024-06-27T09:24:59.914290Z","shell.execute_reply":"2024-06-27T09:25:05.074767Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# LightBGM으로 확률을 예측합니다.\n\nlgbm_pred_proba = lgbm_clf.predict_proba(test)[:,1]","metadata":{"execution":{"iopub.status.busy":"2024-06-27T09:25:05.078479Z","iopub.execute_input":"2024-06-27T09:25:05.078999Z","iopub.status.idle":"2024-06-27T09:25:10.256278Z","shell.execute_reply.started":"2024-06-27T09:25:05.078956Z","shell.execute_reply":"2024-06-27T09:25:10.254650Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"","metadata":{},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"test.shape","metadata":{"execution":{"iopub.status.busy":"2024-06-27T09:25:10.258085Z","iopub.execute_input":"2024-06-27T09:25:10.258489Z","iopub.status.idle":"2024-06-27T09:25:10.268398Z","shell.execute_reply.started":"2024-06-27T09:25:10.258457Z","shell.execute_reply":"2024-06-27T09:25:10.266558Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"test.info()","metadata":{"execution":{"iopub.status.busy":"2024-06-27T09:25:10.270470Z","iopub.execute_input":"2024-06-27T09:25:10.270900Z","iopub.status.idle":"2024-06-27T09:25:10.311424Z","shell.execute_reply.started":"2024-06-27T09:25:10.270864Z","shell.execute_reply":"2024-06-27T09:25:10.310111Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"lgbm_pred_proba.shape","metadata":{"execution":{"iopub.status.busy":"2024-06-27T09:25:10.313277Z","iopub.execute_input":"2024-06-27T09:25:10.313846Z","iopub.status.idle":"2024-06-27T09:25:10.325253Z","shell.execute_reply.started":"2024-06-27T09:25:10.313796Z","shell.execute_reply":"2024-06-27T09:25:10.323159Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"","metadata":{},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"","metadata":{},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"test[\"Class\"] = lgbm_pred_proba","metadata":{"execution":{"iopub.status.busy":"2024-06-27T09:28:47.125312Z","iopub.execute_input":"2024-06-27T09:28:47.126881Z","iopub.status.idle":"2024-06-27T09:28:47.134633Z","shell.execute_reply.started":"2024-06-27T09:28:47.126824Z","shell.execute_reply":"2024-06-27T09:28:47.132974Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"test.info()","metadata":{"execution":{"iopub.status.busy":"2024-06-27T09:28:59.505811Z","iopub.execute_input":"2024-06-27T09:28:59.506254Z","iopub.status.idle":"2024-06-27T09:28:59.530062Z","shell.execute_reply.started":"2024-06-27T09:28:59.506223Z","shell.execute_reply":"2024-06-27T09:28:59.528280Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"del submission[\"Class\"]\nsubmission = submission.merge(test[[\"id\", \"Class\"]], on=\"id\")","metadata":{"execution":{"iopub.status.busy":"2024-06-27T09:35:34.837498Z","iopub.execute_input":"2024-06-27T09:35:34.838051Z","iopub.status.idle":"2024-06-27T09:35:34.858424Z","shell.execute_reply.started":"2024-06-27T09:35:34.837984Z","shell.execute_reply":"2024-06-27T09:35:34.856556Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"","metadata":{},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"submission.to_csv(\"submission.csv\", index=False)","metadata":{"execution":{"iopub.status.busy":"2024-06-27T09:35:53.802082Z","iopub.execute_input":"2024-06-27T09:35:53.802494Z","iopub.status.idle":"2024-06-27T09:35:54.221863Z","shell.execute_reply.started":"2024-06-27T09:35:53.802464Z","shell.execute_reply":"2024-06-27T09:35:54.220371Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"submission.info()","metadata":{"execution":{"iopub.status.busy":"2024-06-27T09:35:58.118501Z","iopub.execute_input":"2024-06-27T09:35:58.118964Z","iopub.status.idle":"2024-06-27T09:35:58.139762Z","shell.execute_reply.started":"2024-06-27T09:35:58.118929Z","shell.execute_reply":"2024-06-27T09:35:58.138374Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"submission.head()","metadata":{"execution":{"iopub.status.busy":"2024-06-27T09:35:44.919707Z","iopub.execute_input":"2024-06-27T09:35:44.920201Z","iopub.status.idle":"2024-06-27T09:35:44.935405Z","shell.execute_reply.started":"2024-06-27T09:35:44.920165Z","shell.execute_reply":"2024-06-27T09:35:44.933571Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"","metadata":{},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"","metadata":{},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"","metadata":{},"execution_count":null,"outputs":[]}]}