{"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":"# 1. **Preprocessing** \n","metadata":{}},{"cell_type":"code","source":"import pandas as pd\nimport numpy as np\nimport matplotlib.pyplot as plt\nimport seaborn as sns\n\n","metadata":{"execution":{"iopub.status.busy":"2024-10-22T09:57:32.994273Z","iopub.execute_input":"2024-10-22T09:57:32.994684Z","iopub.status.idle":"2024-10-22T09:57:33.000208Z","shell.execute_reply.started":"2024-10-22T09:57:32.994645Z","shell.execute_reply":"2024-10-22T09:57:32.998840Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"dictionary = pd.read_csv('/kaggle/input/child-mind-institute-problematic-internet-use/data_dictionary.csv')\ndictionary","metadata":{"execution":{"iopub.status.busy":"2024-10-22T09:57:33.011705Z","iopub.execute_input":"2024-10-22T09:57:33.012522Z","iopub.status.idle":"2024-10-22T09:57:33.034177Z","shell.execute_reply.started":"2024-10-22T09:57:33.012477Z","shell.execute_reply":"2024-10-22T09:57:33.033063Z"},"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-22T09:57:33.036534Z","iopub.execute_input":"2024-10-22T09:57:33.036995Z","iopub.status.idle":"2024-10-22T09:57:33.122489Z","shell.execute_reply.started":"2024-10-22T09:57:33.036928Z","shell.execute_reply":"2024-10-22T09:57:33.121439Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"data = train\nbins = [5,7,9,10,12,14,16,18,20,22]\ndata['AgeGroup'] = pd.cut(data['Basic_Demos-Age'], bins)\nmale = data[data['Basic_Demos-Sex'] == 0]\nfemale = data[data['Basic_Demos-Sex'] == 1]\nmale_counts = male['AgeGroup'].value_counts(sort=False)\nfemale_counts = female['AgeGroup'].value_counts(sort=False)\nmale_percent = -100 * male_counts / len(male)  \nfemale_percent = 100 * female_counts / len(female)\n\nfig, ax = plt.subplots(figsize=(10, 8))\n\nax.barh(male_percent.index.astype(str), male_percent, color='blue', label='Male')\n\nax.barh(female_percent.index.astype(str), female_percent, color='green', label='Female')\n\nax.set_xlabel('Percentage')\nax.set_title('Age Distribution by Gender')\nax.legend()\n\nplt.show()\nprint(\"female:\",female.size)\nprint(\"male:\",male.size)","metadata":{"execution":{"iopub.status.busy":"2024-10-22T09:57:33.123961Z","iopub.execute_input":"2024-10-22T09:57:33.124413Z","iopub.status.idle":"2024-10-22T09:57:33.436181Z","shell.execute_reply.started":"2024-10-22T09:57:33.124362Z","shell.execute_reply":"2024-10-22T09:57:33.435094Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"train1 = train.iloc[:,76:]\ntrain2 = train.iloc[:,:18]\ntrain3 = pd.DataFrame(pd.concat([train2, train1], axis=1))\ntrain3.head(5)\n#train1.head(5)\n#train.head(5)","metadata":{"execution":{"iopub.status.busy":"2024-10-22T09:57:33.438410Z","iopub.execute_input":"2024-10-22T09:57:33.438811Z","iopub.status.idle":"2024-10-22T09:57:33.476372Z","shell.execute_reply.started":"2024-10-22T09:57:33.438768Z","shell.execute_reply":"2024-10-22T09:57:33.475278Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"train_ = train3.drop('Basic_Demos-Enroll_Season', axis=1)\ntrain_ = train_.drop('CGAS-Season', axis=1)\ntrain_ = train_.drop('Physical-Season', axis=1)\ntrain_ = train_.drop('Fitness_Endurance-Season', axis=1)\ntrain_ = train_.drop('PreInt_EduHx-Season',axis = 1)\ntrain_ = train_.drop('SDS-Season',axis = 1)\n\ntrain_.head(5)","metadata":{"execution":{"iopub.status.busy":"2024-10-22T09:57:33.478062Z","iopub.execute_input":"2024-10-22T09:57:33.478521Z","iopub.status.idle":"2024-10-22T09:57:33.518744Z","shell.execute_reply.started":"2024-10-22T09:57:33.478470Z","shell.execute_reply":"2024-10-22T09:57:33.517712Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"train_male = train_[train_['Basic_Demos-Sex'] == 0]\ntrain_male = train_male.drop('Basic_Demos-Sex',axis = 1)\ntrain_female = train_[train_['Basic_Demos-Sex'] == 1]\ntrain_female = train_female.drop('Basic_Demos-Sex',axis = 1)\ntrain_female.head(5)","metadata":{"execution":{"iopub.status.busy":"2024-10-22T09:57:33.520476Z","iopub.execute_input":"2024-10-22T09:57:33.520956Z","iopub.status.idle":"2024-10-22T09:57:33.557953Z","shell.execute_reply.started":"2024-10-22T09:57:33.520893Z","shell.execute_reply":"2024-10-22T09:57:33.556837Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"train_male_adult = train_male[train_male['Basic_Demos-Age']>=15]\ntrain_male_child_10 = train_male[(train_male['Basic_Demos-Age']<15) & (train_male['Basic_Demos-Age']>=10)]\ntrain_male_child_5 = train_male[(train_male['Basic_Demos-Age']<10) & (train_male['Basic_Demos-Age']>=5)]\n\nprint(train_male_adult.size)\nprint(train_male_child_10.size)\nprint(train_male_child_5.size)","metadata":{"execution":{"iopub.status.busy":"2024-10-22T09:57:33.559571Z","iopub.execute_input":"2024-10-22T09:57:33.560585Z","iopub.status.idle":"2024-10-22T09:57:33.573556Z","shell.execute_reply.started":"2024-10-22T09:57:33.560531Z","shell.execute_reply":"2024-10-22T09:57:33.572518Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"physical_male = train_male.iloc[:,list(range(0,10))+list(range(13,17))]\nphysical_male.head(5)\n","metadata":{"execution":{"iopub.status.busy":"2024-10-22T09:57:33.575147Z","iopub.execute_input":"2024-10-22T09:57:33.575593Z","iopub.status.idle":"2024-10-22T09:57:33.603150Z","shell.execute_reply.started":"2024-10-22T09:57:33.575542Z","shell.execute_reply":"2024-10-22T09:57:33.601873Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"avg_score = train_.groupby('Basic_Demos-Age')['sii'].mean()\navg_score.plot(kind='bar')\nplt.xlabel('age')\nplt.ylabel('sii')\nplt.title('age-sii')\nplt.show()\navg_score = train_.groupby('Basic_Demos-Age')['SDS-SDS_Total_Raw'].mean()\navg_score.plot(kind='bar')\nplt.xlabel('age')\nplt.ylabel('raw_score')\nplt.title('age-raw_score')\nplt.show()\navg_score = train_.groupby('Basic_Demos-Age')['SDS-SDS_Total_T'].mean()\navg_score.plot(kind='bar')\nplt.xlabel('age')\nplt.ylabel('T_score')\nplt.title('age-T_score')\nplt.show()\navg_score = train_.groupby('Basic_Demos-Age')['CGAS-CGAS_Score'].mean()\navg_score.plot(kind='bar')\nplt.xlabel('age')\nplt.ylabel('CGAS-CGAS_Score')\nplt.title('age-CGAS')\nplt.show()\navg_score = train_.groupby('Basic_Demos-Age')['PreInt_EduHx-computerinternet_hoursday'].mean()\navg_score.plot(kind='bar')\nplt.xlabel('age')\nplt.ylabel('PreInt_EduHx-computerinternet_hoursday')\nplt.title('age-Hoursday')\nplt.show()","metadata":{"execution":{"iopub.status.busy":"2024-10-22T09:57:33.607217Z","iopub.execute_input":"2024-10-22T09:57:33.607614Z","iopub.status.idle":"2024-10-22T09:57:35.352662Z","shell.execute_reply.started":"2024-10-22T09:57:33.607575Z","shell.execute_reply":"2024-10-22T09:57:35.351566Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"avg_score = physical_male.groupby('SDS-SDS_Total_T')['sii'].mean()\navg_score.plot(kind='bar')\nplt.xlabel('Target Variable')\nplt.ylabel('sii')\nplt.title('Average Score by Target Variable')\nplt.show()","metadata":{"execution":{"iopub.status.busy":"2024-10-22T09:57:35.354349Z","iopub.execute_input":"2024-10-22T09:57:35.354790Z","iopub.status.idle":"2024-10-22T09:57:35.954947Z","shell.execute_reply.started":"2024-10-22T09:57:35.354741Z","shell.execute_reply":"2024-10-22T09:57:35.953853Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"avg_score = physical_male.groupby('CGAS-CGAS_Score')['sii'].mean()\navg_score.plot(kind='bar')\nplt.xlabel('Target Variable')\nplt.ylabel('sii')\nplt.title('Average Score by Target Variable')\nplt.show()","metadata":{"execution":{"iopub.status.busy":"2024-10-22T09:57:35.956498Z","iopub.execute_input":"2024-10-22T09:57:35.956949Z","iopub.status.idle":"2024-10-22T09:57:36.587707Z","shell.execute_reply.started":"2024-10-22T09:57:35.956898Z","shell.execute_reply":"2024-10-22T09:57:36.586416Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"# 2.FitnessGram","metadata":{}},{"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-22T09:57:36.589499Z","iopub.execute_input":"2024-10-22T09:57:36.589921Z","iopub.status.idle":"2024-10-22T09:57:36.675002Z","shell.execute_reply.started":"2024-10-22T09:57:36.589872Z","shell.execute_reply":"2024-10-22T09:57:36.673904Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"train1 = train.iloc[:,15:33]\nid_ = train.iloc[:,0:4]\ntrain_merge = pd.DataFrame(pd.concat([id_, train1], axis=1))\ntrain_merge = train_merge.drop(\"FGC-Season\",axis = 1)\ntrain_merge = train_merge.drop(\"Basic_Demos-Enroll_Season\",axis = 1)\ntrain_merge.head(5)\n","metadata":{"execution":{"iopub.status.busy":"2024-10-22T09:57:36.676718Z","iopub.execute_input":"2024-10-22T09:57:36.677182Z","iopub.status.idle":"2024-10-22T09:57:36.714666Z","shell.execute_reply.started":"2024-10-22T09:57:36.677132Z","shell.execute_reply":"2024-10-22T09:57:36.713581Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"* FGC data spasity check","metadata":{}},{"cell_type":"code","source":"import seaborn as sns\nimport matplotlib.pyplot as plt\nnp.random.seed(0)\n\n# For missing values (NaN)\nsparsity = train_merge.isna().sum().sum() / train_merge.size\n\n# Sparsity of each column for missing values (NaN)\nreverse_sparsity_per_column = 1-train_merge.isna().sum() / len(train_merge)\n\n# Bar plot for column-wise sparsity\nreverse_sparsity_per_column.plot(kind='bar')\nplt.show()\n","metadata":{"execution":{"iopub.status.busy":"2024-10-22T09:57:36.716163Z","iopub.execute_input":"2024-10-22T09:57:36.716507Z","iopub.status.idle":"2024-10-22T09:57:37.022318Z","shell.execute_reply.started":"2024-10-22T09:57:36.716471Z","shell.execute_reply":"2024-10-22T09:57:37.021277Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"#split fitness endurance max_stage and fgc\nid_ = train_merge.iloc[:,0:3]\nFGV = pd.DataFrame(pd.concat([id_, train_merge.iloc[:,3:6]], axis=1))\nFGC = pd.DataFrame(pd.concat([id_, train_merge.iloc[:,6:30]], axis=1))","metadata":{"execution":{"iopub.status.busy":"2024-10-22T09:57:37.023858Z","iopub.execute_input":"2024-10-22T09:57:37.024326Z","iopub.status.idle":"2024-10-22T09:57:37.034837Z","shell.execute_reply.started":"2024-10-22T09:57:37.024279Z","shell.execute_reply":"2024-10-22T09:57:37.033730Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"#merge minutes and seconds column in fitness endurance test as a new feature\nFGV['Fitness_Endurance-Time_TOTAL'] = FGV['Fitness_Endurance-Time_Mins'] * 60 + FGV['Fitness_Endurance-Time_Sec']","metadata":{"execution":{"iopub.status.busy":"2024-10-22T09:57:37.036544Z","iopub.execute_input":"2024-10-22T09:57:37.036942Z","iopub.status.idle":"2024-10-22T09:57:37.048201Z","shell.execute_reply.started":"2024-10-22T09:57:37.036897Z","shell.execute_reply":"2024-10-22T09:57:37.047055Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"sns.heatmap(train[['Fitness_Endurance-Max_Stage', 'Fitness_Endurance-Time_Mins','Fitness_Endurance-Time_Sec','FGC-FGC_CU', 'FGC-FGC_GSND', 'FGC-FGC_GSD', 'FGC-FGC_PU','FGC-FGC_SRL','FGC-FGC_SRR','FGC-FGC_TL','Basic_Demos-Age','Basic_Demos-Sex','sii','PreInt_EduHx-computerinternet_hoursday','CGAS-CGAS_Score','SDS-SDS_Total_Raw','SDS-SDS_Total_T']].corr(), annot=True)","metadata":{"execution":{"iopub.status.busy":"2024-10-22T09:57:37.049585Z","iopub.execute_input":"2024-10-22T09:57:37.049963Z","iopub.status.idle":"2024-10-22T09:57:38.479549Z","shell.execute_reply.started":"2024-10-22T09:57:37.049918Z","shell.execute_reply":"2024-10-22T09:57:38.478386Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"sns.heatmap(FGV[['Basic_Demos-Age', 'Basic_Demos-Sex', 'Fitness_Endurance-Max_Stage', 'Fitness_Endurance-Time_Mins','Fitness_Endurance-Time_Sec','Fitness_Endurance-Time_TOTAL']].corr(), annot=True)","metadata":{"execution":{"iopub.status.busy":"2024-10-22T09:57:38.481120Z","iopub.execute_input":"2024-10-22T09:57:38.481551Z","iopub.status.idle":"2024-10-22T09:57:39.009973Z","shell.execute_reply.started":"2024-10-22T09:57:38.481501Z","shell.execute_reply":"2024-10-22T09:57:39.008801Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"#sparsity of data in each age\nage_groups = FGV.groupby('Basic_Demos-Age')\nsparsity_by_age = age_groups['Fitness_Endurance-Time_TOTAL'].apply(lambda x: x.isna().mean() if x.isna().sum() > 0 else (x == 0).mean())\nprint(sparsity_by_age)\nage_groups = FGV.groupby('Basic_Demos-Age')\nsparsity_by_age = age_groups['Fitness_Endurance-Max_Stage'].apply(lambda x: x.isna().mean() if x.isna().sum() > 0 else (x == 0).mean())\nprint(sparsity_by_age)","metadata":{"execution":{"iopub.status.busy":"2024-10-22T09:57:39.011653Z","iopub.execute_input":"2024-10-22T09:57:39.012251Z","iopub.status.idle":"2024-10-22T09:57:39.041952Z","shell.execute_reply.started":"2024-10-22T09:57:39.012188Z","shell.execute_reply":"2024-10-22T09:57:39.040846Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"AGE_EDV = FGV.groupby('Basic_Demos-Age')['Fitness_Endurance-Max_Stage'].mean()\nAGE_EDV.plot(kind='bar')\nplt.xlabel('age')\nplt.ylabel('Fitness_Endurance-Max_Stage')\nplt.title('age v.s. Fitness endurance max stage')\nplt.show()\n\nAGE_EDV = FGV.groupby('Basic_Demos-Age')['Fitness_Endurance-Time_TOTAL'].mean()\nAGE_EDV.plot(kind='bar')\nplt.xlabel('age')\nplt.ylabel('Fitness_Endurance-Time_TOTAL')\nplt.title('age v.s. Fitness_Endurance-Time_TOTAL')\nplt.show()\n\n\nplt.figure(figsize=(10, 6))\nsns.boxplot(x=FGV['Basic_Demos-Age'], y=FGV['Fitness_Endurance-Time_TOTAL'])\n\nplt.xlabel('Age')\nplt.ylabel('Fitness_Endurance-Time_TOTAL')\nplt.title('Age vs. Fitness_Endurance-Time_TOTAL (Boxplot)')\nplt.xticks(rotation=45) \nplt.show()\n","metadata":{"execution":{"iopub.status.busy":"2024-10-22T09:57:39.043673Z","iopub.execute_input":"2024-10-22T09:57:39.044164Z","iopub.status.idle":"2024-10-22T09:57:39.998032Z","shell.execute_reply.started":"2024-10-22T09:57:39.044114Z","shell.execute_reply":"2024-10-22T09:57:39.996857Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"lower_bound = FGV['Fitness_Endurance-Max_Stage'].quantile(0)\nupper_bound = FGV['Fitness_Endurance-Max_Stage'].quantile(1)\nfiltered_y = FGV[(FGV['Fitness_Endurance-Max_Stage'] > lower_bound) & (FGV['Fitness_Endurance-Max_Stage'] < upper_bound)]\nlower_bound = FGV['Fitness_Endurance-Time_TOTAL'].quantile(0)\nupper_bound = FGV['Fitness_Endurance-Time_TOTAL'].quantile(1)\nfiltered_x = FGV[(filtered_y['Fitness_Endurance-Time_TOTAL'] > lower_bound) & (FGV['Fitness_Endurance-Time_TOTAL'] < upper_bound)]\n\nplt.scatter(x=filtered_x['Fitness_Endurance-Time_TOTAL'], y=filtered_x['Fitness_Endurance-Max_Stage'], alpha=0.5)\nplt.xlabel('Fitness_Endurance-Time_TOTAL')\nplt.ylabel('Fitness_Endurance-Max_Stage')\nplt.title('Fitness_Endurance-Time_TOTAL vs. Fitness_Endurance-Max_Stage')\nplt.show()","metadata":{"execution":{"iopub.status.busy":"2024-10-22T09:57:39.999373Z","iopub.execute_input":"2024-10-22T09:57:39.999749Z","iopub.status.idle":"2024-10-22T09:57:40.239858Z","shell.execute_reply.started":"2024-10-22T09:57:39.999710Z","shell.execute_reply":"2024-10-22T09:57:40.238720Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"plt.figure(figsize=(10, 6))\nsns.regplot(x='CGAS-CGAS_Score', y='Fitness_Endurance-Max_Stage', data=train, marker='o', color='b')\nplt.title('CGAS Score vs Fitness_Endurance-Max_Stage', fontsize=16)\nplt.xlabel('CGAS Score (%)', fontsize=14)\nplt.ylabel('Fitness_Endurance-Max_Stage', fontsize=14)\nplt.show()\n\ncorrelation = train['CGAS-CGAS_Score'].corr(train['Fitness_Endurance-Max_Stage'])\nprint(correlation)","metadata":{"execution":{"iopub.status.busy":"2024-10-22T09:57:40.241679Z","iopub.execute_input":"2024-10-22T09:57:40.242168Z","iopub.status.idle":"2024-10-22T09:57:40.654965Z","shell.execute_reply.started":"2024-10-22T09:57:40.242116Z","shell.execute_reply":"2024-10-22T09:57:40.653948Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"import scipy.stats as stats\nclean = train.dropna(subset=['sii', 'Fitness_Endurance-Max_Stage'])\n\nanova_result = stats.f_oneway(\n    clean[clean['sii'] == 0]['Fitness_Endurance-Max_Stage'],\n    clean[clean['sii'] == 1]['Fitness_Endurance-Max_Stage'],\n    clean[clean['sii'] == 2]['Fitness_Endurance-Max_Stage'],\n    clean[clean['sii'] == 3]['Fitness_Endurance-Max_Stage']\n)\n\nprint(f\"ANOVA檢驗的p值為: {anova_result.pvalue:.4f}\")","metadata":{"execution":{"iopub.status.busy":"2024-10-22T09:57:40.656481Z","iopub.execute_input":"2024-10-22T09:57:40.656930Z","iopub.status.idle":"2024-10-22T09:57:40.675774Z","shell.execute_reply.started":"2024-10-22T09:57:40.656882Z","shell.execute_reply":"2024-10-22T09:57:40.674519Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"sns.heatmap(FGC[['FGC-FGC_CU', 'FGC-FGC_GSND', 'FGC-FGC_GSD', 'FGC-FGC_PU','FGC-FGC_SRL','FGC-FGC_SRR','FGC-FGC_TL','Basic_Demos-Age','Basic_Demos-Sex']].corr(), annot=True)","metadata":{"execution":{"iopub.status.busy":"2024-10-22T09:57:40.682557Z","iopub.execute_input":"2024-10-22T09:57:40.683078Z","iopub.status.idle":"2024-10-22T09:57:41.298343Z","shell.execute_reply.started":"2024-10-22T09:57:40.683006Z","shell.execute_reply":"2024-10-22T09:57:41.297079Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"def summarize_data(df, score_col, zone_col):\n    summary = df.groupby(zone_col)[score_col].agg(['min', 'max', 'mean', 'count'])\n    summary['range'] = summary['max'] - summary['min']\n    return summary","metadata":{"execution":{"iopub.status.busy":"2024-10-22T09:57:41.300091Z","iopub.execute_input":"2024-10-22T09:57:41.300535Z","iopub.status.idle":"2024-10-22T09:57:41.307732Z","shell.execute_reply.started":"2024-10-22T09:57:41.300488Z","shell.execute_reply":"2024-10-22T09:57:41.306455Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"result = {}\nrange_summary = summarize_data(FGC, 'FGC-FGC_CU', 'FGC-FGC_CU_Zone')\nresult['CU'] = range_summary\nrange_summary = summarize_data(FGC, 'FGC-FGC_GSND', 'FGC-FGC_GSND_Zone')\nresult['GSND'] = range_summary\nrange_summary = summarize_data(FGC, 'FGC-FGC_GSD', 'FGC-FGC_GSD_Zone')\nresult['GSD'] = range_summary\nrange_summary = summarize_data(FGC, 'FGC-FGC_PU', 'FGC-FGC_PU_Zone')\nresult['PU'] = range_summary\nrange_summary = summarize_data(FGC, 'FGC-FGC_SRL', 'FGC-FGC_SRL_Zone')\nresult['SRL'] = range_summary\nrange_summary = summarize_data(FGC, 'FGC-FGC_SRR', 'FGC-FGC_SRR_Zone')\nresult['SRR'] = range_summary\nrange_summary = summarize_data(FGC, 'FGC-FGC_TL', 'FGC-FGC_TL_Zone')\nresult['TL'] = range_summary\nresult","metadata":{"execution":{"iopub.status.busy":"2024-10-22T09:57:41.309063Z","iopub.execute_input":"2024-10-22T09:57:41.309477Z","iopub.status.idle":"2024-10-22T09:57:41.367787Z","shell.execute_reply.started":"2024-10-22T09:57:41.309439Z","shell.execute_reply":"2024-10-22T09:57:41.366758Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"* Create new feture","metadata":{}},{"cell_type":"code","source":"plt.scatter(x=FGC['FGC-FGC_GSND'], y=FGC['FGC-FGC_GSD'], alpha=0.5)\nplt.xlabel('FGC-FGC_GSND')\nplt.ylabel('FGC-FGC_GSD')\nplt.title('gsnd vs. gsd')\nplt.show()\n\nplt.scatter(x=FGC['FGC-FGC_GSND_Zone'], y=FGC['FGC-FGC_GSND'], alpha=0.5)\nplt.xlabel('FGC-FGC_GSND_Zone')\nplt.ylabel('FGC-FGC_GSND')\nplt.title('gsnd vs. gsnd_zone')\nplt.show()\n\nplt.scatter(x=FGC['FGC-FGC_GSD_Zone'], y=FGC['FGC-FGC_GSD'], alpha=0.5)\nplt.xlabel('FGC-FGC_GSD_Zone')\nplt.ylabel('FGC-FGC_GSD')\nplt.title('gsd vs. gsd_zone')\nplt.show()\n\nplt.scatter(x=FGC['FGC-FGC_SRL_Zone'], y=FGC['FGC-FGC_SRL'], alpha=0.5)\nplt.xlabel('FGC-FGC_SRL_Zone')\nplt.ylabel('FGC-FGC_SRL')\nplt.title('srl vs. srl_zone')\nplt.show()\n","metadata":{"execution":{"iopub.status.busy":"2024-10-22T09:57:41.369347Z","iopub.execute_input":"2024-10-22T09:57:41.369793Z","iopub.status.idle":"2024-10-22T09:57:42.476367Z","shell.execute_reply.started":"2024-10-22T09:57:41.369744Z","shell.execute_reply":"2024-10-22T09:57:42.475296Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"from scipy.stats import chi2_contingency\n\n# Create a contingency table\ncontingency_table = pd.crosstab(train['PreInt_EduHx-computerinternet_hoursday'], train['sii'])\nprint(\"Contingency Table:\\n\", contingency_table)\n\n# Perform the Chi-Square Test\nchi2, p, dof, expected = chi2_contingency(contingency_table)\n\n# Output the results\nprint(f\"Chi-Square Statistic: {chi2}\")\nprint(f\"Degrees of Freedom: {dof}\")\nprint(f\"Expected Frequencies:\\n{expected}\")\nprint(f\"P-Value: {p}\")\n\n# Interpret the p-value\nalpha = 0.05\nif p < alpha:\n    print(\"Reject the null hypothesis: There is a significant association between the two categorical variables.\")\nelse:\n    print(\"Fail to reject the null hypothesis: There is no significant association between the two categorical variables.\")","metadata":{"execution":{"iopub.status.busy":"2024-10-22T10:04:59.944257Z","iopub.execute_input":"2024-10-22T10:04:59.944678Z","iopub.status.idle":"2024-10-22T10:04:59.967286Z","shell.execute_reply.started":"2024-10-22T10:04:59.944613Z","shell.execute_reply":"2024-10-22T10:04:59.966099Z"},"trusted":true},"execution_count":null,"outputs":[]}]}