{"metadata":{"kernelspec":{"language":"python","display_name":"Python 3","name":"python3"},"language_info":{"pygments_lexer":"ipython3","nbconvert_exporter":"python","version":"3.6.4","file_extension":".py","codemirror_mode":{"name":"ipython","version":3},"name":"python","mimetype":"text/x-python"}},"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 pandas as pd # data processing, CSV file I/O (e.g. pd.read_csv)\nimport numpy as np # linear algebra\nimport matplotlib.pyplot as plt\nimport seaborn as sns\nfrom sklearn.ensemble import RandomForestClassifier\n%matplotlib inline\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\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":"2022-07-18T14:15:40.858252Z","iopub.execute_input":"2022-07-18T14:15:40.859129Z","iopub.status.idle":"2022-07-18T14:15:42.597049Z","shell.execute_reply.started":"2022-07-18T14:15:40.859004Z","shell.execute_reply":"2022-07-18T14:15:42.595816Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"import pandas as pd\nsubmission = pd.read_csv('/kaggle/input/titanic/gender_submission.csv')\nsubmission\n\nsubmission.to_csv('submission.csv', index=False)","metadata":{"execution":{"iopub.status.busy":"2022-07-18T14:17:18.508227Z","iopub.execute_input":"2022-07-18T14:17:18.509278Z","iopub.status.idle":"2022-07-18T14:17:18.530933Z","shell.execute_reply.started":"2022-07-18T14:17:18.509239Z","shell.execute_reply":"2022-07-18T14:17:18.530117Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"import seaborn as sns\n\ntitanic = sns.load_dataset('titanic')\ntitanic.head()","metadata":{"execution":{"iopub.status.busy":"2022-07-18T14:18:27.141062Z","iopub.execute_input":"2022-07-18T14:18:27.141469Z","iopub.status.idle":"2022-07-18T14:18:28.339216Z","shell.execute_reply.started":"2022-07-18T14:18:27.141436Z","shell.execute_reply":"2022-07-18T14:18:28.338086Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"import seaborn as sns\n\ntitanic = sns.load_dataset('titanic')\nsns.histplot(data=titanic, x='age', hue='alive', multiple='stack');","metadata":{"execution":{"iopub.status.busy":"2022-07-14T14:02:35.341075Z","iopub.execute_input":"2022-07-14T14:02:35.341455Z","iopub.status.idle":"2022-07-14T14:02:35.669532Z","shell.execute_reply.started":"2022-07-14T14:02:35.341415Z","shell.execute_reply":"2022-07-14T14:02:35.6682Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"import seaborn as sns\n\ntitanic = sns.load_dataset('titanic')\nsns.kdeplot(data=titanic, x='age', hue='alive', multiple='stack')","metadata":{"execution":{"iopub.status.busy":"2022-07-14T14:02:35.670884Z","iopub.execute_input":"2022-07-14T14:02:35.67122Z","iopub.status.idle":"2022-07-14T14:02:35.882299Z","shell.execute_reply.started":"2022-07-14T14:02:35.671192Z","shell.execute_reply":"2022-07-14T14:02:35.881078Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"import seaborn as sns\n\ntitanic = sns.load_dataset('titanic')\nsns.displot(data=titanic, x='age')","metadata":{"execution":{"iopub.status.busy":"2022-07-14T14:02:35.884167Z","iopub.execute_input":"2022-07-14T14:02:35.884498Z","iopub.status.idle":"2022-07-14T14:02:36.16489Z","shell.execute_reply.started":"2022-07-14T14:02:35.884458Z","shell.execute_reply":"2022-07-14T14:02:36.164021Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"import seaborn as sns\n\ntitanic = sns.load_dataset('titanic')\nsns.displot(data=titanic, x='age', kind='kde')","metadata":{"execution":{"iopub.status.busy":"2022-07-14T14:02:36.166207Z","iopub.execute_input":"2022-07-14T14:02:36.167329Z","iopub.status.idle":"2022-07-14T14:02:36.401343Z","shell.execute_reply.started":"2022-07-14T14:02:36.16729Z","shell.execute_reply":"2022-07-14T14:02:36.400018Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"import seaborn as sns\n\ntitanic = sns.load_dataset('titanic')\nsns.displot(data=titanic, x='age', kde = True)","metadata":{"execution":{"iopub.status.busy":"2022-07-14T14:02:36.402865Z","iopub.execute_input":"2022-07-14T14:02:36.403153Z","iopub.status.idle":"2022-07-14T14:02:36.728064Z","shell.execute_reply.started":"2022-07-14T14:02:36.403126Z","shell.execute_reply":"2022-07-14T14:02:36.726984Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"import seaborn as sns\n\ntitanic = sns.load_dataset('titanic')\nsns.kdeplot(data=titanic, x='age')\nsns.rugplot(data=titanic, x='age')","metadata":{"execution":{"iopub.status.busy":"2022-07-14T14:02:36.72937Z","iopub.execute_input":"2022-07-14T14:02:36.730266Z","iopub.status.idle":"2022-07-14T14:02:36.902693Z","shell.execute_reply.started":"2022-07-14T14:02:36.730233Z","shell.execute_reply":"2022-07-14T14:02:36.902015Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"https://blog.daum.net/tlos6733/136","metadata":{}},{"cell_type":"code","source":"import seaborn as sns\n\ntitanic = sns.load_dataset('titanic')\nsns.barplot(x='class', y='fare', data=titanic); #평균값","metadata":{"execution":{"iopub.status.busy":"2022-07-14T14:12:54.411607Z","iopub.execute_input":"2022-07-14T14:12:54.411906Z","iopub.status.idle":"2022-07-14T14:12:54.591223Z","shell.execute_reply.started":"2022-07-14T14:12:54.411884Z","shell.execute_reply":"2022-07-14T14:12:54.589951Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"import seaborn as sns\n\ntitanic = sns.load_dataset('titanic')\nsns.barplot(x='class', y='fare', data=titanic, estimator=np.median); #중앙값","metadata":{"execution":{"iopub.status.busy":"2022-07-14T14:29:08.835872Z","iopub.execute_input":"2022-07-14T14:29:08.836201Z","iopub.status.idle":"2022-07-14T14:29:09.110211Z","shell.execute_reply.started":"2022-07-14T14:29:08.836177Z","shell.execute_reply":"2022-07-14T14:29:09.109317Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"import seaborn as sns\n\ntitanic = sns.load_dataset('titanic')\nsns.barplot(x='class', y='fare', data=titanic, estimator=np.max); #최댓값","metadata":{"execution":{"iopub.status.busy":"2022-07-14T14:29:41.28251Z","iopub.execute_input":"2022-07-14T14:29:41.282852Z","iopub.status.idle":"2022-07-14T14:29:41.459345Z","shell.execute_reply.started":"2022-07-14T14:29:41.282824Z","shell.execute_reply":"2022-07-14T14:29:41.458633Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"import seaborn as sns\n\ntitanic = sns.load_dataset('titanic')\nsns.barplot(x='class', y='fare', data=titanic, estimator=np.min); #최솟값","metadata":{"execution":{"iopub.status.busy":"2022-07-14T14:30:22.272712Z","iopub.execute_input":"2022-07-14T14:30:22.273024Z","iopub.status.idle":"2022-07-14T14:30:22.479123Z","shell.execute_reply.started":"2022-07-14T14:30:22.272992Z","shell.execute_reply":"2022-07-14T14:30:22.478128Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"import seaborn as sns\n\ntitanic = sns.load_dataset('titanic')\nsns.pointplot(x='class', y='fare', data=titanic);","metadata":{"execution":{"iopub.status.busy":"2022-07-14T14:13:44.723817Z","iopub.execute_input":"2022-07-14T14:13:44.724211Z","iopub.status.idle":"2022-07-14T14:13:44.898934Z","shell.execute_reply.started":"2022-07-14T14:13:44.724181Z","shell.execute_reply":"2022-07-14T14:13:44.898241Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"여러 그래프를 한 화면에 그려서 비교하는 경우\n-> 아래쪽에 그린 포인트플롯이 막대그래프에 비해 유리","metadata":{}},{"cell_type":"code","source":"import seaborn as sns\n\ntitanic = sns.load_dataset('titanic')\nsns.boxplot(x='class', y='age', data=titanic)","metadata":{"execution":{"iopub.status.busy":"2022-07-14T14:19:00.688526Z","iopub.execute_input":"2022-07-14T14:19:00.688838Z","iopub.status.idle":"2022-07-14T14:19:00.83221Z","shell.execute_reply.started":"2022-07-14T14:19:00.688815Z","shell.execute_reply":"2022-07-14T14:19:00.831151Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"import seaborn as sns\n\ntitanic = sns.load_dataset('titanic')\nsns.violinplot(x='class', y='age', data=titanic);","metadata":{"execution":{"iopub.status.busy":"2022-07-14T14:21:55.929886Z","iopub.execute_input":"2022-07-14T14:21:55.930273Z","iopub.status.idle":"2022-07-14T14:21:56.074764Z","shell.execute_reply.started":"2022-07-14T14:21:55.930243Z","shell.execute_reply":"2022-07-14T14:21:56.073734Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"import seaborn as sns\n\ntitanic = sns.load_dataset('titanic')\nsns.violinplot(x='class', y='age', hue='sex', data=titanic, split=True);","metadata":{"execution":{"iopub.status.busy":"2022-07-14T14:22:44.688381Z","iopub.execute_input":"2022-07-14T14:22:44.688724Z","iopub.status.idle":"2022-07-14T14:22:44.873916Z","shell.execute_reply.started":"2022-07-14T14:22:44.6887Z","shell.execute_reply":"2022-07-14T14:22:44.872989Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"import seaborn as sns\n\ntitanic = sns.load_dataset('titanic')\nsns.countplot(x='class', data=titanic);","metadata":{"execution":{"iopub.status.busy":"2022-07-14T14:24:15.871473Z","iopub.execute_input":"2022-07-14T14:24:15.871822Z","iopub.status.idle":"2022-07-14T14:24:15.970415Z","shell.execute_reply.started":"2022-07-14T14:24:15.871796Z","shell.execute_reply":"2022-07-14T14:24:15.969Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"import seaborn as sns\n\ntitanic = sns.load_dataset('titanic')\nsns.countplot(y='class', data=titanic);","metadata":{"execution":{"iopub.status.busy":"2022-07-14T14:24:48.132128Z","iopub.execute_input":"2022-07-14T14:24:48.132451Z","iopub.status.idle":"2022-07-14T14:24:48.260338Z","shell.execute_reply.started":"2022-07-14T14:24:48.1324Z","shell.execute_reply":"2022-07-14T14:24:48.259334Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"카운트플롯은 기본적으로 하나의 파라미터에 대한 csv의 기본값(모든 파라밑에 대해 인원수를 나타내는 csv라면 인원수)을 나타내줌.\n하지만 바플롯은 두 개의 파라미터간의 관계를 보여주기 때문에 파라미터 두 개 입력","metadata":{}},{"cell_type":"code","source":"import seaborn as sns\nimport matplotlib.pyplot as plt\n\ntitanic = sns.load_dataset('titanic')\nx = [10, 60, 30]\nlabels = ['A', 'B', 'C']\n          \nplt.pie(x=x, labels=labels, autopct='%.1f%%');\n","metadata":{"execution":{"iopub.status.busy":"2022-07-14T14:06:16.142843Z","iopub.execute_input":"2022-07-14T14:06:16.143132Z","iopub.status.idle":"2022-07-14T14:06:16.242317Z","shell.execute_reply.started":"2022-07-14T14:06:16.143108Z","shell.execute_reply":"2022-07-14T14:06:16.241407Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"import seaborn as sns\n\nflights = sns.load_dataset('flights')","metadata":{"execution":{"iopub.status.busy":"2022-07-14T14:34:07.361099Z","iopub.execute_input":"2022-07-14T14:34:07.361386Z","iopub.status.idle":"2022-07-14T14:34:07.370787Z","shell.execute_reply.started":"2022-07-14T14:34:07.361363Z","shell.execute_reply":"2022-07-14T14:34:07.369843Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"flights.head()","metadata":{"execution":{"iopub.status.busy":"2022-07-14T14:34:03.31363Z","iopub.execute_input":"2022-07-14T14:34:03.313982Z","iopub.status.idle":"2022-07-14T14:34:03.324104Z","shell.execute_reply.started":"2022-07-14T14:34:03.313953Z","shell.execute_reply":"2022-07-14T14:34:03.323472Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"연도의 월별 승객 수를 알기 위해서 달을 행으로, 연을 열로, 합산할 데이터를 승객 수로 지정하기","metadata":{}},{"cell_type":"code","source":"flights_pivot = flights.pivot(index='month', \n                            columns = 'year', \n                            values='passengers')\nflights_pivot","metadata":{"execution":{"iopub.status.busy":"2022-07-14T14:37:37.533941Z","iopub.execute_input":"2022-07-14T14:37:37.534357Z","iopub.status.idle":"2022-07-14T14:37:37.555697Z","shell.execute_reply.started":"2022-07-14T14:37:37.534327Z","shell.execute_reply":"2022-07-14T14:37:37.554486Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"추이를 더 쉽게 파악하기 위해서는 히트맵으로 표현","metadata":{}},{"cell_type":"code","source":"sns.heatmap(data=flights_pivot)","metadata":{"execution":{"iopub.status.busy":"2022-07-14T14:38:57.525216Z","iopub.execute_input":"2022-07-14T14:38:57.52556Z","iopub.status.idle":"2022-07-14T14:38:57.762893Z","shell.execute_reply.started":"2022-07-14T14:38:57.525535Z","shell.execute_reply":"2022-07-14T14:38:57.76209Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"두 데이터 간의 관계는 라인플롯으로","metadata":{}},{"cell_type":"code","source":"sns.lineplot(x='year', y='passengers', data=flights);","metadata":{"execution":{"iopub.status.busy":"2022-07-14T14:40:16.802337Z","iopub.execute_input":"2022-07-14T14:40:16.802682Z","iopub.status.idle":"2022-07-14T14:40:17.153166Z","shell.execute_reply.started":"2022-07-14T14:40:16.802658Z","shell.execute_reply":"2022-07-14T14:40:17.152471Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"tips = sns.load_dataset('tips')\ntips.head","metadata":{"execution":{"iopub.status.busy":"2022-07-14T14:45:18.400203Z","iopub.execute_input":"2022-07-14T14:45:18.4006Z","iopub.status.idle":"2022-07-14T14:45:18.867589Z","shell.execute_reply.started":"2022-07-14T14:45:18.40057Z","shell.execute_reply":"2022-07-14T14:45:18.865945Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"sns.scatterplot(x='total_bill', y='tip', data=tips);","metadata":{"execution":{"iopub.status.busy":"2022-07-14T14:45:30.924659Z","iopub.execute_input":"2022-07-14T14:45:30.924972Z","iopub.status.idle":"2022-07-14T14:45:31.071911Z","shell.execute_reply.started":"2022-07-14T14:45:30.924949Z","shell.execute_reply":"2022-07-14T14:45:31.070854Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"sns.scatterplot(x='total_bill', y='tip', hue='time', data=tips)","metadata":{"execution":{"iopub.status.busy":"2022-07-14T14:46:14.221009Z","iopub.execute_input":"2022-07-14T14:46:14.221314Z","iopub.status.idle":"2022-07-14T14:46:14.405681Z","shell.execute_reply.started":"2022-07-14T14:46:14.221292Z","shell.execute_reply":"2022-07-14T14:46:14.404393Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"sns.regplot(x='total_bill', y='tip', data=tips);","metadata":{"execution":{"iopub.status.busy":"2022-07-14T14:47:54.318861Z","iopub.execute_input":"2022-07-14T14:47:54.319267Z","iopub.status.idle":"2022-07-14T14:47:54.55188Z","shell.execute_reply.started":"2022-07-14T14:47:54.319237Z","shell.execute_reply":"2022-07-14T14:47:54.550552Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"sns.regplot(x='total_bill', y='tip',ci=99, data=tips);","metadata":{"execution":{"iopub.status.busy":"2022-07-14T14:48:11.338206Z","iopub.execute_input":"2022-07-14T14:48:11.338545Z","iopub.status.idle":"2022-07-14T14:48:11.550263Z","shell.execute_reply.started":"2022-07-14T14:48:11.33852Z","shell.execute_reply":"2022-07-14T14:48:11.549573Z"},"trusted":true},"execution_count":null,"outputs":[]}]}