{"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":9559407,"sourceType":"datasetVersion","datasetId":5825211}],"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\n\nimport os\nfrom sklearn.metrics import cohen_kappa_score\nfrom sklearn.metrics import accuracy_score\n\nfrom catboost import CatBoostClassifier, cv, Pool\nfrom sklearn.model_selection import train_test_split\nimport os","metadata":{"_uuid":"8f2839f25d086af736a60e9eeb907d3b93b6e0e5","_cell_guid":"b1076dfc-b9ad-4769-8c92-a6c4dae69d19","execution":{"iopub.status.busy":"2024-10-06T10:27:43.776805Z","iopub.execute_input":"2024-10-06T10:27:43.777268Z","iopub.status.idle":"2024-10-06T10:27:50.951622Z","shell.execute_reply.started":"2024-10-06T10:27:43.777219Z","shell.execute_reply":"2024-10-06T10:27:50.950201Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df = pd.read_csv('/kaggle/input/datasetss/train.csv')","metadata":{"execution":{"iopub.status.busy":"2024-10-06T10:37:00.822100Z","iopub.execute_input":"2024-10-06T10:37:00.823043Z","iopub.status.idle":"2024-10-06T10:37:00.911553Z","shell.execute_reply.started":"2024-10-06T10:37:00.822986Z","shell.execute_reply":"2024-10-06T10:37:00.910470Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df_test = pd.read_csv('/kaggle/input/datasetss/test.csv')","metadata":{"execution":{"iopub.status.busy":"2024-10-06T10:37:28.495745Z","iopub.execute_input":"2024-10-06T10:37:28.496557Z","iopub.status.idle":"2024-10-06T10:37:28.512993Z","shell.execute_reply.started":"2024-10-06T10:37:28.496507Z","shell.execute_reply":"2024-10-06T10:37:28.511903Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"def not_columns (df):\n    not_column = []\n    for column in df.columns:\n        if column == 'sii':\n            break\n        if column not in df_test.columns:\n            not_column.append(column)\n    return not_column","metadata":{"execution":{"iopub.status.busy":"2024-10-06T10:38:02.742376Z","iopub.execute_input":"2024-10-06T10:38:02.742886Z","iopub.status.idle":"2024-10-06T10:38:02.749904Z","shell.execute_reply.started":"2024-10-06T10:38:02.742834Z","shell.execute_reply":"2024-10-06T10:38:02.748403Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"not_column = not_columns(df)","metadata":{"execution":{"iopub.status.busy":"2024-10-06T10:38:12.676692Z","iopub.execute_input":"2024-10-06T10:38:12.677147Z","iopub.status.idle":"2024-10-06T10:38:12.687934Z","shell.execute_reply.started":"2024-10-06T10:38:12.677103Z","shell.execute_reply":"2024-10-06T10:38:12.686655Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"def cleaning(df):\n    for column in df.columns:\n        if df[column].dtype == 'object':\n            df[column]=df[column].fillna(df[column].mode()[0])\n            df[column]=df[column].astype('category')\n        if df[column].dtypes == 'int64':\n            df[column]=df[column].fillna(df[column].mode()[0])\n        if df[column].dtypes == 'float64':\n            df[column]=df[column].fillna(df[column].mode()[0])\n    return df","metadata":{"execution":{"iopub.status.busy":"2024-10-06T10:38:37.263426Z","iopub.execute_input":"2024-10-06T10:38:37.264624Z","iopub.status.idle":"2024-10-06T10:38:37.272899Z","shell.execute_reply.started":"2024-10-06T10:38:37.264574Z","shell.execute_reply":"2024-10-06T10:38:37.271462Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df_cleaning = df.copy()","metadata":{"execution":{"iopub.status.busy":"2024-10-06T10:38:48.742282Z","iopub.execute_input":"2024-10-06T10:38:48.743220Z","iopub.status.idle":"2024-10-06T10:38:48.749589Z","shell.execute_reply.started":"2024-10-06T10:38:48.743169Z","shell.execute_reply":"2024-10-06T10:38:48.748207Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df_cleaning = cleaning(df_cleaning) ","metadata":{"execution":{"iopub.status.busy":"2024-10-06T10:38:59.133036Z","iopub.execute_input":"2024-10-06T10:38:59.133507Z","iopub.status.idle":"2024-10-06T10:38:59.239598Z","shell.execute_reply.started":"2024-10-06T10:38:59.133457Z","shell.execute_reply":"2024-10-06T10:38:59.238369Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df_nan_index = df.index[df['sii'].isnull()]","metadata":{"execution":{"iopub.status.busy":"2024-10-06T10:39:20.994957Z","iopub.execute_input":"2024-10-06T10:39:20.995450Z","iopub.status.idle":"2024-10-06T10:39:21.001793Z","shell.execute_reply.started":"2024-10-06T10:39:20.995403Z","shell.execute_reply":"2024-10-06T10:39:21.000259Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df_copy = df.drop(df_nan_index)","metadata":{"execution":{"iopub.status.busy":"2024-10-06T10:39:29.093826Z","iopub.execute_input":"2024-10-06T10:39:29.094329Z","iopub.status.idle":"2024-10-06T10:39:29.103746Z","shell.execute_reply.started":"2024-10-06T10:39:29.094266Z","shell.execute_reply":"2024-10-06T10:39:29.102512Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df_copy_cleaning = cleaning(df_copy)","metadata":{"execution":{"iopub.status.busy":"2024-10-06T10:39:40.685187Z","iopub.execute_input":"2024-10-06T10:39:40.686068Z","iopub.status.idle":"2024-10-06T10:39:40.773260Z","shell.execute_reply.started":"2024-10-06T10:39:40.686016Z","shell.execute_reply":"2024-10-06T10:39:40.772179Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"y = df_copy_cleaning['sii']\nX = df_copy_cleaning.drop(['id', 'sii'] , axis = 'columns')\nX = X.drop(columns = not_column)","metadata":{"execution":{"iopub.status.busy":"2024-10-06T10:39:53.326813Z","iopub.execute_input":"2024-10-06T10:39:53.327291Z","iopub.status.idle":"2024-10-06T10:39:53.344838Z","shell.execute_reply.started":"2024-10-06T10:39:53.327245Z","shell.execute_reply":"2024-10-06T10:39:53.343384Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=.3)","metadata":{"execution":{"iopub.status.busy":"2024-10-06T10:40:01.350942Z","iopub.execute_input":"2024-10-06T10:40:01.351481Z","iopub.status.idle":"2024-10-06T10:40:01.369200Z","shell.execute_reply.started":"2024-10-06T10:40:01.351430Z","shell.execute_reply":"2024-10-06T10:40:01.367652Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"cat_model = CatBoostClassifier(cat_features=['Basic_Demos-Enroll_Season',\n                                              'CGAS-Season','Physical-Season', \n                                             'Fitness_Endurance-Season',\n                                             'FGC-Season',\n                                             'BIA-Season',\n                                             'PAQ_A-Season',\n                                             'PAQ_C-Season',\n                                             #'PCIAT-Season',\n                                              'SDS-Season','PreInt_EduHx-Season'],\n                              iterations = 250,\n                              learning_rate = 0.15,\n                              depth = 6,\n                              \n#                               max_depth = 7,\n                              l2_leaf_reg = 82,\n                              )","metadata":{"execution":{"iopub.status.busy":"2024-10-06T10:40:12.610034Z","iopub.execute_input":"2024-10-06T10:40:12.610924Z","iopub.status.idle":"2024-10-06T10:40:12.622334Z","shell.execute_reply.started":"2024-10-06T10:40:12.610862Z","shell.execute_reply":"2024-10-06T10:40:12.620920Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"cat_model.fit(X_train, y_train, \n         \n        eval_set=(X_test, y_test), \n        verbose=False\n)","metadata":{"execution":{"iopub.status.busy":"2024-10-06T10:40:22.283999Z","iopub.execute_input":"2024-10-06T10:40:22.284711Z","iopub.status.idle":"2024-10-06T10:40:36.684134Z","shell.execute_reply.started":"2024-10-06T10:40:22.284656Z","shell.execute_reply":"2024-10-06T10:40:36.683022Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"train_predict = cat_model.predict(X_train)","metadata":{"execution":{"iopub.status.busy":"2024-10-06T10:40:38.958645Z","iopub.execute_input":"2024-10-06T10:40:38.959126Z","iopub.status.idle":"2024-10-06T10:40:38.971906Z","shell.execute_reply.started":"2024-10-06T10:40:38.959080Z","shell.execute_reply":"2024-10-06T10:40:38.970619Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"print(accuracy_score(y_train, train_predict))","metadata":{"execution":{"iopub.status.busy":"2024-10-06T10:40:51.345220Z","iopub.execute_input":"2024-10-06T10:40:51.346477Z","iopub.status.idle":"2024-10-06T10:40:51.355263Z","shell.execute_reply.started":"2024-10-06T10:40:51.346423Z","shell.execute_reply":"2024-10-06T10:40:51.354071Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"test_predict = cat_model.predict(X_test)","metadata":{"execution":{"iopub.status.busy":"2024-10-06T10:40:58.756160Z","iopub.execute_input":"2024-10-06T10:40:58.756638Z","iopub.status.idle":"2024-10-06T10:40:58.767219Z","shell.execute_reply.started":"2024-10-06T10:40:58.756592Z","shell.execute_reply":"2024-10-06T10:40:58.765874Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"print(accuracy_score(y_test, test_predict))","metadata":{"execution":{"iopub.status.busy":"2024-10-06T10:41:08.023859Z","iopub.execute_input":"2024-10-06T10:41:08.024767Z","iopub.status.idle":"2024-10-06T10:41:08.032461Z","shell.execute_reply.started":"2024-10-06T10:41:08.024714Z","shell.execute_reply":"2024-10-06T10:41:08.031113Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"print(cohen_kappa_score(y_test, test_predict))","metadata":{"execution":{"iopub.status.busy":"2024-10-06T10:41:22.921872Z","iopub.execute_input":"2024-10-06T10:41:22.922815Z","iopub.status.idle":"2024-10-06T10:41:22.932856Z","shell.execute_reply.started":"2024-10-06T10:41:22.922761Z","shell.execute_reply":"2024-10-06T10:41:22.931593Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df_test_copy = df_test.copy()","metadata":{"execution":{"iopub.status.busy":"2024-10-06T10:41:43.293625Z","iopub.execute_input":"2024-10-06T10:41:43.294128Z","iopub.status.idle":"2024-10-06T10:41:43.300441Z","shell.execute_reply.started":"2024-10-06T10:41:43.294079Z","shell.execute_reply":"2024-10-06T10:41:43.299152Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df_test_cleaning = cleaning(df_test_copy)","metadata":{"execution":{"iopub.status.busy":"2024-10-06T10:42:12.803484Z","iopub.execute_input":"2024-10-06T10:42:12.803992Z","iopub.status.idle":"2024-10-06T10:42:12.973383Z","shell.execute_reply.started":"2024-10-06T10:42:12.803945Z","shell.execute_reply":"2024-10-06T10:42:12.972351Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df_test_cleaning_ = df_test_cleaning.drop(['id'], axis = 'columns')","metadata":{"execution":{"iopub.status.busy":"2024-10-06T10:42:21.985947Z","iopub.execute_input":"2024-10-06T10:42:21.986417Z","iopub.status.idle":"2024-10-06T10:42:21.995941Z","shell.execute_reply.started":"2024-10-06T10:42:21.986371Z","shell.execute_reply":"2024-10-06T10:42:21.994835Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"test_test_predict = cat_model.predict(df_test_cleaning_)","metadata":{"execution":{"iopub.status.busy":"2024-10-06T10:42:57.954290Z","iopub.execute_input":"2024-10-06T10:42:57.954799Z","iopub.status.idle":"2024-10-06T10:42:57.963517Z","shell.execute_reply.started":"2024-10-06T10:42:57.954748Z","shell.execute_reply":"2024-10-06T10:42:57.962190Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"test_test_predict_pd = pd.DataFrame(df_test_copy['id'])","metadata":{"execution":{"iopub.status.busy":"2024-10-06T10:43:22.827692Z","iopub.execute_input":"2024-10-06T10:43:22.828124Z","iopub.status.idle":"2024-10-06T10:43:22.834559Z","shell.execute_reply.started":"2024-10-06T10:43:22.828083Z","shell.execute_reply":"2024-10-06T10:43:22.833151Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"test_test_predict_pd['sii'] = test_test_predict","metadata":{"execution":{"iopub.status.busy":"2024-10-06T10:43:30.523709Z","iopub.execute_input":"2024-10-06T10:43:30.524152Z","iopub.status.idle":"2024-10-06T10:43:30.530670Z","shell.execute_reply.started":"2024-10-06T10:43:30.524113Z","shell.execute_reply":"2024-10-06T10:43:30.529300Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"test_test_predict_pd.to_csv('/kaggle/working/submission.csv', index = False)","metadata":{"execution":{"iopub.status.busy":"2024-10-06T10:46:54.630710Z","iopub.execute_input":"2024-10-06T10:46:54.631410Z","iopub.status.idle":"2024-10-06T10:46:54.639811Z","shell.execute_reply.started":"2024-10-06T10:46:54.631355Z","shell.execute_reply":"2024-10-06T10:46:54.638423Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"","metadata":{},"execution_count":null,"outputs":[]}]}