{"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":50160,"databundleVersionId":7921029,"sourceType":"competition"}],"dockerImageVersionId":30698,"isInternetEnabled":false,"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","execution":{"iopub.status.busy":"2024-04-27T14:28:10.772013Z","iopub.execute_input":"2024-04-27T14:28:10.772456Z","iopub.status.idle":"2024-04-27T14:28:11.328974Z","shell.execute_reply.started":"2024-04-27T14:28:10.772427Z","shell.execute_reply":"2024-04-27T14:28:11.327609Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"train=pd.read_csv(\"/kaggle/input/home-credit-credit-risk-model-stability/csv_files/train/train_base.csv\",encoding='latin')\ntest=pd.read_csv(\"/kaggle/input/home-credit-credit-risk-model-stability/csv_files/test/test_base.csv\")\ntrain.head()","metadata":{"execution":{"iopub.status.busy":"2024-04-27T14:28:11.331360Z","iopub.execute_input":"2024-04-27T14:28:11.332229Z","iopub.status.idle":"2024-04-27T14:28:13.058367Z","shell.execute_reply.started":"2024-04-27T14:28:11.332194Z","shell.execute_reply":"2024-04-27T14:28:13.057447Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"test.head()","metadata":{"execution":{"iopub.status.busy":"2024-04-27T14:28:13.059569Z","iopub.execute_input":"2024-04-27T14:28:13.060835Z","iopub.status.idle":"2024-04-27T14:28:13.073261Z","shell.execute_reply.started":"2024-04-27T14:28:13.060775Z","shell.execute_reply":"2024-04-27T14:28:13.071773Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"train.info()\ntrain.columns","metadata":{"execution":{"iopub.status.busy":"2024-04-27T14:28:13.076522Z","iopub.execute_input":"2024-04-27T14:28:13.077113Z","iopub.status.idle":"2024-04-27T14:28:13.290635Z","shell.execute_reply.started":"2024-04-27T14:28:13.077070Z","shell.execute_reply":"2024-04-27T14:28:13.289487Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"train.fillna(0, inplace=True)\ntrain['date_decision'] = pd.to_datetime(train['date_decision'])\nx= train.drop(['case_id', 'date_decision'], axis=1)\ny= train.iloc[:, -1]","metadata":{"execution":{"iopub.status.busy":"2024-04-27T14:28:13.292284Z","iopub.execute_input":"2024-04-27T14:28:13.292734Z","iopub.status.idle":"2024-04-27T14:28:13.821449Z","shell.execute_reply.started":"2024-04-27T14:28:13.292697Z","shell.execute_reply":"2024-04-27T14:28:13.820140Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"from sklearn.model_selection import train_test_split\nfrom sklearn.ensemble import RandomForestClassifier\nfrom sklearn.metrics import roc_auc_score\nx_train,x_test,y_train, y_test = train_test_split(x, y, test_size=0.2, random_state=42)\nmodel=RandomForestClassifier(n_estimators=100,max_depth=4)\nmodel.fit(x_train,y_train)\npre1=model.predict_proba(x_test)[:,1]\nacc1=roc_auc_score(y_test,pre1)\nacc1\n","metadata":{"execution":{"iopub.status.busy":"2024-04-27T14:28:13.822924Z","iopub.execute_input":"2024-04-27T14:28:13.823829Z","iopub.status.idle":"2024-04-27T14:29:11.462906Z","shell.execute_reply.started":"2024-04-27T14:28:13.823777Z","shell.execute_reply":"2024-04-27T14:29:11.461607Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"x_train = train.drop(['case_id', 'date_decision', 'target'], axis=1)\ny_train = train['target']\nx_test = test.drop(['case_id', 'date_decision'], axis=1)\nmodel.fit(x_train,y_train)\npre=model.predict_proba(x_test)[:,1]\nsubmission = pd.DataFrame({'case_id': test['case_id'].to_numpy(), 'prediction': pre})\n\nsubmission.to_csv('submission.csv', index=False)","metadata":{"execution":{"iopub.status.busy":"2024-04-27T14:29:11.464460Z","iopub.execute_input":"2024-04-27T14:29:11.464915Z","iopub.status.idle":"2024-04-27T14:29:52.665381Z","shell.execute_reply.started":"2024-04-27T14:29:11.464875Z","shell.execute_reply":"2024-04-27T14:29:52.664258Z"},"trusted":true},"execution_count":null,"outputs":[]}]}