{"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":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","execution":{"iopub.status.busy":"2024-11-15T22:14:43.636582Z","iopub.execute_input":"2024-11-15T22:14:43.637069Z","iopub.status.idle":"2024-11-15T22:14:43.645981Z","shell.execute_reply.started":"2024-11-15T22:14:43.637024Z","shell.execute_reply":"2024-11-15T22:14:43.644823Z"},"trusted":true},"outputs":[],"execution_count":null},{"cell_type":"markdown","source":"# DATA LOADING AND INITIAL PREVIEW","metadata":{}},{"cell_type":"code","source":"data_test=pd.read_csv('/kaggle/input/child-mind-institute-problematic-internet-use/test.csv')","metadata":{"execution":{"iopub.status.busy":"2024-11-15T22:14:43.647949Z","iopub.execute_input":"2024-11-15T22:14:43.648315Z","iopub.status.idle":"2024-11-15T22:14:43.669465Z","shell.execute_reply.started":"2024-11-15T22:14:43.648276Z","shell.execute_reply":"2024-11-15T22:14:43.668130Z"},"trusted":true},"outputs":[],"execution_count":null},{"cell_type":"code","source":"#data_test","metadata":{"execution":{"iopub.status.busy":"2024-11-15T22:14:43.671687Z","iopub.execute_input":"2024-11-15T22:14:43.672186Z","iopub.status.idle":"2024-11-15T22:14:43.677351Z","shell.execute_reply.started":"2024-11-15T22:14:43.672142Z","shell.execute_reply":"2024-11-15T22:14:43.676243Z"},"trusted":true},"outputs":[],"execution_count":null},{"cell_type":"code","source":"data_train = pd.read_csv(\"/kaggle/input/child-mind-institute-problematic-internet-use/train.csv\")","metadata":{"execution":{"iopub.status.busy":"2024-11-15T22:14:43.678990Z","iopub.execute_input":"2024-11-15T22:14:43.679363Z","iopub.status.idle":"2024-11-15T22:14:43.740063Z","shell.execute_reply.started":"2024-11-15T22:14:43.679308Z","shell.execute_reply":"2024-11-15T22:14:43.738914Z"},"trusted":true},"outputs":[],"execution_count":null},{"cell_type":"code","source":"#data_train","metadata":{"execution":{"iopub.status.busy":"2024-11-15T22:14:43.742817Z","iopub.execute_input":"2024-11-15T22:14:43.743181Z","iopub.status.idle":"2024-11-15T22:14:43.747932Z","shell.execute_reply.started":"2024-11-15T22:14:43.743142Z","shell.execute_reply":"2024-11-15T22:14:43.746960Z"},"trusted":true},"outputs":[],"execution_count":null},{"cell_type":"code","source":"mean_usage_by_season = data_train.groupby(\"CGAS-Season\")[\"PreInt_EduHx-computerinternet_hoursday\"].mean().reset_index()","metadata":{"execution":{"iopub.status.busy":"2024-11-15T22:14:43.749354Z","iopub.execute_input":"2024-11-15T22:14:43.749794Z","iopub.status.idle":"2024-11-15T22:14:43.764836Z","shell.execute_reply.started":"2024-11-15T22:14:43.749731Z","shell.execute_reply":"2024-11-15T22:14:43.763597Z"},"trusted":true},"outputs":[],"execution_count":null},{"cell_type":"code","source":"mean_usage_by_season","metadata":{"execution":{"iopub.status.busy":"2024-11-15T22:14:43.766454Z","iopub.execute_input":"2024-11-15T22:14:43.767295Z","iopub.status.idle":"2024-11-15T22:14:43.780744Z","shell.execute_reply.started":"2024-11-15T22:14:43.767240Z","shell.execute_reply":"2024-11-15T22:14:43.779561Z"},"trusted":true},"outputs":[],"execution_count":null},{"cell_type":"code","source":"import matplotlib.pyplot as plt\nplt.figure(figsize=(8, 6))  # Set the figure size\nplt.plot(mean_usage_by_season[\"CGAS-Season\"], mean_usage_by_season[\"PreInt_EduHx-computerinternet_hoursday\"], marker='o', linestyle='-', color='b', label=\"Mean Internet Usage\")\n\n# Step 4: Add labels and title\nplt.title(\"Mean Internet Usage by Season\", fontsize=16)\nplt.xlabel(\"Season\", fontsize=14)\nplt.ylabel(\"Mean Internet Usage\", fontsize=14)\nplt.xticks(fontsize=12)\nplt.yticks(fontsize=12)","metadata":{"execution":{"iopub.status.busy":"2024-11-15T22:14:43.782453Z","iopub.execute_input":"2024-11-15T22:14:43.783275Z","iopub.status.idle":"2024-11-15T22:14:44.115079Z","shell.execute_reply.started":"2024-11-15T22:14:43.783233Z","shell.execute_reply":"2024-11-15T22:14:44.113892Z"},"trusted":true},"outputs":[],"execution_count":null},{"cell_type":"markdown","source":"We can see that Spring is the season where young people use internet the most. The usage of internet is the lowest in summer. Maybe this has something to do with a good weather and warm temperatures outside. Interesting thing is the low number of internet usage in the winter, because this is the season with the least outdoor activity.","metadata":{}},{"cell_type":"code","source":"use_by_bmi = data_train.groupby(\"Physical-BMI\")[\"PreInt_EduHx-computerinternet_hoursday\"].mean().reset_index()","metadata":{"execution":{"iopub.status.busy":"2024-11-15T22:14:44.116559Z","iopub.execute_input":"2024-11-15T22:14:44.116967Z","iopub.status.idle":"2024-11-15T22:14:44.125865Z","shell.execute_reply.started":"2024-11-15T22:14:44.116927Z","shell.execute_reply":"2024-11-15T22:14:44.124531Z"},"trusted":true},"outputs":[],"execution_count":null},{"cell_type":"code","source":"use_by_bmi","metadata":{"execution":{"iopub.status.busy":"2024-11-15T22:14:44.127661Z","iopub.execute_input":"2024-11-15T22:14:44.128116Z","iopub.status.idle":"2024-11-15T22:14:44.142585Z","shell.execute_reply.started":"2024-11-15T22:14:44.128056Z","shell.execute_reply":"2024-11-15T22:14:44.141260Z"},"trusted":true},"outputs":[],"execution_count":null},{"cell_type":"code","source":"import matplotlib.pyplot as plt\nplt.figure(figsize=(8, 6))  # Set the figure size\nplt.plot(use_by_bmi[\"Physical-BMI\"], use_by_bmi[\"PreInt_EduHx-computerinternet_hoursday\"], marker='o', linestyle='-', color='b', label=\"Mean Internet Usage\")\n\n# Step 4: Add labels and title\nplt.title(\"Mean Internet Usage by BMI\", fontsize=16)\nplt.xlabel(\"Season\", fontsize=14)\nplt.ylabel(\"Mean Internet Usage\", fontsize=14)\nplt.xticks(fontsize=12)\nplt.yticks(fontsize=12)","metadata":{"execution":{"iopub.status.busy":"2024-11-15T22:14:44.147312Z","iopub.execute_input":"2024-11-15T22:14:44.148374Z","iopub.status.idle":"2024-11-15T22:14:44.624183Z","shell.execute_reply.started":"2024-11-15T22:14:44.148314Z","shell.execute_reply":"2024-11-15T22:14:44.622822Z"},"trusted":true},"outputs":[],"execution_count":null},{"cell_type":"markdown","source":"Usage of BMI does not provide sucessfull results we need to set BMI to intervals instead of providing the data for every single BMI ","metadata":{}},{"cell_type":"code","source":"use_by_age = data_train.groupby(\"Basic_Demos-Age\")[\"PreInt_EduHx-computerinternet_hoursday\"].mean().reset_index()","metadata":{"execution":{"iopub.status.busy":"2024-11-15T22:14:44.625873Z","iopub.execute_input":"2024-11-15T22:14:44.626344Z","iopub.status.idle":"2024-11-15T22:14:44.636143Z","shell.execute_reply.started":"2024-11-15T22:14:44.626288Z","shell.execute_reply":"2024-11-15T22:14:44.634882Z"},"trusted":true},"outputs":[],"execution_count":null},{"cell_type":"code","source":"import matplotlib.pyplot as plt\nplt.figure(figsize=(8, 6))  # Set the figure size\nplt.plot(use_by_age[\"Basic_Demos-Age\"], use_by_age[\"PreInt_EduHx-computerinternet_hoursday\"], marker='o', linestyle='-', color='b', label=\"Mean Internet Usage\")\n\n# Step 4: Add labels and title\nplt.title(\"Mean Internet Usage by Age\", fontsize=16)\nplt.xlabel(\"Season\", fontsize=14)\nplt.ylabel(\"Mean Internet Usage\", fontsize=14)\nplt.xticks(fontsize=12)\nplt.yticks(fontsize=12)","metadata":{"execution":{"iopub.status.busy":"2024-11-15T22:14:44.638104Z","iopub.execute_input":"2024-11-15T22:14:44.638937Z","iopub.status.idle":"2024-11-15T22:14:45.002608Z","shell.execute_reply.started":"2024-11-15T22:14:44.638879Z","shell.execute_reply":"2024-11-15T22:14:45.001453Z"},"trusted":true},"outputs":[],"execution_count":null},{"cell_type":"markdown","source":"When grouping by age we get a readable graph where we can see that with age also the time of usage internet drastically increases","metadata":{}},{"cell_type":"code","source":"use_by_age_season = data_train.groupby([\"Basic_Demos-Age\",\"CGAS-Season\"])[\"PreInt_EduHx-computerinternet_hoursday\"].mean().reset_index()","metadata":{"execution":{"iopub.status.busy":"2024-11-15T22:14:45.005333Z","iopub.execute_input":"2024-11-15T22:14:45.005739Z","iopub.status.idle":"2024-11-15T22:14:45.015268Z","shell.execute_reply.started":"2024-11-15T22:14:45.005698Z","shell.execute_reply":"2024-11-15T22:14:45.014208Z"},"trusted":true},"outputs":[],"execution_count":null},{"cell_type":"code","source":"plt.figure(figsize=(10, 6))  # Set the figure size\nseasons = use_by_age_season[\"CGAS-Season\"].unique()\n\n# Loop through each season and plot bars for each age group\nfor i, season in enumerate(seasons):\n    subset = use_by_age_season[use_by_age_season[\"CGAS-Season\"] == season]\n    plt.bar(\n        subset[\"Basic_Demos-Age\"] + i * 0.20,  # Offset each season slightly\n        subset[\"PreInt_EduHx-computerinternet_hoursday\"],\n        width=0.20,\n        label=season\n    )\n\n# Step 4: Add labels, title, and legend\nplt.title(\"Mean Internet Usage by Age and Season\", fontsize=16)\nplt.xlabel(\"Age\", fontsize=14)\nplt.ylabel(\"Mean Internet Usage\", fontsize=14)\nplt.xticks(ticks=use_by_age_season[\"Basic_Demos-Age\"].unique())\nplt.legend(title=\"Season\")\nplt.grid(axis=\"y\", linestyle=\"--\", alpha=0.7)\n\n# Step 5: Display the plot\nplt.show()","metadata":{"execution":{"iopub.status.busy":"2024-11-15T22:17:28.878307Z","iopub.execute_input":"2024-11-15T22:17:28.879139Z","iopub.status.idle":"2024-11-15T22:17:29.444780Z","shell.execute_reply.started":"2024-11-15T22:17:28.879093Z","shell.execute_reply":"2024-11-15T22:17:29.443784Z"},"trusted":true},"outputs":[],"execution_count":null},{"cell_type":"markdown","source":"Here is an interesting graph represnting usage grouped by age for each season.","metadata":{}},{"cell_type":"code","source":"use_by_age","metadata":{"execution":{"iopub.status.busy":"2024-11-15T22:14:45.531917Z","iopub.execute_input":"2024-11-15T22:14:45.532397Z","iopub.status.idle":"2024-11-15T22:14:45.546210Z","shell.execute_reply.started":"2024-11-15T22:14:45.532339Z","shell.execute_reply":"2024-11-15T22:14:45.545045Z"},"trusted":true},"outputs":[],"execution_count":null},{"cell_type":"code","source":"use_by_gender = data_train.groupby(\"Basic_Demos-Sex\")[\"PreInt_EduHx-computerinternet_hoursday\"].mean().reset_index()","metadata":{"execution":{"iopub.status.busy":"2024-11-15T22:14:45.547476Z","iopub.execute_input":"2024-11-15T22:14:45.547886Z","iopub.status.idle":"2024-11-15T22:14:45.556719Z","shell.execute_reply.started":"2024-11-15T22:14:45.547840Z","shell.execute_reply":"2024-11-15T22:14:45.555713Z"},"trusted":true},"outputs":[],"execution_count":null},{"cell_type":"code","source":"use_by_gender","metadata":{"execution":{"iopub.status.busy":"2024-11-15T22:14:45.558308Z","iopub.execute_input":"2024-11-15T22:14:45.559392Z","iopub.status.idle":"2024-11-15T22:14:45.576199Z","shell.execute_reply.started":"2024-11-15T22:14:45.559335Z","shell.execute_reply":"2024-11-15T22:14:45.575035Z"},"trusted":true},"outputs":[],"execution_count":null},{"cell_type":"code","source":"import matplotlib.pyplot as plt\nplt.figure(figsize=(8, 6))  # Set the figure size\nplt.bar(use_by_gender[\"Basic_Demos-Sex\"], use_by_gender[\"PreInt_EduHx-computerinternet_hoursday\"], color=['blue', 'purple'])\n\n# Step 4: Add labels and title\nplt.title(\"Mean Internet Usage by Gender\", fontsize=16)\nplt.xlabel(\"Season\", fontsize=14)\nplt.ylabel(\"Mean Internet Usage\", fontsize=14)\nplt.ylim(min(use_by_gender[\"PreInt_EduHx-computerinternet_hoursday\"][0],use_by_gender[\"PreInt_EduHx-computerinternet_hoursday\"][1])-0.003, max(use_by_gender[\"PreInt_EduHx-computerinternet_hoursday\"][0],use_by_gender[\"PreInt_EduHx-computerinternet_hoursday\"][1])+0.003)\nplt.xticks(fontsize=12)\nplt.yticks(fontsize=12)","metadata":{"execution":{"iopub.status.busy":"2024-11-15T22:14:45.578123Z","iopub.execute_input":"2024-11-15T22:14:45.578596Z","iopub.status.idle":"2024-11-15T22:14:45.897033Z","shell.execute_reply.started":"2024-11-15T22:14:45.578551Z","shell.execute_reply":"2024-11-15T22:14:45.895926Z"},"trusted":true},"outputs":[],"execution_count":null}]}