{"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":81933,"databundleVersionId":9643020,"sourceType":"competition"}],"dockerImageVersionId":30786,"isInternetEnabled":false,"language":"python","sourceType":"notebook","isGpuEnabled":false}},"nbformat_minor":4,"nbformat":4,"cells":[{"cell_type":"code","source":"import pandas as pd\npd.set_option('display.max_rows', 100)\n\nfrom catboost import CatBoostClassifier","metadata":{"_uuid":"8f2839f25d086af736a60e9eeb907d3b93b6e0e5","_cell_guid":"b1076dfc-b9ad-4769-8c92-a6c4dae69d19","execution":{"iopub.status.busy":"2024-10-10T14:53:22.525676Z","iopub.execute_input":"2024-10-10T14:53:22.526567Z","iopub.status.idle":"2024-10-10T14:53:22.531994Z","shell.execute_reply.started":"2024-10-10T14:53:22.526516Z","shell.execute_reply":"2024-10-10T14:53:22.530771Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"data_dict = pd.read_csv('/kaggle/input/child-mind-institute-problematic-internet-use/data_dictionary.csv')\n\nprint(data_dict.shape)\n\ndata_dict","metadata":{"execution":{"iopub.status.busy":"2024-10-10T14:53:22.699483Z","iopub.execute_input":"2024-10-10T14:53:22.700525Z","iopub.status.idle":"2024-10-10T14:53:22.738928Z","shell.execute_reply.started":"2024-10-10T14:53:22.700471Z","shell.execute_reply":"2024-10-10T14:53:22.737758Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"train_df = pd.read_csv('/kaggle/input/child-mind-institute-problematic-internet-use/train.csv')\n\nprint(train_df.shape)\n\ntrain_df.head()","metadata":{"execution":{"iopub.status.busy":"2024-10-10T15:02:59.672177Z","iopub.execute_input":"2024-10-10T15:02:59.672645Z","iopub.status.idle":"2024-10-10T15:02:59.756604Z","shell.execute_reply.started":"2024-10-10T15:02:59.672600Z","shell.execute_reply":"2024-10-10T15:02:59.755422Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"feature_cols = ['Basic_Demos-Sex', 'Basic_Demos-Age', 'CGAS-CGAS_Score', 'PreInt_EduHx-computerinternet_hoursday', 'SDS-SDS_Total_T']","metadata":{"execution":{"iopub.status.busy":"2024-10-10T14:53:22.845095Z","iopub.execute_input":"2024-10-10T14:53:22.845597Z","iopub.status.idle":"2024-10-10T14:53:22.850829Z","shell.execute_reply.started":"2024-10-10T14:53:22.845543Z","shell.execute_reply":"2024-10-10T14:53:22.849767Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"We will take for consideration \n- Sex\n- Age\n- Mental Score\n- Hours of Internet Usage\n- Sleep disorder score","metadata":{}},{"cell_type":"code","source":"target_col = 'sii'","metadata":{"execution":{"iopub.status.busy":"2024-10-10T14:53:23.179348Z","iopub.execute_input":"2024-10-10T14:53:23.179821Z","iopub.status.idle":"2024-10-10T14:53:23.184679Z","shell.execute_reply.started":"2024-10-10T14:53:23.179777Z","shell.execute_reply":"2024-10-10T14:53:23.183468Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"As for the target - we will build single MultiClassification model.","metadata":{}},{"cell_type":"code","source":"train_X = train_df[feature_cols]\ntrain_X.head()","metadata":{"execution":{"iopub.status.busy":"2024-10-10T14:53:23.473603Z","iopub.execute_input":"2024-10-10T14:53:23.474059Z","iopub.status.idle":"2024-10-10T14:53:23.490596Z","shell.execute_reply.started":"2024-10-10T14:53:23.474014Z","shell.execute_reply":"2024-10-10T14:53:23.489348Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"train_X.isna().mean()","metadata":{"execution":{"iopub.status.busy":"2024-10-10T14:53:23.617316Z","iopub.execute_input":"2024-10-10T14:53:23.617783Z","iopub.status.idle":"2024-10-10T14:53:23.628417Z","shell.execute_reply.started":"2024-10-10T14:53:23.617739Z","shell.execute_reply":"2024-10-10T14:53:23.627105Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"CatBoost will work with NaN features just fine","metadata":{}},{"cell_type":"code","source":"train_y = train_df[target_col]\ntrain_y.head()","metadata":{"execution":{"iopub.status.busy":"2024-10-10T14:53:23.949905Z","iopub.execute_input":"2024-10-10T14:53:23.950599Z","iopub.status.idle":"2024-10-10T14:53:23.962610Z","shell.execute_reply.started":"2024-10-10T14:53:23.950530Z","shell.execute_reply":"2024-10-10T14:53:23.960938Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"train_y.value_counts(dropna=False)","metadata":{"execution":{"iopub.status.busy":"2024-10-10T14:53:24.098289Z","iopub.execute_input":"2024-10-10T14:53:24.098770Z","iopub.status.idle":"2024-10-10T14:53:24.108443Z","shell.execute_reply.started":"2024-10-10T14:53:24.098729Z","shell.execute_reply":"2024-10-10T14:53:24.107239Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"Around 33% percent of target is NaN, we will drop those entries for the training.","metadata":{}},{"cell_type":"code","source":"nan_target_filter = train_y.isna()\nnan_target_filter.sum()","metadata":{"execution":{"iopub.status.busy":"2024-10-10T14:53:24.801468Z","iopub.execute_input":"2024-10-10T14:53:24.801892Z","iopub.status.idle":"2024-10-10T14:53:24.810252Z","shell.execute_reply.started":"2024-10-10T14:53:24.801852Z","shell.execute_reply":"2024-10-10T14:53:24.809041Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"train_X = train_X[~nan_target_filter]\ntrain_y = train_y[~nan_target_filter]\n\ntrain_X.shape, train_y.shape","metadata":{"execution":{"iopub.status.busy":"2024-10-10T14:53:24.992151Z","iopub.execute_input":"2024-10-10T14:53:24.993372Z","iopub.status.idle":"2024-10-10T14:53:25.003783Z","shell.execute_reply.started":"2024-10-10T14:53:24.993315Z","shell.execute_reply":"2024-10-10T14:53:25.002512Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"model = CatBoostClassifier(n_estimators = 100, verbose=False)","metadata":{"execution":{"iopub.status.busy":"2024-10-10T14:54:42.684935Z","iopub.execute_input":"2024-10-10T14:54:42.685365Z","iopub.status.idle":"2024-10-10T14:54:42.690780Z","shell.execute_reply.started":"2024-10-10T14:54:42.685323Z","shell.execute_reply":"2024-10-10T14:54:42.689547Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"Default 1000 estimators may overfit 3 thousand examples. Let's take much parameters value.","metadata":{}},{"cell_type":"code","source":"model.fit(train_X, train_y)","metadata":{"execution":{"iopub.status.busy":"2024-10-10T14:54:43.094636Z","iopub.execute_input":"2024-10-10T14:54:43.095504Z","iopub.status.idle":"2024-10-10T14:54:43.342572Z","shell.execute_reply.started":"2024-10-10T14:54:43.095453Z","shell.execute_reply":"2024-10-10T14:54:43.341369Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"test_df = pd.read_csv('/kaggle/input/child-mind-institute-problematic-internet-use/test.csv')\ntest_df.head()","metadata":{"execution":{"iopub.status.busy":"2024-10-10T14:55:04.737821Z","iopub.execute_input":"2024-10-10T14:55:04.738296Z","iopub.status.idle":"2024-10-10T14:55:04.777668Z","shell.execute_reply.started":"2024-10-10T14:55:04.738253Z","shell.execute_reply":"2024-10-10T14:55:04.776443Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"test_X = test_df[feature_cols]\ntest_X","metadata":{"execution":{"iopub.status.busy":"2024-10-10T14:55:39.748225Z","iopub.execute_input":"2024-10-10T14:55:39.748707Z","iopub.status.idle":"2024-10-10T14:55:39.770566Z","shell.execute_reply.started":"2024-10-10T14:55:39.748665Z","shell.execute_reply":"2024-10-10T14:55:39.769421Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"test_y = model.predict(test_X)\ntest_y.shape","metadata":{"execution":{"iopub.status.busy":"2024-10-10T14:56:49.392532Z","iopub.execute_input":"2024-10-10T14:56:49.393602Z","iopub.status.idle":"2024-10-10T14:56:49.402520Z","shell.execute_reply.started":"2024-10-10T14:56:49.393552Z","shell.execute_reply":"2024-10-10T14:56:49.401412Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"submission = pd.read_csv('/kaggle/input/child-mind-institute-problematic-internet-use/sample_submission.csv')\n\nprint(submission.shape)\n\nsubmission.head()","metadata":{"execution":{"iopub.status.busy":"2024-10-10T14:57:01.367908Z","iopub.execute_input":"2024-10-10T14:57:01.368408Z","iopub.status.idle":"2024-10-10T14:57:01.383428Z","shell.execute_reply.started":"2024-10-10T14:57:01.368332Z","shell.execute_reply":"2024-10-10T14:57:01.382191Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"submission['sii'] = test_y\nsubmission.head()","metadata":{"execution":{"iopub.status.busy":"2024-10-10T14:57:23.846647Z","iopub.execute_input":"2024-10-10T14:57:23.847100Z","iopub.status.idle":"2024-10-10T14:57:23.860743Z","shell.execute_reply.started":"2024-10-10T14:57:23.847057Z","shell.execute_reply":"2024-10-10T14:57:23.859173Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"submission.to_csv('submission.csv', index=False)","metadata":{"execution":{"iopub.status.busy":"2024-10-10T14:58:17.818457Z","iopub.execute_input":"2024-10-10T14:58:17.819797Z","iopub.status.idle":"2024-10-10T14:58:17.826231Z","shell.execute_reply.started":"2024-10-10T14:58:17.819746Z","shell.execute_reply":"2024-10-10T14:58:17.825063Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"pd.read_csv('submission.csv')","metadata":{"execution":{"iopub.status.busy":"2024-10-10T14:58:41.673830Z","iopub.execute_input":"2024-10-10T14:58:41.674269Z","iopub.status.idle":"2024-10-10T14:58:41.691983Z","shell.execute_reply.started":"2024-10-10T14:58:41.674222Z","shell.execute_reply":"2024-10-10T14:58:41.690800Z"},"trusted":true},"execution_count":null,"outputs":[]}]}