{"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","trusted":true,"_kg_hide-input":false,"_kg_hide-output":true},"outputs":[],"execution_count":null},{"cell_type":"code","source":"'''\nBasic_Demos-Enroll_Season\n등록 계절 / str / Spring, Summer, Fall, Winter\n변수 요약 : 결측 없음, 이상치 없음, 머신러닝에 적합하도록 str->int로 변경, 스케일링 필요 없음\n'''","metadata":{"trusted":true},"outputs":[],"execution_count":null},{"cell_type":"code","source":"train = pd.read_csv('/kaggle/input/child-mind-institute-problematic-internet-use/train.csv')\ntest = pd.read_csv('/kaggle/input/child-mind-institute-problematic-internet-use/test.csv')","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2024-11-25T12:58:54.505642Z","iopub.execute_input":"2024-11-25T12:58:54.506093Z","iopub.status.idle":"2024-11-25T12:58:54.561482Z","shell.execute_reply.started":"2024-11-25T12:58:54.506053Z","shell.execute_reply":"2024-11-25T12:58:54.560633Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"train.info()","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2024-11-25T13:02:07.380612Z","iopub.execute_input":"2024-11-25T13:02:07.381066Z","iopub.status.idle":"2024-11-25T13:02:07.399061Z","shell.execute_reply.started":"2024-11-25T13:02:07.381027Z","shell.execute_reply":"2024-11-25T13:02:07.397863Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"# 1. 이상치\n\nprint(\"이상치 판단 : \",train['Basic_Demos-Enroll_Season'].unique())","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2024-11-25T13:18:59.240700Z","iopub.execute_input":"2024-11-25T13:18:59.241399Z","iopub.status.idle":"2024-11-25T13:18:59.246863Z","shell.execute_reply.started":"2024-11-25T13:18:59.241361Z","shell.execute_reply":"2024-11-25T13:18:59.245824Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"# 2. 결측치\n\nprint(\"결측치 : \",train['Basic_Demos-Enroll_Season'].isnull().sum())","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2024-11-25T13:18:33.253498Z","iopub.execute_input":"2024-11-25T13:18:33.253986Z","iopub.status.idle":"2024-11-25T13:18:33.260027Z","shell.execute_reply.started":"2024-11-25T13:18:33.253931Z","shell.execute_reply":"2024-11-25T13:18:33.258936Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"# 범주형 -> 수치형 변환\n\nfrom sklearn.preprocessing import LabelEncoder\nle = LabelEncoder()\n\n'''\nnew_Basic_Demos-Enroll_Season <카테고리 변수>\n범주형 데이터인 계절 -> 머신러닝에 적합하도록 숫자로 변환\n트리기반 모델을 사용할 것으로 가정하고 순서에 맞게 수동 매핑\nSpring -> 0\nSummer -> 1\nFall -> 2\nWinter -> 3\n'''\n\nseason_mapping = {'Spring':0,'Summer':1,'Fall':2,'Winter':3}\n\ntrain['new_Basic_Demos-Enroll_Season'] = train['Basic_Demos-Enroll_Season'].map(season_mapping)\n\nprint(train['new_Basic_Demos-Enroll_Season'])","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2024-11-25T13:16:59.363340Z","iopub.execute_input":"2024-11-25T13:16:59.364462Z","iopub.status.idle":"2024-11-25T13:16:59.375637Z","shell.execute_reply.started":"2024-11-25T13:16:59.364404Z","shell.execute_reply":"2024-11-25T13:16:59.374398Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"# 4. 스케일링 \n\nprint(train['new_Basic_Demos-Enroll_Season'].value_counts())\nprint(\"모든 범주가 전체 데이터의 약 20~30% 사이에 분포하므로 별도의 스케일링은 필요 없음\")","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2024-11-25T13:21:57.678569Z","iopub.execute_input":"2024-11-25T13:21:57.679051Z","iopub.status.idle":"2024-11-25T13:21:57.686012Z","shell.execute_reply.started":"2024-11-25T13:21:57.679011Z","shell.execute_reply":"2024-11-25T13:21:57.684946Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"import matplotlib.pyplot as plt\n\nvalue_counts = train['new_Basic_Demos-Enroll_Season'].value_counts().sort_index()\n\nplt.figure(figsize=(8,5))\nvalue_counts.plot(kind='bar')\nplt.title('Distribution of enroll season',fontsize=14)\nplt.xlabel('Enroll Season',fontsize=14)\nplt.ylabel('Frequency',fontsize=12)\nplt.xticks(ticks=range(len(value_counts.index)),labels=value_counts.index, fontsize=10)\nplt.yticks(fontsize=10)\nplt.tight_layout()\n\nplt.show()","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2024-11-25T13:27:44.505361Z","iopub.execute_input":"2024-11-25T13:27:44.505768Z","iopub.status.idle":"2024-11-25T13:27:44.720236Z","shell.execute_reply.started":"2024-11-25T13:27:44.505724Z","shell.execute_reply":"2024-11-25T13:27:44.719130Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"# 테스트 df에도 비율상 차이는 없음\n\ntest['Basic_Demos-Enroll_Season']\nprint(test['Basic_Demos-Enroll_Season'].value_counts())","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2024-11-25T13:30:49.113316Z","iopub.execute_input":"2024-11-25T13:30:49.113722Z","iopub.status.idle":"2024-11-25T13:30:49.121299Z","shell.execute_reply.started":"2024-11-25T13:30:49.113685Z","shell.execute_reply":"2024-11-25T13:30:49.119842Z"}},"outputs":[],"execution_count":null}]}