{"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":"import pandas as pd\nimport seaborn as sns\nimport matplotlib.pyplot as plt","metadata":{"execution":{"iopub.status.busy":"2024-10-21T14:36:24.192481Z","iopub.execute_input":"2024-10-21T14:36:24.193037Z","iopub.status.idle":"2024-10-21T14:36:24.199100Z","shell.execute_reply.started":"2024-10-21T14:36:24.192984Z","shell.execute_reply":"2024-10-21T14:36:24.197771Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df=pd.read_csv('/kaggle/input/child-mind-institute-problematic-internet-use/train.csv')","metadata":{"execution":{"iopub.status.busy":"2024-10-21T14:37:44.658091Z","iopub.execute_input":"2024-10-21T14:37:44.659202Z","iopub.status.idle":"2024-10-21T14:37:44.722767Z","shell.execute_reply.started":"2024-10-21T14:37:44.659142Z","shell.execute_reply":"2024-10-21T14:37:44.721460Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df.head()","metadata":{"execution":{"iopub.status.busy":"2024-10-21T14:36:24.263630Z","iopub.execute_input":"2024-10-21T14:36:24.264097Z","iopub.status.idle":"2024-10-21T14:36:24.293275Z","shell.execute_reply.started":"2024-10-21T14:36:24.264046Z","shell.execute_reply":"2024-10-21T14:36:24.291809Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df.columns","metadata":{"execution":{"iopub.status.busy":"2024-10-21T14:36:24.296077Z","iopub.execute_input":"2024-10-21T14:36:24.296466Z","iopub.status.idle":"2024-10-21T14:36:24.307030Z","shell.execute_reply.started":"2024-10-21T14:36:24.296428Z","shell.execute_reply":"2024-10-21T14:36:24.305793Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df.info()","metadata":{"execution":{"iopub.status.busy":"2024-10-21T14:36:24.308553Z","iopub.execute_input":"2024-10-21T14:36:24.308939Z","iopub.status.idle":"2024-10-21T14:36:24.338177Z","shell.execute_reply.started":"2024-10-21T14:36:24.308901Z","shell.execute_reply":"2024-10-21T14:36:24.336869Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df.describe","metadata":{"execution":{"iopub.status.busy":"2024-10-21T14:36:24.339474Z","iopub.execute_input":"2024-10-21T14:36:24.339902Z","iopub.status.idle":"2024-10-21T14:36:24.363930Z","shell.execute_reply.started":"2024-10-21T14:36:24.339861Z","shell.execute_reply":"2024-10-21T14:36:24.362810Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"col=df.columns","metadata":{"execution":{"iopub.status.busy":"2024-10-21T14:36:24.365895Z","iopub.execute_input":"2024-10-21T14:36:24.366265Z","iopub.status.idle":"2024-10-21T14:36:24.371065Z","shell.execute_reply.started":"2024-10-21T14:36:24.366227Z","shell.execute_reply":"2024-10-21T14:36:24.369747Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"num_cols = df._get_numeric_data().columns","metadata":{"execution":{"iopub.status.busy":"2024-10-21T14:36:24.372688Z","iopub.execute_input":"2024-10-21T14:36:24.373074Z","iopub.status.idle":"2024-10-21T14:36:24.383934Z","shell.execute_reply.started":"2024-10-21T14:36:24.373036Z","shell.execute_reply":"2024-10-21T14:36:24.382766Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"num_cols","metadata":{"execution":{"iopub.status.busy":"2024-10-21T14:36:24.386882Z","iopub.execute_input":"2024-10-21T14:36:24.387285Z","iopub.status.idle":"2024-10-21T14:36:24.397935Z","shell.execute_reply.started":"2024-10-21T14:36:24.387238Z","shell.execute_reply":"2024-10-21T14:36:24.396816Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"num_cols.shape","metadata":{"execution":{"iopub.status.busy":"2024-10-21T14:36:24.399768Z","iopub.execute_input":"2024-10-21T14:36:24.400204Z","iopub.status.idle":"2024-10-21T14:36:24.409927Z","shell.execute_reply.started":"2024-10-21T14:36:24.400165Z","shell.execute_reply":"2024-10-21T14:36:24.408757Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df['Basic_Demos-Sex'].head()","metadata":{"execution":{"iopub.status.busy":"2024-10-21T14:36:24.411249Z","iopub.execute_input":"2024-10-21T14:36:24.411602Z","iopub.status.idle":"2024-10-21T14:36:24.424187Z","shell.execute_reply.started":"2024-10-21T14:36:24.411561Z","shell.execute_reply":"2024-10-21T14:36:24.422815Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"for x in num_cols:\n    print(x)\n    print('Mean:', df[x].mean())\n    print('Median:', df[x].median())\n    print('Mode:', df[x].mode())\n    print(\"\\n\")\n    print(\"----------------------------------\")\n","metadata":{"execution":{"iopub.status.busy":"2024-10-21T14:36:24.425964Z","iopub.execute_input":"2024-10-21T14:36:24.426507Z","iopub.status.idle":"2024-10-21T14:36:24.513861Z","shell.execute_reply.started":"2024-10-21T14:36:24.426455Z","shell.execute_reply":"2024-10-21T14:36:24.512781Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"for x in num_cols:\n    plt.figure(figsize=(8, 4))  \n    sns.boxplot(data=df, x=x)   \n    plt.title(f'Boxplot of {x}')\n    plt.show()                  ","metadata":{"execution":{"iopub.status.busy":"2024-10-21T14:36:24.515099Z","iopub.execute_input":"2024-10-21T14:36:24.515427Z","iopub.status.idle":"2024-10-21T14:36:34.545513Z","shell.execute_reply.started":"2024-10-21T14:36:24.515391Z","shell.execute_reply":"2024-10-21T14:36:34.544216Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df.drop(['id', 'Basic_Demos-Enroll_Season', 'CGAS-Season', 'Physical-Season', 'Fitness_Endurance-Season', 'FGC-Season', 'BIA-Season'], axis=1, inplace=True)\n","metadata":{"execution":{"iopub.status.busy":"2024-10-21T14:37:56.176850Z","iopub.execute_input":"2024-10-21T14:37:56.177946Z","iopub.status.idle":"2024-10-21T14:37:56.185889Z","shell.execute_reply.started":"2024-10-21T14:37:56.177892Z","shell.execute_reply":"2024-10-21T14:37:56.184706Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df.shape","metadata":{"execution":{"iopub.status.busy":"2024-10-21T14:38:02.201318Z","iopub.execute_input":"2024-10-21T14:38:02.202417Z","iopub.status.idle":"2024-10-21T14:38:02.209921Z","shell.execute_reply.started":"2024-10-21T14:38:02.202354Z","shell.execute_reply":"2024-10-21T14:38:02.208799Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df.head()","metadata":{"execution":{"iopub.status.busy":"2024-10-21T14:38:17.482960Z","iopub.execute_input":"2024-10-21T14:38:17.483427Z","iopub.status.idle":"2024-10-21T14:38:17.513944Z","shell.execute_reply.started":"2024-10-21T14:38:17.483368Z","shell.execute_reply":"2024-10-21T14:38:17.512477Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df.drop(['PreInt_EduHx-Season'],axis=1,inplace=True)","metadata":{"execution":{"iopub.status.busy":"2024-10-21T14:38:50.345642Z","iopub.execute_input":"2024-10-21T14:38:50.346079Z","iopub.status.idle":"2024-10-21T14:38:50.354057Z","shell.execute_reply.started":"2024-10-21T14:38:50.346039Z","shell.execute_reply":"2024-10-21T14:38:50.352424Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df.head()","metadata":{"execution":{"iopub.status.busy":"2024-10-21T14:38:56.292876Z","iopub.execute_input":"2024-10-21T14:38:56.294191Z","iopub.status.idle":"2024-10-21T14:38:56.327013Z","shell.execute_reply.started":"2024-10-21T14:38:56.294128Z","shell.execute_reply":"2024-10-21T14:38:56.325526Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df.drop(['SDS-Season'],axis=1,inplace=True)","metadata":{"execution":{"iopub.status.busy":"2024-10-21T14:40:17.440766Z","iopub.execute_input":"2024-10-21T14:40:17.441853Z","iopub.status.idle":"2024-10-21T14:40:17.448293Z","shell.execute_reply.started":"2024-10-21T14:40:17.441801Z","shell.execute_reply":"2024-10-21T14:40:17.447079Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df.head()","metadata":{"execution":{"iopub.status.busy":"2024-10-21T14:40:25.262902Z","iopub.execute_input":"2024-10-21T14:40:25.264020Z","iopub.status.idle":"2024-10-21T14:40:25.305231Z","shell.execute_reply.started":"2024-10-21T14:40:25.263955Z","shell.execute_reply":"2024-10-21T14:40:25.303923Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# Sum of null and NaN values in each column\nnull_values_per_column = df.isnull().sum()\nnull_values_per_column.head(10)\n","metadata":{"execution":{"iopub.status.busy":"2024-10-21T15:00:18.578872Z","iopub.execute_input":"2024-10-21T15:00:18.579390Z","iopub.status.idle":"2024-10-21T15:00:18.593948Z","shell.execute_reply.started":"2024-10-21T15:00:18.579343Z","shell.execute_reply":"2024-10-21T15:00:18.592316Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df.dtypes","metadata":{"execution":{"iopub.status.busy":"2024-10-21T15:06:31.561128Z","iopub.execute_input":"2024-10-21T15:06:31.561592Z","iopub.status.idle":"2024-10-21T15:06:31.571484Z","shell.execute_reply.started":"2024-10-21T15:06:31.561548Z","shell.execute_reply":"2024-10-21T15:06:31.570221Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# Select only non-numerical columns\nnon_numerical_columns = df.select_dtypes(exclude=['number'])\n\nprint(non_numerical_columns.dtypes)\n","metadata":{"execution":{"iopub.status.busy":"2024-10-21T15:07:16.036102Z","iopub.execute_input":"2024-10-21T15:07:16.036535Z","iopub.status.idle":"2024-10-21T15:07:16.045918Z","shell.execute_reply.started":"2024-10-21T15:07:16.036492Z","shell.execute_reply":"2024-10-21T15:07:16.044460Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df.drop(['PAQ_A-Season','PAQ_C-Season','PCIAT-Season'],axis=1,inplace=True)","metadata":{"execution":{"iopub.status.busy":"2024-10-21T15:08:14.664038Z","iopub.execute_input":"2024-10-21T15:08:14.664476Z","iopub.status.idle":"2024-10-21T15:08:14.671815Z","shell.execute_reply.started":"2024-10-21T15:08:14.664434Z","shell.execute_reply":"2024-10-21T15:08:14.670458Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# Replace NaN values with the mean of each column\ndf.fillna(df.mean(), inplace=True)","metadata":{"execution":{"iopub.status.busy":"2024-10-21T15:08:24.352107Z","iopub.execute_input":"2024-10-21T15:08:24.352530Z","iopub.status.idle":"2024-10-21T15:08:24.393316Z","shell.execute_reply.started":"2024-10-21T15:08:24.352490Z","shell.execute_reply":"2024-10-21T15:08:24.392019Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# Sum of null and NaN values in each column\nnull_values_per_column = df.isnull().sum()\nnull_values_per_column.tail(20)\n","metadata":{"execution":{"iopub.status.busy":"2024-10-21T15:10:56.765760Z","iopub.execute_input":"2024-10-21T15:10:56.766927Z","iopub.status.idle":"2024-10-21T15:10:56.778838Z","shell.execute_reply.started":"2024-10-21T15:10:56.766866Z","shell.execute_reply":"2024-10-21T15:10:56.777654Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"for x in df.columns:\n    plt.figure(figsize=(8, 4))  \n    sns.boxplot(data=df, x=x)   \n    plt.title(f'Boxplot of {x}')\n    plt.show()                  ","metadata":{"execution":{"iopub.status.busy":"2024-10-21T15:16:41.765734Z","iopub.execute_input":"2024-10-21T15:16:41.766200Z","iopub.status.idle":"2024-10-21T15:16:51.421624Z","shell.execute_reply.started":"2024-10-21T15:16:41.766151Z","shell.execute_reply":"2024-10-21T15:16:51.420353Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"def remove_outliers(df, columns):\n    for column in columns:\n        # Calculate Q1 (25th percentile) and Q3 (75th percentile)\n        Q1 = df[column].quantile(0.25)\n        Q3 = df[column].quantile(0.75)\n\n        IQR = Q3 - Q1\n\n        lower_bound = Q1 - 1.5 * IQR\n        upper_bound = Q3 + 1.5 * IQR\n\n        df = df[(df[column] >= lower_bound) & (df[column] <= upper_bound)]\n    \n    return df\n\ncolumns_to_check = [\n    'Basic_Demos-Age',\n    'FGC-FGC_PU_Zone', 'FGC-FGC_SRL_Zone', 'FGC-FGC_SRR_Zone', 'FGC-FGC_TL_Zone',\n    'BIA-BIA_Activity_Level_num', 'BIA-BIA_Frame_num',\n    'PCIAT-PCIAT_01', 'PCIAT-PCIAT_03', 'PCIAT-PCIAT_04', 'PCIAT-PCIAT_05',\n    'PCIAT-PCIAT_06', 'PCIAT-PCIAT_07', 'PCIAT-PCIAT_08', 'PCIAT-PCIAT_09',\n    'PCIAT-PCIAT_10', 'PCIAT-PCIAT_11', 'PCIAT-PCIAT_12', 'PCIAT-PCIAT_14',\n    'PCIAT-PCIAT_15', 'PCIAT-PCIAT_16', 'PCIAT-PCIAT_17', 'PCIAT-PCIAT_18',\n    'PCIAT-PCIAT_19', 'PCIAT-PCIAT_20'\n]\n\n# Apply the function to remove outliers\ndf= remove_outliers(df, columns_to_check)","metadata":{"execution":{"iopub.status.busy":"2024-10-21T15:38:26.519018Z","iopub.execute_input":"2024-10-21T15:38:26.520592Z","iopub.status.idle":"2024-10-21T15:38:26.583361Z","shell.execute_reply.started":"2024-10-21T15:38:26.520523Z","shell.execute_reply":"2024-10-21T15:38:26.582150Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"for x in df.columns:\n    plt.figure(figsize=(8, 4))  \n    sns.boxplot(data=df, x=x)   \n    plt.title(f'Boxplot of {x}')\n    plt.show()                  ","metadata":{"execution":{"iopub.status.busy":"2024-10-21T15:38:52.860143Z","iopub.execute_input":"2024-10-21T15:38:52.861140Z","iopub.status.idle":"2024-10-21T15:39:04.188610Z","shell.execute_reply.started":"2024-10-21T15:38:52.861091Z","shell.execute_reply":"2024-10-21T15:39:04.187381Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"","metadata":{},"execution_count":null,"outputs":[]}]}