{"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":"# 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","execution":{"iopub.status.busy":"2024-10-27T02:57:17.734747Z","iopub.execute_input":"2024-10-27T02:57:17.735140Z","iopub.status.idle":"2024-10-27T02:57:21.534995Z","shell.execute_reply.started":"2024-10-27T02:57:17.735100Z","shell.execute_reply":"2024-10-27T02:57:21.533623Z"},"trusted":true},"execution_count":null,"outputs":[]},{"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-10-27T02:57:39.784548Z","iopub.execute_input":"2024-10-27T02:57:39.785281Z","iopub.status.idle":"2024-10-27T02:57:40.792783Z","shell.execute_reply.started":"2024-10-27T02:57:39.785210Z","shell.execute_reply":"2024-10-27T02:57:40.791405Z"},"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-10-27T02:58:08.712974Z","iopub.execute_input":"2024-10-27T02:58:08.713447Z","iopub.status.idle":"2024-10-27T02:58:08.805809Z","shell.execute_reply.started":"2024-10-27T02:58:08.713396Z","shell.execute_reply":"2024-10-27T02:58:08.804629Z"},"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-10-27T02:58:27.593437Z","iopub.execute_input":"2024-10-27T02:58:27.593979Z","iopub.status.idle":"2024-10-27T02:58:27.613897Z","shell.execute_reply.started":"2024-10-27T02:58:27.593927Z","shell.execute_reply":"2024-10-27T02:58:27.612410Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"train.head()","metadata":{"execution":{"iopub.status.busy":"2024-10-27T02:58:32.078063Z","iopub.execute_input":"2024-10-27T02:58:32.078638Z","iopub.status.idle":"2024-10-27T02:58:32.133879Z","shell.execute_reply.started":"2024-10-27T02:58:32.078569Z","shell.execute_reply":"2024-10-27T02:58:32.132534Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"train.shape","metadata":{"execution":{"iopub.status.busy":"2024-10-27T02:58:50.960372Z","iopub.execute_input":"2024-10-27T02:58:50.960880Z","iopub.status.idle":"2024-10-27T02:58:50.969995Z","shell.execute_reply.started":"2024-10-27T02:58:50.960834Z","shell.execute_reply":"2024-10-27T02:58:50.968563Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# for i in train.isnull().sum():\n#     print(i)","metadata":{"execution":{"iopub.status.busy":"2024-10-27T02:59:13.461826Z","iopub.execute_input":"2024-10-27T02:59:13.462420Z","iopub.status.idle":"2024-10-27T02:59:13.468648Z","shell.execute_reply.started":"2024-10-27T02:59:13.462367Z","shell.execute_reply":"2024-10-27T02:59:13.466957Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"train.info()","metadata":{"execution":{"iopub.status.busy":"2024-10-27T02:59:33.871786Z","iopub.execute_input":"2024-10-27T02:59:33.873017Z","iopub.status.idle":"2024-10-27T02:59:33.918078Z","shell.execute_reply.started":"2024-10-27T02:59:33.872949Z","shell.execute_reply":"2024-10-27T02:59:33.916514Z"},"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-10-27T03:00:31.903691Z","iopub.execute_input":"2024-10-27T03:00:31.904252Z","iopub.status.idle":"2024-10-27T03:00:31.933927Z","shell.execute_reply.started":"2024-10-27T03:00:31.904181Z","shell.execute_reply":"2024-10-27T03:00:31.931647Z"},"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-10-27T03:00:45.012990Z","iopub.execute_input":"2024-10-27T03:00:45.014284Z","iopub.status.idle":"2024-10-27T03:00:45.029280Z","shell.execute_reply.started":"2024-10-27T03:00:45.014208Z","shell.execute_reply":"2024-10-27T03:00:45.028112Z"},"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-10-27T03:00:54.594732Z","iopub.execute_input":"2024-10-27T03:00:54.595280Z","iopub.status.idle":"2024-10-27T03:00:54.626883Z","shell.execute_reply.started":"2024-10-27T03:00:54.595200Z","shell.execute_reply":"2024-10-27T03:00:54.625362Z"},"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-10-27T03:01:02.574176Z","iopub.execute_input":"2024-10-27T03:01:02.574718Z","iopub.status.idle":"2024-10-27T03:01:02.604339Z","shell.execute_reply.started":"2024-10-27T03:01:02.574657Z","shell.execute_reply":"2024-10-27T03:01:02.602601Z"},"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-10-27T03:01:17.358221Z","iopub.execute_input":"2024-10-27T03:01:17.359834Z","iopub.status.idle":"2024-10-27T03:01:17.875374Z","shell.execute_reply.started":"2024-10-27T03:01:17.359750Z","shell.execute_reply":"2024-10-27T03:01:17.873749Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"y_pred = model.predict(X_test)","metadata":{"execution":{"iopub.status.busy":"2024-10-27T03:01:24.055107Z","iopub.execute_input":"2024-10-27T03:01:24.055676Z","iopub.status.idle":"2024-10-27T03:01:24.063055Z","shell.execute_reply.started":"2024-10-27T03:01:24.055626Z","shell.execute_reply":"2024-10-27T03:01:24.061790Z"},"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\"Precisión: {accuracy*100}\")\nprint(\"Reporte de clasificación:\")\nprint(report)","metadata":{"execution":{"iopub.status.busy":"2024-10-27T03:01:38.943365Z","iopub.execute_input":"2024-10-27T03:01:38.944338Z","iopub.status.idle":"2024-10-27T03:01:38.970215Z","shell.execute_reply.started":"2024-10-27T03:01:38.944271Z","shell.execute_reply":"2024-10-27T03:01:38.968897Z"},"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-10-27T03:02:01.943594Z","iopub.execute_input":"2024-10-27T03:02:01.944121Z","iopub.status.idle":"2024-10-27T03:02:01.963660Z","shell.execute_reply.started":"2024-10-27T03:02:01.944073Z","shell.execute_reply":"2024-10-27T03:02:01.962195Z"},"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-10-27T03:02:14.141658Z","iopub.execute_input":"2024-10-27T03:02:14.142312Z","iopub.status.idle":"2024-10-27T03:02:14.153139Z","shell.execute_reply.started":"2024-10-27T03:02:14.142228Z","shell.execute_reply":"2024-10-27T03:02:14.151747Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"","metadata":{},"execution_count":null,"outputs":[]}]}