{"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":"markdown","source":"# Some Graphs to Understand the Problematic Interner Use Dataset.\n\nHello again, Kaggle comunity! This time, I want to practice my skills in creating graphs. I have tried to create some that can be useful in our notebook or data research. If you have any suggestion for me, you are welcome! 🥳","metadata":{}},{"cell_type":"markdown","source":"# What I Understand from This Dataset\n\nThis dataset contains information of various atributes related to individuals.\n\n**To Summarize**\n\n1. Demographics\n2. Children's Global Assessment Scale\n3. Physical Measures\n4. FitnessGram Vitals and Treadmill\n5. FitnessGram Child\n6. Bio-electric Impedance Analysis\n7. Physical Activity Questionnaire\n8. Parent-Child Internet Addiction Test\n9. Sleep Disturbance Scale\n10. Internet Use\n\nUsing the Parent-Child Internet Addiction Test, we can calculate a metric to measure the impact of internet use. The metric ranges from 0 to 100, categorized as follows: (0-30 -> none, 31-49 -> mild, 50-79 -> moderate, 80-100 -> severe). This metric is called the Severity Impairment Index (SII), which is the target feature we want to predict in the competition.","metadata":{}},{"cell_type":"markdown","source":"# Load the data.","metadata":{}},{"cell_type":"code","source":"import pandas as pd\nimport warnings\nwarnings.filterwarnings(\"ignore\")","metadata":{"execution":{"iopub.status.busy":"2024-10-28T05:03:32.227392Z","iopub.execute_input":"2024-10-28T05:03:32.228217Z","iopub.status.idle":"2024-10-28T05:03:32.233430Z","shell.execute_reply.started":"2024-10-28T05:03:32.228165Z","shell.execute_reply":"2024-10-28T05:03:32.232139Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"train = pd.read_csv('/kaggle/input/child-mind-institute-problematic-internet-use/train.csv')\ntrain.head(5)","metadata":{"execution":{"iopub.status.busy":"2024-10-28T05:03:34.961350Z","iopub.execute_input":"2024-10-28T05:03:34.962417Z","iopub.status.idle":"2024-10-28T05:03:35.044902Z","shell.execute_reply.started":"2024-10-28T05:03:34.962369Z","shell.execute_reply":"2024-10-28T05:03:35.043632Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"test = pd.read_csv('/kaggle/input/child-mind-institute-problematic-internet-use/test.csv')\ntest.head(5)","metadata":{"execution":{"iopub.status.busy":"2024-10-28T05:03:36.947061Z","iopub.execute_input":"2024-10-28T05:03:36.947913Z","iopub.status.idle":"2024-10-28T05:03:36.982276Z","shell.execute_reply.started":"2024-10-28T05:03:36.947866Z","shell.execute_reply":"2024-10-28T05:03:36.981147Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"Parent_Child_Internet_Addiction_Test =  train[['PCIAT-PCIAT_01', 'PCIAT-PCIAT_02', 'PCIAT-PCIAT_03',\n    'PCIAT-PCIAT_04', 'PCIAT-PCIAT_05', 'PCIAT-PCIAT_06', 'PCIAT-PCIAT_07',\n    'PCIAT-PCIAT_08', 'PCIAT-PCIAT_09', 'PCIAT-PCIAT_10', 'PCIAT-PCIAT_11',\n    'PCIAT-PCIAT_12', 'PCIAT-PCIAT_13', 'PCIAT-PCIAT_14', 'PCIAT-PCIAT_15',\n    'PCIAT-PCIAT_16', 'PCIAT-PCIAT_17', 'PCIAT-PCIAT_18', 'PCIAT-PCIAT_19',\n    'PCIAT-PCIAT_20']]","metadata":{"execution":{"iopub.status.busy":"2024-10-28T05:03:58.978385Z","iopub.execute_input":"2024-10-28T05:03:58.978844Z","iopub.status.idle":"2024-10-28T05:03:58.986702Z","shell.execute_reply.started":"2024-10-28T05:03:58.978795Z","shell.execute_reply":"2024-10-28T05:03:58.985387Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"Parent_Child_Internet_Addiction_Test","metadata":{"execution":{"iopub.status.busy":"2024-10-28T05:04:01.525895Z","iopub.execute_input":"2024-10-28T05:04:01.526329Z","iopub.status.idle":"2024-10-28T05:04:01.574570Z","shell.execute_reply.started":"2024-10-28T05:04:01.526285Z","shell.execute_reply":"2024-10-28T05:04:01.573328Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"import pandas as pd\n\n# Crear una lista de categorías posibles\ncategorias = [0,1,2,3,4,5]\n\n# Inicializar un DataFrame vacío para almacenar los resultados\nresultados = pd.DataFrame(columns=Parent_Child_Internet_Addiction_Test.columns, index=categorias).fillna(0)\n\n# Recorrer cada columna (pregunta) y contar las respuestas\nfor columna in Parent_Child_Internet_Addiction_Test.columns:\n    conteo = Parent_Child_Internet_Addiction_Test[columna].value_counts()\n    resultados[columna].update(conteo)\n\n# Reemplazar NaN por 0 en caso de que alguna categoría no esté presente en alguna pregunta\nresultados = resultados.fillna(0).astype(int)\n\n# Mostrar el DataFrame de resultados\nresultados\n","metadata":{"execution":{"iopub.status.busy":"2024-10-28T05:19:47.487060Z","iopub.execute_input":"2024-10-28T05:19:47.487496Z","iopub.status.idle":"2024-10-28T05:19:47.538889Z","shell.execute_reply.started":"2024-10-28T05:19:47.487451Z","shell.execute_reply":"2024-10-28T05:19:47.537824Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"# A little rename","metadata":{}},{"cell_type":"code","source":"# Renombrar las columnas a los nombres que proporcionaste\nnuevos_nombres_columnas = {\n    'PCIAT-PCIAT_01':'Q1', 'PCIAT-PCIAT_02':'Q2',  'PCIAT-PCIAT_03':'Q3',  'PCIAT-PCIAT_04':'Q4',\n    'PCIAT-PCIAT_05':'Q5', 'PCIAT-PCIAT_06':'Q6',  'PCIAT-PCIAT_07':'Q7',  'PCIAT-PCIAT_08':'Q8',\n    'PCIAT-PCIAT_09':'Q9',  'PCIAT-PCIAT_10':'Q10',  'PCIAT-PCIAT_11':'Q11',  'PCIAT-PCIAT_12':'Q12',\n    'PCIAT-PCIAT_13':'Q13',  'PCIAT-PCIAT_14':'Q14',  'PCIAT-PCIAT_15':'Q15',  'PCIAT-PCIAT_16':'Q16',\n    'PCIAT-PCIAT_17':'Q17',  'PCIAT-PCIAT_18':'Q18',  'PCIAT-PCIAT_19':'Q19',  'PCIAT-PCIAT_20':'Q20'\n}\n\nresultados.rename(columns=nuevos_nombres_columnas, inplace=True)\n\n# Renombrar las filas a índices numéricos (0, 1, 2, 3, 4, 5) en el orden deseado\nnuevos_nombres_filas = {\n    0: 'Does Not Apply',\n    1: 'Rarely',\n    2: 'Occasionally', \n    3: 'Frequently', \n    4: 'Often', \n    5: 'Always' \n}\n\nresultados.rename(index=nuevos_nombres_filas, inplace= True)\n\n# Mostrar el DataFrame actualizado\nresultados\n","metadata":{"execution":{"iopub.status.busy":"2024-10-28T05:19:49.738286Z","iopub.execute_input":"2024-10-28T05:19:49.738719Z","iopub.status.idle":"2024-10-28T05:19:49.766825Z","shell.execute_reply.started":"2024-10-28T05:19:49.738673Z","shell.execute_reply":"2024-10-28T05:19:49.765572Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"import seaborn as sns\nimport matplotlib.pyplot as plt","metadata":{"execution":{"iopub.status.busy":"2024-10-28T05:22:54.459234Z","iopub.execute_input":"2024-10-28T05:22:54.459687Z","iopub.status.idle":"2024-10-28T05:22:54.464968Z","shell.execute_reply.started":"2024-10-28T05:22:54.459637Z","shell.execute_reply":"2024-10-28T05:22:54.463649Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"plt.figure(figsize=(12,4))\nsns.heatmap(data=resultados,annot=True,fmt='g')","metadata":{"execution":{"iopub.status.busy":"2024-10-28T05:25:33.932699Z","iopub.execute_input":"2024-10-28T05:25:33.933118Z","iopub.status.idle":"2024-10-28T05:25:34.769254Z","shell.execute_reply.started":"2024-10-28T05:25:33.933077Z","shell.execute_reply":"2024-10-28T05:25:34.768073Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"In this heatmap, we can identify specific questions that provide insights:\n\n**Not common symptoms**\n\n1. Q4 - How often does your child form new relationships with fellow online users?\n2. Q6 - How often do your child's grades suffer because of the amount of time he or she spends online?\n3. Q7 - How often does your child check his or her e-mail before doing something else?\n4. Q9 - How often does your child become defensive or secretive when asked what he or she does online?\n5. Q12 - How often does your child receive strange phone calls from new \"online\" friends?\n6. Q14 - How often does your child seem more tired and fatigued than he or she did before the Internet came along?\n7. Q19 - How often does your child choose to spend more time online than going out with friends?\n8. Q20 - PCIAT-PCIAT_20\tHow often does your child feel depressed, moody, or nervous when off-line which seems to go away once back online?\n\n**Common symptoms**\n\n1. Q1 - How often does your child disobey time limits you set for online use?\n2. Q2 - How often does your child neglect household chores to spend more time online?\n3. Q3 - How often does your child prefer to spend time online rather than with the rest of your family?\n4. Q5 - How often do you complain about the amount of time your child spends online?\n5. Q17 - How often does your child choose to spend time online rather than doing once enjoyed hobbies and/or outside interests?\n6. Q18 - How often does your child become angry or belligerent when your place time limits on how much time he or shes is allowed to spend online?\n","metadata":{}},{"cell_type":"markdown","source":"# Distribution of SII","metadata":{}},{"cell_type":"code","source":"Parent_Child_Internet_Addiction_Test = train[['PCIAT-PCIAT_Total']]","metadata":{"execution":{"iopub.status.busy":"2024-10-28T05:54:06.403729Z","iopub.execute_input":"2024-10-28T05:54:06.405511Z","iopub.status.idle":"2024-10-28T05:54:06.414293Z","shell.execute_reply.started":"2024-10-28T05:54:06.405456Z","shell.execute_reply":"2024-10-28T05:54:06.412852Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"import pandas as pd\n\n# Supongamos que tienes un DataFrame llamado 'Parent_Child_Internet_Addiction_Test'\n# que contiene los datos de la encuesta.\n\n# Aplanar todas las respuestas en una sola serie\nrespuestas = Parent_Child_Internet_Addiction_Test.values.flatten()\n\n# Crear un DataFrame que cuente la frecuencia de cada puntaje\nconteo_puntaje = pd.Series(respuestas).value_counts().sort_index()\n\n# Convertirlo en un DataFrame con las columnas \"Puntaje\" y \"Recuento\"\nresultados = pd.DataFrame({'Pts': conteo_puntaje.index, 'Count': conteo_puntaje.values})\n\n# Remover un valor atipico \nresultados.drop(resultados[resultados['Pts'] == 0].index, inplace=True)\n\n# Mostrar el DataFrame resultante\nresultados","metadata":{"execution":{"iopub.status.busy":"2024-10-28T06:00:56.106939Z","iopub.execute_input":"2024-10-28T06:00:56.107363Z","iopub.status.idle":"2024-10-28T06:00:56.127837Z","shell.execute_reply.started":"2024-10-28T06:00:56.107323Z","shell.execute_reply":"2024-10-28T06:00:56.126664Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"plt.title(\"Distribution of SII\")\nsns.scatterplot(x='Pts',y='Count',data=resultados)","metadata":{"execution":{"iopub.status.busy":"2024-10-28T06:01:44.292701Z","iopub.execute_input":"2024-10-28T06:01:44.293173Z","iopub.status.idle":"2024-10-28T06:01:44.648950Z","shell.execute_reply.started":"2024-10-28T06:01:44.293127Z","shell.execute_reply":"2024-10-28T06:01:44.647751Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"This indicates that the majority of people in this test do not have a 'severe' diagnosis. Most are classified as 'moderate' or less.","metadata":{}}]}