{"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-27T18:16:07.520296Z","iopub.execute_input":"2024-10-27T18:16:07.520850Z","iopub.status.idle":"2024-10-27T18:16:08.499066Z","shell.execute_reply.started":"2024-10-27T18:16:07.520790Z","shell.execute_reply":"2024-10-27T18:16:08.497735Z"},"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-27T18:16:08.501610Z","iopub.execute_input":"2024-10-27T18:16:08.501996Z","iopub.status.idle":"2024-10-27T18:16:08.507200Z","shell.execute_reply.started":"2024-10-27T18:16:08.501956Z","shell.execute_reply":"2024-10-27T18:16:08.506055Z"},"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-27T18:16:08.508577Z","iopub.execute_input":"2024-10-27T18:16:08.508989Z","iopub.status.idle":"2024-10-27T18:16:08.567712Z","shell.execute_reply.started":"2024-10-27T18:16:08.508935Z","shell.execute_reply":"2024-10-27T18:16:08.566525Z"},"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-27T18:16:08.569406Z","iopub.execute_input":"2024-10-27T18:16:08.569732Z","iopub.status.idle":"2024-10-27T18:16:08.582746Z","shell.execute_reply.started":"2024-10-27T18:16:08.569697Z","shell.execute_reply":"2024-10-27T18:16:08.581792Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"train.head()","metadata":{"execution":{"iopub.status.busy":"2024-10-27T18:16:08.586082Z","iopub.execute_input":"2024-10-27T18:16:08.586446Z","iopub.status.idle":"2024-10-27T18:16:08.636719Z","shell.execute_reply.started":"2024-10-27T18:16:08.586405Z","shell.execute_reply":"2024-10-27T18:16:08.635630Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"train.shape","metadata":{"execution":{"iopub.status.busy":"2024-10-27T18:16:08.638102Z","iopub.execute_input":"2024-10-27T18:16:08.638435Z","iopub.status.idle":"2024-10-27T18:16:08.645149Z","shell.execute_reply.started":"2024-10-27T18:16:08.638390Z","shell.execute_reply":"2024-10-27T18:16:08.644236Z"},"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-27T18:16:08.646827Z","iopub.execute_input":"2024-10-27T18:16:08.647205Z","iopub.status.idle":"2024-10-27T18:16:08.654813Z","shell.execute_reply.started":"2024-10-27T18:16:08.647166Z","shell.execute_reply":"2024-10-27T18:16:08.653823Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"train.info()","metadata":{"execution":{"iopub.status.busy":"2024-10-27T18:16:08.656413Z","iopub.execute_input":"2024-10-27T18:16:08.656844Z","iopub.status.idle":"2024-10-27T18:16:08.699472Z","shell.execute_reply.started":"2024-10-27T18:16:08.656791Z","shell.execute_reply":"2024-10-27T18:16:08.698377Z"},"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-27T18:16:08.701012Z","iopub.execute_input":"2024-10-27T18:16:08.701821Z","iopub.status.idle":"2024-10-27T18:16:08.721141Z","shell.execute_reply.started":"2024-10-27T18:16:08.701744Z","shell.execute_reply":"2024-10-27T18:16:08.719814Z"},"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-27T18:16:08.722482Z","iopub.execute_input":"2024-10-27T18:16:08.722846Z","iopub.status.idle":"2024-10-27T18:16:08.739060Z","shell.execute_reply.started":"2024-10-27T18:16:08.722807Z","shell.execute_reply":"2024-10-27T18:16:08.737905Z"},"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-27T18:16:08.740844Z","iopub.execute_input":"2024-10-27T18:16:08.741331Z","iopub.status.idle":"2024-10-27T18:16:08.767578Z","shell.execute_reply.started":"2024-10-27T18:16:08.741279Z","shell.execute_reply":"2024-10-27T18:16:08.766486Z"},"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-27T18:16:08.768885Z","iopub.execute_input":"2024-10-27T18:16:08.769190Z","iopub.status.idle":"2024-10-27T18:16:08.788500Z","shell.execute_reply.started":"2024-10-27T18:16:08.769154Z","shell.execute_reply":"2024-10-27T18:16:08.787403Z"},"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-27T18:16:08.789776Z","iopub.execute_input":"2024-10-27T18:16:08.790133Z","iopub.status.idle":"2024-10-27T18:16:09.159780Z","shell.execute_reply.started":"2024-10-27T18:16:08.790094Z","shell.execute_reply":"2024-10-27T18:16:09.158720Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"y_pred = model.predict(X_test)","metadata":{"execution":{"iopub.status.busy":"2024-10-27T18:16:09.164245Z","iopub.execute_input":"2024-10-27T18:16:09.164580Z","iopub.status.idle":"2024-10-27T18:16:09.169843Z","shell.execute_reply.started":"2024-10-27T18:16:09.164542Z","shell.execute_reply":"2024-10-27T18:16:09.168644Z"},"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-27T18:16:09.171408Z","iopub.execute_input":"2024-10-27T18:16:09.171881Z","iopub.status.idle":"2024-10-27T18:16:09.198100Z","shell.execute_reply.started":"2024-10-27T18:16:09.171840Z","shell.execute_reply":"2024-10-27T18:16:09.197064Z"},"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-27T18:16:09.199412Z","iopub.execute_input":"2024-10-27T18:16:09.199717Z","iopub.status.idle":"2024-10-27T18:16:09.217629Z","shell.execute_reply.started":"2024-10-27T18:16:09.199683Z","shell.execute_reply":"2024-10-27T18:16:09.216524Z"},"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-27T18:16:09.219250Z","iopub.execute_input":"2024-10-27T18:16:09.219685Z","iopub.status.idle":"2024-10-27T18:16:09.227976Z","shell.execute_reply.started":"2024-10-27T18:16:09.219633Z","shell.execute_reply":"2024-10-27T18:16:09.227045Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"","metadata":{},"execution_count":null,"outputs":[]}]}