{"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\nimport numpy as np","metadata":{"execution":{"iopub.status.busy":"2024-11-08T02:13:26.423755Z","iopub.execute_input":"2024-11-08T02:13:26.424890Z","iopub.status.idle":"2024-11-08T02:13:27.624030Z","shell.execute_reply.started":"2024-11-08T02:13:26.424817Z","shell.execute_reply":"2024-11-08T02:13:27.623053Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"train = pd.read_csv('/kaggle/input/child-mind-institute-problematic-internet-use/train.csv')","metadata":{"execution":{"iopub.status.busy":"2024-11-08T02:13:27.625571Z","iopub.execute_input":"2024-11-08T02:13:27.626035Z","iopub.status.idle":"2024-11-08T02:13:27.694920Z","shell.execute_reply.started":"2024-11-08T02:13:27.625999Z","shell.execute_reply":"2024-11-08T02:13:27.693918Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"test = pd.read_csv('/kaggle/input/child-mind-institute-problematic-internet-use/test.csv')","metadata":{"execution":{"iopub.status.busy":"2024-11-08T02:13:27.696041Z","iopub.execute_input":"2024-11-08T02:13:27.696342Z","iopub.status.idle":"2024-11-08T02:13:27.707444Z","shell.execute_reply.started":"2024-11-08T02:13:27.696311Z","shell.execute_reply":"2024-11-08T02:13:27.706476Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"train.head()","metadata":{"execution":{"iopub.status.busy":"2024-11-08T02:13:27.710092Z","iopub.execute_input":"2024-11-08T02:13:27.710843Z","iopub.status.idle":"2024-11-08T02:13:27.755138Z","shell.execute_reply.started":"2024-11-08T02:13:27.710793Z","shell.execute_reply":"2024-11-08T02:13:27.754035Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"train.shape","metadata":{"execution":{"iopub.status.busy":"2024-11-08T02:13:27.756474Z","iopub.execute_input":"2024-11-08T02:13:27.757037Z","iopub.status.idle":"2024-11-08T02:13:27.764198Z","shell.execute_reply.started":"2024-11-08T02:13:27.756998Z","shell.execute_reply":"2024-11-08T02:13:27.763170Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"train.info()","metadata":{"execution":{"iopub.status.busy":"2024-11-08T02:13:27.765425Z","iopub.execute_input":"2024-11-08T02:13:27.765719Z","iopub.status.idle":"2024-11-08T02:13:27.796990Z","shell.execute_reply.started":"2024-11-08T02:13:27.765686Z","shell.execute_reply":"2024-11-08T02:13:27.796005Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"selected_train = train.copy()\nselected_train = selected_train[['Basic_Demos-Enroll_Season', 'Basic_Demos-Age', 'Basic_Demos-Sex','sii']]\nselected_train","metadata":{"execution":{"iopub.status.busy":"2024-11-08T02:13:44.153040Z","iopub.execute_input":"2024-11-08T02:13:44.153436Z","iopub.status.idle":"2024-11-08T02:13:44.172049Z","shell.execute_reply.started":"2024-11-08T02:13:44.153396Z","shell.execute_reply":"2024-11-08T02:13:44.170771Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"selected_test = test.copy()\nselected_test = selected_test[['Basic_Demos-Enroll_Season', 'Basic_Demos-Age', 'Basic_Demos-Sex']]\nselected_test","metadata":{"execution":{"iopub.status.busy":"2024-11-08T02:13:50.930315Z","iopub.execute_input":"2024-11-08T02:13:50.930701Z","iopub.status.idle":"2024-11-08T02:13:50.943720Z","shell.execute_reply.started":"2024-11-08T02:13:50.930665Z","shell.execute_reply":"2024-11-08T02:13:50.942733Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"selected_train.fillna(0, inplace=True)\nselected_train = pd.get_dummies(selected_train, columns=['Basic_Demos-Enroll_Season'])\nselected_train['sii'] = selected_train.pop('sii')\nselected_train","metadata":{"execution":{"iopub.status.busy":"2024-11-08T02:14:06.265025Z","iopub.execute_input":"2024-11-08T02:14:06.265405Z","iopub.status.idle":"2024-11-08T02:14:06.286206Z","shell.execute_reply.started":"2024-11-08T02:14:06.265367Z","shell.execute_reply":"2024-11-08T02:14:06.285164Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"selected_test.fillna(0, inplace=True)\nselected_test = pd.get_dummies(selected_test, columns=['Basic_Demos-Enroll_Season'])\nselected_test","metadata":{"execution":{"iopub.status.busy":"2024-11-08T02:14:18.656740Z","iopub.execute_input":"2024-11-08T02:14:18.657501Z","iopub.status.idle":"2024-11-08T02:14:18.674969Z","shell.execute_reply.started":"2024-11-08T02:14:18.657454Z","shell.execute_reply":"2024-11-08T02:14:18.673799Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"from sklearn.model_selection import train_test_split\nfrom sklearn.preprocessing import MinMaxScaler\nfrom sklearn.linear_model import LogisticRegression\nfrom sklearn.metrics import accuracy_score, classification_report\n\nX = selected_train.drop(columns=['sii'])  \ny = selected_train['sii']  \n\nscaler = MinMaxScaler()\nX = scaler.fit_transform(X)\n\nX_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.3, random_state=42)\n\nmodel = LogisticRegression()\n\nmodel.fit(X_train, y_train)","metadata":{"execution":{"iopub.status.busy":"2024-11-08T02:14:26.061751Z","iopub.execute_input":"2024-11-08T02:14:26.062390Z","iopub.status.idle":"2024-11-08T02:14:26.445980Z","shell.execute_reply.started":"2024-11-08T02:14:26.062348Z","shell.execute_reply":"2024-11-08T02:14:26.444949Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"y_pred = model.predict(X_test)","metadata":{"execution":{"iopub.status.busy":"2024-11-08T02:14:38.363306Z","iopub.execute_input":"2024-11-08T02:14:38.363971Z","iopub.status.idle":"2024-11-08T02:14:38.369132Z","shell.execute_reply.started":"2024-11-08T02:14:38.363929Z","shell.execute_reply":"2024-11-08T02:14:38.367944Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"accuracy = accuracy_score(y_test, y_pred)\nreport = classification_report(y_test, y_pred)\n\nprint(f\"Precision: {accuracy*100}\")\nprint(\"Classification Report:\")\nprint(report)","metadata":{"execution":{"iopub.status.busy":"2024-11-08T02:15:01.689807Z","iopub.execute_input":"2024-11-08T02:15:01.690638Z","iopub.status.idle":"2024-11-08T02:15:01.709468Z","shell.execute_reply.started":"2024-11-08T02:15:01.690591Z","shell.execute_reply":"2024-11-08T02:15:01.708523Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"predictions = model.predict(selected_test).astype(int)\n\npredictions_df = pd.DataFrame({\n    'id': test['id'],  \n    'sii': predictions  \n})\n\npredictions_df","metadata":{"execution":{"iopub.status.busy":"2024-11-08T02:15:10.798742Z","iopub.execute_input":"2024-11-08T02:15:10.799152Z","iopub.status.idle":"2024-11-08T02:15:10.814436Z","shell.execute_reply.started":"2024-11-08T02:15:10.799114Z","shell.execute_reply":"2024-11-08T02:15:10.813356Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"predictions_df.to_csv('/kaggle/working/submission.csv', index=False)","metadata":{"execution":{"iopub.status.busy":"2024-11-08T02:15:21.224331Z","iopub.execute_input":"2024-11-08T02:15:21.225647Z","iopub.status.idle":"2024-11-08T02:15:21.233355Z","shell.execute_reply.started":"2024-11-08T02:15:21.225603Z","shell.execute_reply":"2024-11-08T02:15:21.232243Z"},"trusted":true},"execution_count":null,"outputs":[]}]}