{"metadata":{"kernelspec":{"language":"python","display_name":"Python 3","name":"python3"},"language_info":{"name":"python","version":"3.10.12","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":30822,"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","trusted":true,"execution":{"iopub.status.busy":"2024-12-21T19:17:44.373874Z","iopub.execute_input":"2024-12-21T19:17:44.374225Z","iopub.status.idle":"2024-12-21T19:17:45.862015Z","shell.execute_reply.started":"2024-12-21T19:17:44.374198Z","shell.execute_reply":"2024-12-21T19:17:45.860101Z"},"collapsed":true,"jupyter":{"outputs_hidden":true}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"trainpath=r'/kaggle/input/child-mind-institute-problematic-internet-use/train.csv'\ntestpath=r'/kaggle/input/child-mind-institute-problematic-internet-use/test.csv'","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2024-12-21T19:17:45.863470Z","iopub.execute_input":"2024-12-21T19:17:45.863796Z","iopub.status.idle":"2024-12-21T19:17:45.869492Z","shell.execute_reply.started":"2024-12-21T19:17:45.863767Z","shell.execute_reply":"2024-12-21T19:17:45.868456Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"import pandas as pd\nimport numpy as np\nimport seaborn as sns\nimport matplotlib.pyplot as plt\n\npd.set_option('display.max_columns',None)\ndf_train=pd.read_csv(trainpath).drop(columns=['id'])\ndf_train.sample(5)","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2024-12-21T19:17:45.872771Z","iopub.execute_input":"2024-12-21T19:17:45.873287Z","iopub.status.idle":"2024-12-21T19:17:46.006089Z","shell.execute_reply.started":"2024-12-21T19:17:45.873253Z","shell.execute_reply":"2024-12-21T19:17:46.004783Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"test_df=pd.read_csv(testpath)\n","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2024-12-21T20:25:46.512450Z","iopub.execute_input":"2024-12-21T20:25:46.513038Z","iopub.status.idle":"2024-12-21T20:25:46.525637Z","shell.execute_reply.started":"2024-12-21T20:25:46.512992Z","shell.execute_reply":"2024-12-21T20:25:46.524392Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"df_train.info()","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2024-12-21T19:17:46.007788Z","iopub.execute_input":"2024-12-21T19:17:46.008120Z","iopub.status.idle":"2024-12-21T19:17:46.026398Z","shell.execute_reply.started":"2024-12-21T19:17:46.008094Z","shell.execute_reply":"2024-12-21T19:17:46.025119Z"},"collapsed":true,"jupyter":{"outputs_hidden":true}},"outputs":[],"execution_count":null},{"cell_type":"markdown","source":"**Check Categorical Data**","metadata":{}},{"cell_type":"code","source":"ca_df=df_train.select_dtypes(exclude=[np.number])\nca_df.sample(5)\nca_test=test_df.select_dtypes(exclude=[np.number])","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2024-12-21T20:26:41.781431Z","iopub.execute_input":"2024-12-21T20:26:41.781796Z","iopub.status.idle":"2024-12-21T20:26:41.788145Z","shell.execute_reply.started":"2024-12-21T20:26:41.781768Z","shell.execute_reply":"2024-12-21T20:26:41.786924Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"ca_df.info()","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2024-12-21T19:17:46.050762Z","iopub.execute_input":"2024-12-21T19:17:46.051165Z","iopub.status.idle":"2024-12-21T19:17:46.078101Z","shell.execute_reply.started":"2024-12-21T19:17:46.051134Z","shell.execute_reply":"2024-12-21T19:17:46.077113Z"}},"outputs":[],"execution_count":null},{"cell_type":"markdown","source":"**Numerical Data**","metadata":{}},{"cell_type":"code","source":"num_df=df_train.select_dtypes(include=[np.number])\nnum_df.sample(5)\nnum_test=test_df.select_dtypes(include=[np.number])\n","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2024-12-21T20:27:19.954479Z","iopub.execute_input":"2024-12-21T20:27:19.954912Z","iopub.status.idle":"2024-12-21T20:27:19.963074Z","shell.execute_reply.started":"2024-12-21T20:27:19.954881Z","shell.execute_reply":"2024-12-21T20:27:19.961907Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"num_df.info()","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2024-12-21T19:17:46.157860Z","iopub.execute_input":"2024-12-21T19:17:46.158137Z","iopub.status.idle":"2024-12-21T19:17:46.172602Z","shell.execute_reply.started":"2024-12-21T19:17:46.158115Z","shell.execute_reply":"2024-12-21T19:17:46.171502Z"},"collapsed":true,"jupyter":{"outputs_hidden":true}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"threshold=1224\ntotal_col=[]\ncolumns=num_df.columns\nfor i in columns:\n    nan=num_df[i].isna().sum()\n    if nan > threshold :\n        total_col.append(i)\n        print(f\"Columns Name {i} Nan Value {nan}\")\nprint(\"--------------------------------------\")\nprint(f\"Total COlumns {len(total_col)}\")","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2024-12-21T19:17:46.175718Z","iopub.execute_input":"2024-12-21T19:17:46.176056Z","iopub.status.idle":"2024-12-21T19:17:46.210264Z","shell.execute_reply.started":"2024-12-21T19:17:46.176026Z","shell.execute_reply":"2024-12-21T19:17:46.209306Z"},"collapsed":true,"jupyter":{"outputs_hidden":true}},"outputs":[],"execution_count":null},{"cell_type":"markdown","source":"**Delet Nan Value In Numerical Data**","metadata":{}},{"cell_type":"code","source":"threshold=1224\ncolumns=num_df.columns\nfor i in columns:\n    nan=num_df[i].isna().sum()\n    if nan > threshold :\n       df_train=df_train.drop(columns=[i])\n\n\ndf_train.info()","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2024-12-21T20:35:42.396840Z","iopub.execute_input":"2024-12-21T20:35:42.397277Z","iopub.status.idle":"2024-12-21T20:35:42.413984Z","shell.execute_reply.started":"2024-12-21T20:35:42.397244Z","shell.execute_reply":"2024-12-21T20:35:42.412414Z"}},"outputs":[],"execution_count":null},{"cell_type":"markdown","source":"**Delet Nan Value In Categorical Data**","metadata":{}},{"cell_type":"code","source":"threshold=1224\ncolumns=ca_df.columns\nfor i in columns:\n    nan=ca_df[i].isna().sum()\n    if nan > threshold :\n      df_train=df_train.drop(columns=[i])\n\ndf_train.info()","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2024-12-21T20:35:37.817418Z","iopub.execute_input":"2024-12-21T20:35:37.817916Z","iopub.status.idle":"2024-12-21T20:35:37.835066Z","shell.execute_reply.started":"2024-12-21T20:35:37.817878Z","shell.execute_reply":"2024-12-21T20:35:37.833941Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"df_train=df_train.dropna()\ndf_train.info()\ntest_df=test_df.dropna()","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2024-12-21T20:30:35.280879Z","iopub.execute_input":"2024-12-21T20:30:35.281375Z","iopub.status.idle":"2024-12-21T20:30:35.300920Z","shell.execute_reply.started":"2024-12-21T20:30:35.281311Z","shell.execute_reply":"2024-12-21T20:30:35.299748Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"df_train.isna().sum()","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2024-12-21T19:17:46.340187Z","iopub.execute_input":"2024-12-21T19:17:46.340597Z","iopub.status.idle":"2024-12-21T19:17:46.358055Z","shell.execute_reply.started":"2024-12-21T19:17:46.340553Z","shell.execute_reply":"2024-12-21T19:17:46.356935Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"df_train.describe()","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2024-12-21T19:17:46.359131Z","iopub.execute_input":"2024-12-21T19:17:46.359522Z","iopub.status.idle":"2024-12-21T19:17:46.413184Z","shell.execute_reply.started":"2024-12-21T19:17:46.359481Z","shell.execute_reply":"2024-12-21T19:17:46.411961Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"df_train['Physical-Weight']=df_train['Physical-Weight'].replace(0,80)\ndf_train.describe()\n","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2024-12-21T20:35:30.084666Z","iopub.execute_input":"2024-12-21T20:35:30.085023Z","iopub.status.idle":"2024-12-21T20:35:30.135487Z","shell.execute_reply.started":"2024-12-21T20:35:30.084996Z","shell.execute_reply":"2024-12-21T20:35:30.134479Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"num=df_train.select_dtypes(include=[np.number])\nsns.heatmap(num.corr(),annot=True)","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2024-12-21T19:20:18.293883Z","iopub.execute_input":"2024-12-21T19:20:18.294232Z","iopub.status.idle":"2024-12-21T19:20:18.995492Z","shell.execute_reply.started":"2024-12-21T19:20:18.294196Z","shell.execute_reply":"2024-12-21T19:20:18.994217Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"df_train.head()","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2024-12-21T19:21:22.382505Z","iopub.execute_input":"2024-12-21T19:21:22.382917Z","iopub.status.idle":"2024-12-21T19:21:22.404322Z","shell.execute_reply.started":"2024-12-21T19:21:22.382888Z","shell.execute_reply":"2024-12-21T19:21:22.402676Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"df_train['Basic_Demos-Enroll_Season'].value_counts().plot.bar()","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2024-12-21T19:25:45.348280Z","iopub.execute_input":"2024-12-21T19:25:45.348676Z","iopub.status.idle":"2024-12-21T19:25:45.569104Z","shell.execute_reply.started":"2024-12-21T19:25:45.348637Z","shell.execute_reply":"2024-12-21T19:25:45.567967Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"df_train['sii'].value_counts().plot.bar()","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2024-12-21T19:26:31.736629Z","iopub.execute_input":"2024-12-21T19:26:31.737071Z","iopub.status.idle":"2024-12-21T19:26:31.952876Z","shell.execute_reply.started":"2024-12-21T19:26:31.737033Z","shell.execute_reply":"2024-12-21T19:26:31.951849Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"categ=df_train.select_dtypes(exclude=[np.number])\n","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2024-12-21T19:27:42.507880Z","iopub.execute_input":"2024-12-21T19:27:42.508255Z","iopub.status.idle":"2024-12-21T19:27:42.516108Z","shell.execute_reply.started":"2024-12-21T19:27:42.508226Z","shell.execute_reply":"2024-12-21T19:27:42.514495Z"}},"outputs":[],"execution_count":null},{"cell_type":"markdown","source":"**Encoder To Categorical Values**","metadata":{}},{"cell_type":"code","source":"from sklearn.preprocessing import LabelEncoder\nencoder=LabelEncoder()\nfor i in categ:\n    df_train[i]=encoder.fit_transform(df_train[i])\n\n\n","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2024-12-21T20:31:54.836252Z","iopub.execute_input":"2024-12-21T20:31:54.836646Z","iopub.status.idle":"2024-12-21T20:31:54.880919Z","shell.execute_reply.started":"2024-12-21T20:31:54.836617Z","shell.execute_reply":"2024-12-21T20:31:54.879661Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"feature=df_train.iloc[:,:-1]\nlabel=df_train.iloc[:,-1]\nprint(f\"features shape {feature.shape}\\nlabels shape {label.shape}\")","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2024-12-21T19:32:03.507832Z","iopub.execute_input":"2024-12-21T19:32:03.508207Z","iopub.status.idle":"2024-12-21T19:32:03.516032Z","shell.execute_reply.started":"2024-12-21T19:32:03.508176Z","shell.execute_reply":"2024-12-21T19:32:03.514629Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"from sklearn.model_selection import train_test_split\nfrom sklearn.feature_selection import SequentialFeatureSelector\nfrom sklearn.metrics import accuracy_score,confusion_matrix, ConfusionMatrixDisplay\nfrom sklearn.ensemble import RandomForestClassifier\n\nmodel=RandomForestClassifier(max_depth=50,n_estimators=100)\nfe=SequentialFeatureSelector(model,n_features_to_select=11)\nfe.fit(feature,label)\nfe.get_support()\n","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2024-12-21T20:12:49.639206Z","iopub.execute_input":"2024-12-21T20:12:49.639620Z","iopub.status.idle":"2024-12-21T20:14:54.852972Z","shell.execute_reply.started":"2024-12-21T20:12:49.639590Z","shell.execute_reply":"2024-12-21T20:14:54.851829Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"o=fe.get_support()\nindex=0\nfeature_w_del={}\nfor i in feature.columns:\n    feature_w_del[i]=o[index]\n    index=index+1\n\npd.Series(feature_w_del)","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2024-12-21T19:58:58.251456Z","iopub.execute_input":"2024-12-21T19:58:58.251922Z","iopub.status.idle":"2024-12-21T19:58:58.262172Z","shell.execute_reply.started":"2024-12-21T19:58:58.251889Z","shell.execute_reply":"2024-12-21T19:58:58.260491Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"x=fe.fit_transform(feature,label)\nx.shape","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2024-12-21T20:32:56.298831Z","iopub.execute_input":"2024-12-21T20:32:56.299261Z","iopub.status.idle":"2024-12-21T20:35:02.151915Z","shell.execute_reply.started":"2024-12-21T20:32:56.299226Z","shell.execute_reply":"2024-12-21T20:35:02.150841Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"x_train,x_test,y_train,y_test=train_test_split(x,label,test_size=0.2,random_state=44)\nmodel.fit(x_train,y_train)\npre=model.predict(x_test)\nprint(f\"score for train {model.score(x_train,y_train)}\")\nprint(f\"score for test {model.score(x_test,y_test)}\")\nprint(f\" accuracy {accuracy_score(y_test,pre)}\")\n","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2024-12-21T20:32:47.483550Z","iopub.execute_input":"2024-12-21T20:32:47.484016Z","iopub.status.idle":"2024-12-21T20:32:47.826685Z","shell.execute_reply.started":"2024-12-21T20:32:47.483977Z","shell.execute_reply":"2024-12-21T20:32:47.825476Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"cm = confusion_matrix(y_test, pre)\ndisp = ConfusionMatrixDisplay(confusion_matrix=cm)\ndisp.plot()\nplt.show()","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2024-12-21T20:16:01.954642Z","iopub.execute_input":"2024-12-21T20:16:01.955058Z","iopub.status.idle":"2024-12-21T20:16:02.224061Z","shell.execute_reply.started":"2024-12-21T20:16:01.955029Z","shell.execute_reply":"2024-12-21T20:16:02.222736Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"test_df=pd.read_csv(testpath)\ntest_df.head()","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2024-12-21T20:22:52.394854Z","iopub.execute_input":"2024-12-21T20:22:52.395240Z","iopub.status.idle":"2024-12-21T20:22:52.453927Z","shell.execute_reply.started":"2024-12-21T20:22:52.395210Z","shell.execute_reply":"2024-12-21T20:22:52.452964Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"","metadata":{"trusted":true},"outputs":[],"execution_count":null}]}