{"metadata":{"kernelspec":{"name":"python3","display_name":"Python 3","language":"python"},"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"},"colab":{"provenance":[]},"kaggle":{"accelerator":"none","dataSources":[{"sourceId":81933,"databundleVersionId":9643020,"sourceType":"competition"}],"dockerImageVersionId":30786,"isInternetEnabled":true,"language":"python","sourceType":"notebook","isGpuEnabled":false}},"nbformat_minor":4,"nbformat":4,"cells":[{"cell_type":"markdown","source":"## Child Mind Institute — Problematic Internet Use: AutoML(LazyPredict)/ Xgboost_Model\r\n","metadata":{}},{"cell_type":"markdown","source":"## Objective\rObjective:\nThe goal of this analysis is to predict the level of problematic internet usage among children and adolescents using their physical activity and fitness data. By building a predictive model, we aim to identify early patterns that could help design interventions for promoting healthier digital habits.\n\n## Key Outcomes\n\n1. Develop a robust predictive model for identifying problematic internet usage.\n2. Explore the relationship between physical activity levels and internet use behaviors.\n3. Provide actionable insights to foster better digital and physical health practices.\n\n## Outline\n1. ## Introduction\nBrief description of the problem.\nImportance of addressing problematic internet usage in children and adolescents.\nRelevance of physical activity as a predictor.\n\n2. ## Data Loading and Inspection\nImporting libraries (e.g., pandas, numpy)\nLoading the dataset (train_child.csv)\nDisplaying initial rows of the dataset for review (train_data) , (test_data)\n\n3. ## Data Preprocessing\nHandle missing or inconsistent data.\nFeature engineering (e.g., creating meaningful metrics from raw activity data).\nNormalize or scale features if required.\n\n4. ## Model Development\nSplit data into training and testing subsets.\nBuild baseline models (e.g., linear regression, decision trees).\nExperiment with advanced machine learning models (e.g., random forests, gradient boosting, or neural networks).\n\n5. ## Model Evaluation\nUse appropriate metrics (e.g., RMSE, MAE, classification metrics like accuracy or F1 score) to evaluate model performance.\nCompare the performance of different models.\nPerform hyperparameter tuning to optimize the best-performing model.\n\n6. ## Exporting Results\nSave the final predictions to a CSV file (submission.csv).\nEnsure the output format aligns with the competition or project requirements.\n","metadata":{}},{"cell_type":"markdown","source":"## Data Loading and Inspection","metadata":{}},{"cell_type":"code","source":"import pandas as pd\nimport numpy as np\nimport warnings\nwarnings.filterwarnings('ignore')","metadata":{"id":"wQJrKsby71pQ","trusted":true,"execution":{"iopub.status.busy":"2024-11-22T02:47:03.825421Z","iopub.execute_input":"2024-11-22T02:47:03.825823Z","iopub.status.idle":"2024-11-22T02:47:04.269252Z","shell.execute_reply.started":"2024-11-22T02:47:03.825788Z","shell.execute_reply":"2024-11-22T02:47:04.268168Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"train_data=pd.read_csv('/kaggle/input/child-mind-institute-problematic-internet-use/train.csv')\ntrain_data","metadata":{"id":"hcPELhDOM9k2","outputId":"1c548cad-2064-4698-faa3-53679fc7367b","trusted":true,"execution":{"iopub.status.busy":"2024-11-22T02:47:06.234274Z","iopub.execute_input":"2024-11-22T02:47:06.234777Z","iopub.status.idle":"2024-11-22T02:47:06.359585Z","shell.execute_reply.started":"2024-11-22T02:47:06.234743Z","shell.execute_reply":"2024-11-22T02:47:06.358696Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"train_data.info()","metadata":{"id":"eKsfoK5P71Bi","outputId":"8577d2b2-3833-416e-b12a-45bce06f44b1","trusted":true,"execution":{"iopub.status.busy":"2024-11-22T02:47:08.314559Z","iopub.execute_input":"2024-11-22T02:47:08.315523Z","iopub.status.idle":"2024-11-22T02:47:08.347428Z","shell.execute_reply.started":"2024-11-22T02:47:08.315476Z","shell.execute_reply":"2024-11-22T02:47:08.346481Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"train_data.isna().sum()","metadata":{"id":"CKX_FzOb-I_s","outputId":"f88ac5ec-08a6-4712-e2aa-dc0412ba0f5d","trusted":true,"execution":{"iopub.status.busy":"2024-11-22T02:47:09.415641Z","iopub.execute_input":"2024-11-22T02:47:09.416620Z","iopub.status.idle":"2024-11-22T02:47:09.428192Z","shell.execute_reply.started":"2024-11-22T02:47:09.416561Z","shell.execute_reply":"2024-11-22T02:47:09.427186Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"cleaned_train_data = train_data.fillna(0)","metadata":{"id":"X7axGgy8-xAx","trusted":true,"execution":{"iopub.status.busy":"2024-11-22T02:47:13.051403Z","iopub.execute_input":"2024-11-22T02:47:13.051800Z","iopub.status.idle":"2024-11-22T02:47:13.062804Z","shell.execute_reply.started":"2024-11-22T02:47:13.051766Z","shell.execute_reply":"2024-11-22T02:47:13.061668Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"cleaned_train_data","metadata":{"id":"DplpOvQZ-Lic","outputId":"f2da1804-af61-4462-ce3e-b10d6fe55b22","trusted":true,"execution":{"iopub.status.busy":"2024-11-22T02:47:14.940905Z","iopub.execute_input":"2024-11-22T02:47:14.941629Z","iopub.status.idle":"2024-11-22T02:47:14.973176Z","shell.execute_reply.started":"2024-11-22T02:47:14.941574Z","shell.execute_reply":"2024-11-22T02:47:14.972203Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"test_data=pd.read_csv('/kaggle/input/child-mind-institute-problematic-internet-use/test.csv')\ntest_data","metadata":{"id":"TuRg6Qn1BOxG","outputId":"5ae46f3b-f233-4865-9f0b-60ae294010e0","trusted":true,"execution":{"iopub.status.busy":"2024-11-22T02:47:28.269660Z","iopub.execute_input":"2024-11-22T02:47:28.270035Z","iopub.status.idle":"2024-11-22T02:47:28.310657Z","shell.execute_reply.started":"2024-11-22T02:47:28.270000Z","shell.execute_reply":"2024-11-22T02:47:28.309693Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"test_data.info()","metadata":{"id":"j1cA43C_Bcm2","outputId":"4f169158-54f2-44e8-b598-892e54af3ec3","trusted":true,"execution":{"iopub.status.busy":"2024-11-22T02:47:29.780729Z","iopub.execute_input":"2024-11-22T02:47:29.781377Z","iopub.status.idle":"2024-11-22T02:47:29.794277Z","shell.execute_reply.started":"2024-11-22T02:47:29.781343Z","shell.execute_reply":"2024-11-22T02:47:29.793201Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"test_data.isna().sum()","metadata":{"id":"qdpgqC1DBgpK","outputId":"6a0bffcb-84e2-45d8-b449-03bb7be7c9d9","trusted":true,"execution":{"iopub.status.busy":"2024-11-22T02:47:30.626087Z","iopub.execute_input":"2024-11-22T02:47:30.626454Z","iopub.status.idle":"2024-11-22T02:47:30.635101Z","shell.execute_reply.started":"2024-11-22T02:47:30.626420Z","shell.execute_reply":"2024-11-22T02:47:30.634154Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"cleaned_test_data = test_data.fillna(0)","metadata":{"id":"K3jon1dbBndo","trusted":true,"execution":{"iopub.status.busy":"2024-11-22T02:47:31.472754Z","iopub.execute_input":"2024-11-22T02:47:31.473138Z","iopub.status.idle":"2024-11-22T02:47:31.478570Z","shell.execute_reply.started":"2024-11-22T02:47:31.473104Z","shell.execute_reply":"2024-11-22T02:47:31.477541Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"cleaned_test_data","metadata":{"id":"OwPWf6u0B73Q","outputId":"d65dc6e7-0e2f-4700-a5bd-72b4bccd1956","trusted":true,"execution":{"iopub.status.busy":"2024-11-22T02:47:32.658051Z","iopub.execute_input":"2024-11-22T02:47:32.658948Z","iopub.status.idle":"2024-11-22T02:47:32.691556Z","shell.execute_reply.started":"2024-11-22T02:47:32.658912Z","shell.execute_reply":"2024-11-22T02:47:32.690565Z"}},"outputs":[],"execution_count":null},{"cell_type":"markdown","source":"## Data Preprocessing","metadata":{}},{"cell_type":"code","source":"from sklearn.preprocessing import LabelEncoder\nmodel=LabelEncoder()\nmodel_train_data=cleaned_train_data.apply(lambda col: model.fit_transform(col.astype('str')))\nmodel_train_data","metadata":{"id":"NYpSKAjr0wnW","outputId":"522269a8-142c-42a4-95a9-35c0fe71fc60","trusted":true,"execution":{"iopub.status.busy":"2024-11-22T02:47:39.913406Z","iopub.execute_input":"2024-11-22T02:47:39.913756Z","iopub.status.idle":"2024-11-22T02:47:40.677412Z","shell.execute_reply.started":"2024-11-22T02:47:39.913726Z","shell.execute_reply":"2024-11-22T02:47:40.676386Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"model=LabelEncoder()\nmodel_test_data=cleaned_test_data.apply(lambda col: model.fit_transform(col.astype('str')))\nmodel_test_data","metadata":{"id":"aKKNQxACCGRi","outputId":"e32739a9-4dd3-4887-8a1b-8a6027704031","trusted":true,"execution":{"iopub.status.busy":"2024-11-22T02:47:41.347690Z","iopub.execute_input":"2024-11-22T02:47:41.348688Z","iopub.status.idle":"2024-11-22T02:47:41.385583Z","shell.execute_reply.started":"2024-11-22T02:47:41.348651Z","shell.execute_reply":"2024-11-22T02:47:41.384580Z"}},"outputs":[],"execution_count":null},{"cell_type":"markdown","source":" ## Model Development","metadata":{}},{"cell_type":"code","source":"x_train=model_train_data.drop(['sii'],axis=1)\ny_train=model_train_data['sii']","metadata":{"id":"LwgUv5B9Mm9d","trusted":true,"execution":{"iopub.status.busy":"2024-11-22T02:47:44.011688Z","iopub.execute_input":"2024-11-22T02:47:44.012449Z","iopub.status.idle":"2024-11-22T02:47:44.019272Z","shell.execute_reply.started":"2024-11-22T02:47:44.012415Z","shell.execute_reply":"2024-11-22T02:47:44.018370Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"missing_columns = set(x_train.columns) - set(model_test_data.columns)\n\n# Add missing columns with zero values\nfor col in missing_columns:\n    model_test_data[col] = 0  # Fill missing columns with zeros\n\n# Ensure the column order matches\nmodel_test_data = model_test_data[x_train.columns]\nmodel_test_data","metadata":{"id":"NEklGpVgPqfr","outputId":"cecf012a-c47f-4e2e-ba1c-652f276501e3","trusted":true,"execution":{"iopub.status.busy":"2024-11-22T02:47:45.933133Z","iopub.execute_input":"2024-11-22T02:47:45.933502Z","iopub.status.idle":"2024-11-22T02:47:45.964047Z","shell.execute_reply.started":"2024-11-22T02:47:45.933469Z","shell.execute_reply":"2024-11-22T02:47:45.962979Z"}},"outputs":[],"execution_count":null},{"cell_type":"markdown","source":"## Model Evaluation","metadata":{}},{"cell_type":"code","source":"from sklearn.model_selection import train_test_split\nx_train,x_test,y_train,y_test=train_test_split(x_train,y_train,test_size=0.2,random_state=42)\nfrom lazypredict.Supervised import LazyClassifier\nclf = LazyClassifier(verbose=0,ignore_warnings=True, custom_metric=None)\nmodels,predictions = clf.fit(x_train, x_test, y_train, y_test)\nprint(models)","metadata":{"id":"a2vK7CtGK7np","outputId":"593c0dba-39a5-45e4-9a5c-c62e7824ddbc","trusted":true,"execution":{"iopub.status.busy":"2024-11-22T02:48:54.417494Z","iopub.execute_input":"2024-11-22T02:48:54.418467Z","iopub.status.idle":"2024-11-22T02:49:11.845651Z","shell.execute_reply.started":"2024-11-22T02:48:54.418428Z","shell.execute_reply":"2024-11-22T02:49:11.843555Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"models.sort_values('Accuracy',ascending=False)","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2024-11-22T02:49:35.421466Z","iopub.execute_input":"2024-11-22T02:49:35.422143Z","iopub.status.idle":"2024-11-22T02:49:35.437582Z","shell.execute_reply.started":"2024-11-22T02:49:35.422104Z","shell.execute_reply":"2024-11-22T02:49:35.436506Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"from xgboost import XGBClassifier\nmodel=XGBClassifier()\nmodel.fit(x_train,y_train)","metadata":{"id":"4zou1ajzMcys","outputId":"24bf9dfc-ea96-4570-c35a-e25e19df52c9","trusted":true,"execution":{"iopub.status.busy":"2024-11-22T02:49:40.930472Z","iopub.execute_input":"2024-11-22T02:49:40.931443Z","iopub.status.idle":"2024-11-22T02:49:41.300163Z","shell.execute_reply.started":"2024-11-22T02:49:40.931402Z","shell.execute_reply":"2024-11-22T02:49:41.299211Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"model.score(x_train,y_train)","metadata":{"id":"-4DztfCc45YR","outputId":"c74b7806-b333-4c6a-cd87-b2912bc375d6","trusted":true,"execution":{"iopub.status.busy":"2024-11-22T02:49:46.385206Z","iopub.execute_input":"2024-11-22T02:49:46.385620Z","iopub.status.idle":"2024-11-22T02:49:46.411437Z","shell.execute_reply.started":"2024-11-22T02:49:46.385569Z","shell.execute_reply":"2024-11-22T02:49:46.410442Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"y_pred=model.predict(model_test_data)","metadata":{"id":"zVrIVpnbM9rL","trusted":true,"execution":{"iopub.status.busy":"2024-11-22T02:49:48.922147Z","iopub.execute_input":"2024-11-22T02:49:48.922533Z","iopub.status.idle":"2024-11-22T02:49:48.938291Z","shell.execute_reply.started":"2024-11-22T02:49:48.922497Z","shell.execute_reply":"2024-11-22T02:49:48.937273Z"}},"outputs":[],"execution_count":null},{"cell_type":"markdown","source":"## Exporting Results","metadata":{}},{"cell_type":"code","source":"result=output_df = pd.DataFrame({\n    'id': cleaned_test_data['id'],\n    'sii': y_pred\n})\nresult.to_csv('submission.csv', index=False)","metadata":{"id":"DuSyEqK7LSlO","trusted":true,"execution":{"iopub.status.busy":"2024-11-22T02:49:51.876084Z","iopub.execute_input":"2024-11-22T02:49:51.876467Z","iopub.status.idle":"2024-11-22T02:49:51.886445Z","shell.execute_reply.started":"2024-11-22T02:49:51.876432Z","shell.execute_reply":"2024-11-22T02:49:51.885419Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"result","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2024-11-22T02:50:35.229145Z","iopub.execute_input":"2024-11-22T02:50:35.229527Z","iopub.status.idle":"2024-11-22T02:50:35.241357Z","shell.execute_reply.started":"2024-11-22T02:50:35.229493Z","shell.execute_reply":"2024-11-22T02:50:35.240107Z"}},"outputs":[],"execution_count":null}]}