{"metadata":{"kernelspec":{"language":"python","display_name":"Python 3","name":"python3"},"language_info":{"name":"python","version":"3.10.14","mimetype":"text/x-python","codemirror_mode":{"name":"ipython","version":3},"pygments_lexer":"ipython3","nbconvert_exporter":"python","file_extension":".py"},"kaggle":{"accelerator":"none","dataSources":[{"sourceId":88400,"databundleVersionId":10121331,"sourceType":"competition"}],"dockerImageVersionId":30786,"isInternetEnabled":true,"language":"python","sourceType":"notebook","isGpuEnabled":false}},"nbformat_minor":4,"nbformat":4,"cells":[{"cell_type":"code","source":"# This Python 3 environment comes with many helpful analytics libraries installed\n# It is defined by the kaggle/python Docker image: https://github.com/kaggle/docker-python\n# For example, here's several helpful packages to load\n\nimport numpy as np # linear algebra\nimport pandas as pd # data processing, CSV file I/O (e.g. pd.read_csv)\n\n# Input data files are available in the read-only \"../input/\" directory\n# For example, running this (by clicking run or pressing Shift+Enter) will list all files under the input directory\n\nimport os\nfor dirname, _, filenames in os.walk('/kaggle/input'):\n    for filename in filenames:\n        print(os.path.join(dirname, filename))\n\n# You can write up to 20GB to the current directory (/kaggle/working/) that gets preserved as output when you create a version using \"Save & Run All\" \n# You can also write temporary files to /kaggle/temp/, but they won't be saved outside of the current session","metadata":{"_uuid":"8f2839f25d086af736a60e9eeb907d3b93b6e0e5","_cell_guid":"b1076dfc-b9ad-4769-8c92-a6c4dae69d19","trusted":true,"execution":{"iopub.status.busy":"2024-11-23T03:01:47.753017Z","iopub.execute_input":"2024-11-23T03:01:47.753469Z","iopub.status.idle":"2024-11-23T03:01:47.763106Z","shell.execute_reply.started":"2024-11-23T03:01:47.753426Z","shell.execute_reply":"2024-11-23T03:01:47.761876Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"train = pd.read_csv(\"/kaggle/input/aiffel-ds-3-credit-card-fraud-detection/train.csv\") \ntest = pd.read_csv(\"/kaggle/input/aiffel-ds-3-credit-card-fraud-detection/test.csv\")\nsubmission = pd.read_csv(\"/kaggle/input/aiffel-ds-3-credit-card-fraud-detection/sample_submission.csv\")","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2024-11-23T03:01:47.765071Z","iopub.execute_input":"2024-11-23T03:01:47.766050Z","iopub.status.idle":"2024-11-23T03:01:50.487201Z","shell.execute_reply.started":"2024-11-23T03:01:47.765995Z","shell.execute_reply":"2024-11-23T03:01:50.486128Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"train.head()","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2024-11-23T03:01:50.489165Z","iopub.execute_input":"2024-11-23T03:01:50.489612Z","iopub.status.idle":"2024-11-23T03:01:50.513799Z","shell.execute_reply.started":"2024-11-23T03:01:50.489562Z","shell.execute_reply":"2024-11-23T03:01:50.512599Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"test.head()","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2024-11-23T03:01:50.515425Z","iopub.execute_input":"2024-11-23T03:01:50.516116Z","iopub.status.idle":"2024-11-23T03:01:50.540927Z","shell.execute_reply.started":"2024-11-23T03:01:50.516061Z","shell.execute_reply":"2024-11-23T03:01:50.539621Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"# test가 170883부터 시작하는 것을 볼 수 있어 170882를 기점으로 그 뒷 부분은 자름\n\ntrain['id'].max() , test['id'].min()","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2024-11-23T03:01:50.543587Z","iopub.execute_input":"2024-11-23T03:01:50.544011Z","iopub.status.idle":"2024-11-23T03:01:50.558002Z","shell.execute_reply.started":"2024-11-23T03:01:50.543969Z","shell.execute_reply":"2024-11-23T03:01:50.556528Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"train.head()","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2024-11-23T03:01:50.559649Z","iopub.execute_input":"2024-11-23T03:01:50.560191Z","iopub.status.idle":"2024-11-23T03:01:50.586700Z","shell.execute_reply.started":"2024-11-23T03:01:50.560135Z","shell.execute_reply":"2024-11-23T03:01:50.585523Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"train.shape","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2024-11-23T03:01:50.588118Z","iopub.execute_input":"2024-11-23T03:01:50.588586Z","iopub.status.idle":"2024-11-23T03:01:50.595568Z","shell.execute_reply.started":"2024-11-23T03:01:50.588537Z","shell.execute_reply":"2024-11-23T03:01:50.594571Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"test.shape","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2024-11-23T03:01:50.597089Z","iopub.execute_input":"2024-11-23T03:01:50.597525Z","iopub.status.idle":"2024-11-23T03:01:50.607596Z","shell.execute_reply.started":"2024-11-23T03:01:50.597476Z","shell.execute_reply":"2024-11-23T03:01:50.606388Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"train.info()","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2024-11-23T03:01:50.609037Z","iopub.execute_input":"2024-11-23T03:01:50.609419Z","iopub.status.idle":"2024-11-23T03:01:50.633762Z","shell.execute_reply.started":"2024-11-23T03:01:50.609384Z","shell.execute_reply":"2024-11-23T03:01:50.632667Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"# Class의 비율을 확인하기 위해서 normalize=True 적용 후 0 과 1의 비율을 확인\ntrain['Class'].value_counts(normalize = True)*100","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2024-11-23T03:01:50.635252Z","iopub.execute_input":"2024-11-23T03:01:50.635734Z","iopub.status.idle":"2024-11-23T03:01:50.646821Z","shell.execute_reply.started":"2024-11-23T03:01:50.635680Z","shell.execute_reply":"2024-11-23T03:01:50.645535Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"# 필요한 패키지를 임포트 후 데이터 불러오기\n\nimport numpy as np\n\nimport pandas as pd\n\n\n\nfrom sklearn.ensemble import RandomForestClassifier, VotingClassifier\n\nfrom sklearn.model_selection import train_test_split, GridSearchCV\n\nfrom sklearn.linear_model import LogisticRegression\n\nfrom lightgbm import LGBMClassifier\n\nfrom xgboost import XGBClassifier\n\nimport seaborn as sns\n\nimport matplotlib.pyplot as plt\n\nfrom sklearn.metrics import accuracy_score, precision_score, recall_score, confusion_matrix, f1_score, roc_auc_score\n\nimport warnings\n\nfrom xgboost import XGBClassifier\n\nwarnings.filterwarnings('ignore')\n\n%matplotlib inline","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2024-11-23T03:01:50.651630Z","iopub.execute_input":"2024-11-23T03:01:50.652002Z","iopub.status.idle":"2024-11-23T03:01:50.660795Z","shell.execute_reply.started":"2024-11-23T03:01:50.651967Z","shell.execute_reply":"2024-11-23T03:01:50.659555Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"# 피처별 상관관계 분석\n# Class와 상관관계가 높은 값들을 위주로 이상치 제거\n# 음의 상관 관계가 높게 나타나는 V14 이상치 제거\n\nplt.figure(figsize=(9,9))\ncorr = train.corr()\nsns.heatmap(corr, cmap='RdBu')","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2024-11-23T03:01:50.662058Z","iopub.execute_input":"2024-11-23T03:01:50.662413Z","iopub.status.idle":"2024-11-23T03:01:51.856110Z","shell.execute_reply.started":"2024-11-23T03:01:50.662378Z","shell.execute_reply":"2024-11-23T03:01:51.855043Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"# Amount의 분포 확인\n\nsns.histplot(train['Amount'], bins=100, kde=True)\n\n# 대부분 2500이하의 값들이 존재함을 알 수 있음.","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2024-11-23T03:01:51.858092Z","iopub.execute_input":"2024-11-23T03:01:51.858567Z","iopub.status.idle":"2024-11-23T03:01:53.061914Z","shell.execute_reply.started":"2024-11-23T03:01:51.858513Z","shell.execute_reply":"2024-11-23T03:01:53.060817Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"# 한쪽으로 치우친 모습을 나타내기 때문에 정규분포로 만들기 위해 'log1p'를 적용하는 함수 생성\n# log1p 변환 후 필요없는 'Time'과 'Amount' 컬럼은 제거 (by.Amount_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    # get_outlier 인자 중에 df.copy()에서 '괄호()'를 꼭 써야 하는 이유는\n    # get_preprocessed_df 함수에서 df.copy 메서드를 호출할때 괄호를 포함해야 하기 떄문\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":{"trusted":true,"execution":{"iopub.status.busy":"2024-11-23T03:01:53.063294Z","iopub.execute_input":"2024-11-23T03:01:53.063651Z","iopub.status.idle":"2024-11-23T03:01:53.070406Z","shell.execute_reply.started":"2024-11-23T03:01:53.063613Z","shell.execute_reply":"2024-11-23T03:01:53.069279Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"# 사전 데이터 가공 후 학습과 테스트 데이터 세트를 반환하는 함수 생성\n\ndef get_train_test_dataset(df=None):\n    df_copy = get_preprocessed_df(df)\n\n    # X_features 과 y_target 를 분리하기 위해 X_features에는 Class 컬럼을 제외한 전체 행,\n    # y_target에는 Class 컬럼만 있는 전체 행을 배분\n    \n    X_features = df_copy.iloc[:, :-1]\n    y_target = df_copy.iloc[:, -1]\n\n    \n    # train_test_split안에 있는 인수로 'stratify'는 데이터셋을 훈련세트와 테스트 세트로 나눌때,\n    # 특정 클래스(y_target)의 테이터 비율이 심하게 불균형이 있을 수 있으므로, \n    # stratify = y_target 으로 설정하면, 분할 후에도 각 클래스의 비율이 \n    # 원본 데이터셋과 동일하게 유지되므로 적용했음.\n    \n    X_train , X_test, y_train, y_test = train_test_split(X_features, y_target,\n                                                        test_size=0.3, random_state=0,\n                                                        stratify=y_target)\n\n    return X_train, X_test, y_train, y_test\n    ","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2024-11-23T03:01:53.071964Z","iopub.execute_input":"2024-11-23T03:01:53.072488Z","iopub.status.idle":"2024-11-23T03:01:53.084153Z","shell.execute_reply.started":"2024-11-23T03:01:53.072431Z","shell.execute_reply":"2024-11-23T03:01:53.082880Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"# 분류 평가 종류인 정확도, 정밀도, 재현율, f1스코어, roc_auc 를 만드는 함수 생성\n\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    precision = precision_score(y_test, pred)\n    recall = recall_score(y_test, pred)\n    f1 = f1_score(y_test, pred)\n\n    # 다른 평가 종류들과는 다르게 roc_auc 스코어에서는 인자에 'pred'대신 'pred_proba'를\n    # 쓰는 이유는 해당 평가 방식이 모델의 예측 확률값을 기반으로 하기 때문이다.\n    # 다른 평가 지표들과 비교할때 AUC는 모든 가능한 결정 임계값(threshold)을 고려하여 모델을 평가함.\n    roc_auc = roc_auc_score(y_test, pred_proba)\n\n    print(\"오차 행렬\")\n    print(confusion)\n    print(f\"정확도: {accuracy:.4f}, 정밀도: {precision: .4f}, 재현율: {recall: .4f}, f1스코어: {f1:.4f}, roc-auc: {roc_auc:.4f}\")","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2024-11-23T03:01:53.086076Z","iopub.execute_input":"2024-11-23T03:01:53.086615Z","iopub.status.idle":"2024-11-23T03:01:53.100283Z","shell.execute_reply.started":"2024-11-23T03:01:53.086556Z","shell.execute_reply":"2024-11-23T03:01:53.099184Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"# 이제 학습 및 예측 데이터를 만들기 위해 get_model_train_eval 함수 생성\n\ndef get_model_train_eval(model, ftr_train=None, ftr_test=None, \n                         tgt_train=None, tgt_test=None):\n    model.fit(ftr_train, tgt_train)\n    pred = model.predict(ftr_test)\n\n    # 예측 비율을 만들때 ftr_test의 두번째열(1)에 Class가 있으므로 슬라이싱 인덱스 적용\n    pred_proba = model.predict_proba(ftr_test)[:, 1]\n    get_clf_eval(tgt_test, pred, pred_proba)","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2024-11-23T03:01:53.101665Z","iopub.execute_input":"2024-11-23T03:01:53.102157Z","iopub.status.idle":"2024-11-23T03:01:53.115501Z","shell.execute_reply.started":"2024-11-23T03:01:53.102104Z","shell.execute_reply":"2024-11-23T03:01:53.114287Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"# <교제 288~289페이지 내용>\n\n# weight를 1.5로 적용하는 이유는 특정 클래스나 샘플의 중요도를 조정하기 위한 일반적인 접근법\n# 특히, 분류 문제에서 데이터가 불균형한 경우에 1.5로 자주 사용\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    \n    # outlier_index(전체 데이터의 패턴에서 벗어난 이상치 값의 데이터_는 \n    # iqr(사분위수)에서 가중치까지 전부 적용했을때 \n    # 가장 낮은값(lowest_val)보다 낮고, 가장 높은값(highest_val)보다 \n    # 높은 값들을 이상치로 간주하여 두 집합간의 or('|')연산을 써서 적용\n    outlier_index = fraud[(fraud < lowest_val) | (fraud > highest_val)].index\n    \n    return outlier_index","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2024-11-23T03:01:53.119404Z","iopub.execute_input":"2024-11-23T03:01:53.120002Z","iopub.status.idle":"2024-11-23T03:01:53.128240Z","shell.execute_reply.started":"2024-11-23T03:01:53.119946Z","shell.execute_reply":"2024-11-23T03:01:53.127207Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"X_train , X_test, y_train, y_test = get_train_test_dataset(train)","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2024-11-23T03:01:53.131928Z","iopub.execute_input":"2024-11-23T03:01:53.132327Z","iopub.status.idle":"2024-11-23T03:01:53.334404Z","shell.execute_reply.started":"2024-11-23T03:01:53.132291Z","shell.execute_reply":"2024-11-23T03:01:53.333431Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"print(\"학습 데이터 레이블 값 비율\")\nprint(y_train.value_counts() / y_train.shape[0]*100)\nprint()\nprint(\"테스트 데이터 레이블 값 비율\")\nprint(y_test.value_counts() / y_test.shape[0] *100)","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2024-11-23T03:01:53.335855Z","iopub.execute_input":"2024-11-23T03:01:53.336234Z","iopub.status.idle":"2024-11-23T03:01:53.346596Z","shell.execute_reply.started":"2024-11-23T03:01:53.336195Z","shell.execute_reply":"2024-11-23T03:01:53.345332Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"from imblearn.over_sampling import SMOTE\n\nsmote = SMOTE(random_state=0)\n\nX_train_over , y_train_over = smote.fit_resample(X_train, y_train)","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2024-11-23T03:01:53.347931Z","iopub.execute_input":"2024-11-23T03:01:53.348262Z","iopub.status.idle":"2024-11-23T03:01:53.561955Z","shell.execute_reply.started":"2024-11-23T03:01:53.348229Z","shell.execute_reply":"2024-11-23T03:01:53.560912Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"print(\"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":{"trusted":true,"execution":{"iopub.status.busy":"2024-11-23T03:01:53.563183Z","iopub.execute_input":"2024-11-23T03:01:53.563531Z","iopub.status.idle":"2024-11-23T03:01:53.575387Z","shell.execute_reply.started":"2024-11-23T03:01:53.563495Z","shell.execute_reply":"2024-11-23T03:01:53.573964Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"lr_clf = LogisticRegression(max_iter=1000)\nlgbm_clf = LGBMClassifier(n_estimators=1000 , num_leaves=64,\n                         n_jobs= -1, boost_from_average=False)","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2024-11-23T03:01:53.577379Z","iopub.execute_input":"2024-11-23T03:01:53.577869Z","iopub.status.idle":"2024-11-23T03:01:53.583959Z","shell.execute_reply.started":"2024-11-23T03:01:53.577817Z","shell.execute_reply":"2024-11-23T03:01:53.582882Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"get_model_train_eval(model= lr_clf, ftr_train = X_train, ftr_test = X_test,\n                    tgt_train = y_train, tgt_test = y_test)","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2024-11-23T03:01:53.587289Z","iopub.execute_input":"2024-11-23T03:01:53.587942Z","iopub.status.idle":"2024-11-23T03:01:55.806813Z","shell.execute_reply.started":"2024-11-23T03:01:53.587900Z","shell.execute_reply":"2024-11-23T03:01:55.805722Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"get_model_train_eval(model = lr_clf, ftr_train = X_train_over, ftr_test = X_test,\n                    tgt_train = y_train_over, tgt_test = y_test)","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2024-11-23T03:01:55.808277Z","iopub.execute_input":"2024-11-23T03:01:55.808739Z","iopub.status.idle":"2024-11-23T03:01:57.282070Z","shell.execute_reply.started":"2024-11-23T03:01:55.808700Z","shell.execute_reply":"2024-11-23T03:01:57.281271Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"get_model_train_eval(model = lgbm_clf, ftr_train = X_train, ftr_test = X_test,\n                    tgt_train = y_train, tgt_test = y_test)","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2024-11-23T03:01:57.283004Z","iopub.execute_input":"2024-11-23T03:01:57.283346Z","iopub.status.idle":"2024-11-23T03:02:17.805324Z","shell.execute_reply.started":"2024-11-23T03:01:57.283311Z","shell.execute_reply":"2024-11-23T03:02:17.804134Z"},"collapsed":true,"jupyter":{"outputs_hidden":true}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"get_model_train_eval(model = lgbm_clf, ftr_train = X_train_over, ftr_test = X_test,\n                    tgt_train = y_train_over, tgt_test = y_test)","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2024-11-23T03:02:17.806565Z","iopub.execute_input":"2024-11-23T03:02:17.806899Z","iopub.status.idle":"2024-11-23T03:03:03.489108Z","shell.execute_reply.started":"2024-11-23T03:02:17.806867Z","shell.execute_reply":"2024-11-23T03:03:03.487888Z"},"collapsed":true,"jupyter":{"outputs_hidden":true}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"test['Amount_Scaled'] = np.log1p(test['Amount'])","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2024-11-23T03:04:14.455241Z","iopub.execute_input":"2024-11-23T03:04:14.455684Z","iopub.status.idle":"2024-11-23T03:04:14.464539Z","shell.execute_reply.started":"2024-11-23T03:04:14.455647Z","shell.execute_reply":"2024-11-23T03:04:14.463432Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"test.drop(['Time','Amount'], axis=1, inplace=True)","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2024-11-23T03:04:45.704739Z","iopub.execute_input":"2024-11-23T03:04:45.705318Z","iopub.status.idle":"2024-11-23T03:04:45.719824Z","shell.execute_reply.started":"2024-11-23T03:04:45.705268Z","shell.execute_reply":"2024-11-23T03:04:45.718500Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"lgbm_pred = lgbm_clf.predict(test)","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2024-11-23T03:05:02.024496Z","iopub.execute_input":"2024-11-23T03:05:02.025599Z","iopub.status.idle":"2024-11-23T03:05:08.640083Z","shell.execute_reply.started":"2024-11-23T03:05:02.025551Z","shell.execute_reply":"2024-11-23T03:05:08.638951Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"lgbm_pred_proba = lgbm_clf.predict_proba(test)","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2024-11-23T03:05:29.747830Z","iopub.execute_input":"2024-11-23T03:05:29.748235Z","iopub.status.idle":"2024-11-23T03:05:36.734698Z","shell.execute_reply.started":"2024-11-23T03:05:29.748197Z","shell.execute_reply":"2024-11-23T03:05:36.733615Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"test['Class'] = lgbm_pred","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2024-11-23T03:05:54.163541Z","iopub.execute_input":"2024-11-23T03:05:54.164370Z","iopub.status.idle":"2024-11-23T03:05:54.169950Z","shell.execute_reply.started":"2024-11-23T03:05:54.164326Z","shell.execute_reply":"2024-11-23T03:05:54.168862Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"test.Class.value_counts()","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2024-11-23T03:06:09.342104Z","iopub.execute_input":"2024-11-23T03:06:09.342549Z","iopub.status.idle":"2024-11-23T03:06:09.352225Z","shell.execute_reply.started":"2024-11-23T03:06:09.342497Z","shell.execute_reply":"2024-11-23T03:06:09.350850Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"del submission[\"Class\"]","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2024-11-23T03:06:26.996909Z","iopub.execute_input":"2024-11-23T03:06:26.997717Z","iopub.status.idle":"2024-11-23T03:06:27.002734Z","shell.execute_reply.started":"2024-11-23T03:06:26.997677Z","shell.execute_reply":"2024-11-23T03:06:27.001643Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"test['Class'] = lgbm_pred_proba","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2024-11-23T03:06:45.642528Z","iopub.execute_input":"2024-11-23T03:06:45.643548Z","iopub.status.idle":"2024-11-23T03:06:45.648984Z","shell.execute_reply.started":"2024-11-23T03:06:45.643499Z","shell.execute_reply":"2024-11-23T03:06:45.647770Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"submission = submission.merge(test[['id','Class']], on='id')","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2024-11-23T03:07:12.299646Z","iopub.execute_input":"2024-11-23T03:07:12.301195Z","iopub.status.idle":"2024-11-23T03:07:12.316157Z","shell.execute_reply.started":"2024-11-23T03:07:12.301135Z","shell.execute_reply":"2024-11-23T03:07:12.315177Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"submission.to_csv(\"./submission.csv\", index=False)","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2024-11-23T03:07:45.506450Z","iopub.execute_input":"2024-11-23T03:07:45.507047Z","iopub.status.idle":"2024-11-23T03:07:45.753392Z","shell.execute_reply.started":"2024-11-23T03:07:45.507004Z","shell.execute_reply":"2024-11-23T03:07:45.752123Z"}},"outputs":[],"execution_count":null}]}