{"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":"markdown","source":"# 주요 명령어 \n\n\njupiter notebook shortcuts\n\n\n셀 실행 : ctrl+Enter/shift+Enter\n\n\nEsc + b(↓) \n\n\nEsc + a(↑)\n\n\nEsc + d,d(x) / Esc + x\n\nEsc + m , Esc + y","metadata":{}},{"cell_type":"markdown","source":"# 주요 시각화 그래프","metadata":{}},{"cell_type":"markdown","source":"# 4.3 수치형 데이터 시각화 ","metadata":{}},{"cell_type":"code","source":"# titanic dataset 확인\n# pclass? parch? embarked? alone??\n\nimport seaborn as sns \n\ntitanic = sns.load_dataset('titanic')\ntitanic.head()","metadata":{"execution":{"iopub.status.busy":"2022-07-16T09:26:55.996306Z","iopub.execute_input":"2022-07-16T09:26:55.996847Z","iopub.status.idle":"2022-07-16T09:26:56.034447Z","shell.execute_reply.started":"2022-07-16T09:26:55.996791Z","shell.execute_reply":"2022-07-16T09:26:56.033000Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# 히스토그램이란? 구간별 빈도수 \n\nimport seaborn as sns\n\ntitanic=sns.load_dataset('titanic')\nsns.histplot(data=titanic, x='age')","metadata":{"execution":{"iopub.status.busy":"2022-07-16T08:00:39.210758Z","iopub.execute_input":"2022-07-16T08:00:39.211792Z","iopub.status.idle":"2022-07-16T08:00:39.506940Z","shell.execute_reply.started":"2022-07-16T08:00:39.211747Z","shell.execute_reply":"2022-07-16T08:00:39.505638Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# 히스토그램에서 구간은 자동으로 20구간임. 수정하고 싶다면? bins\n\nimport seaborn as sns\n\ntitanic=sns.load_dataset('titanic')\nsns.histplot(data=titanic, x='age', bins=10)","metadata":{"execution":{"iopub.status.busy":"2022-07-16T08:02:05.181561Z","iopub.execute_input":"2022-07-16T08:02:05.182007Z","iopub.status.idle":"2022-07-16T08:02:05.444909Z","shell.execute_reply.started":"2022-07-16T08:02:05.181952Z","shell.execute_reply":"2022-07-16T08:02:05.443544Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# hue는 뭐의 약자인지.. \n# 하여간 범주별로 구분하고 싶다면 \n\n\nimport seaborn as sns\n\ntitanic=sns.load_dataset('titanic')\nsns.histplot(data=titanic, x='age', bins=10, hue='alive');","metadata":{"execution":{"iopub.status.busy":"2022-07-16T08:03:53.472738Z","iopub.execute_input":"2022-07-16T08:03:53.473183Z","iopub.status.idle":"2022-07-16T08:03:53.757200Z","shell.execute_reply.started":"2022-07-16T08:03:53.473145Z","shell.execute_reply":"2022-07-16T08:03:53.756014Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# 범주별로 겹치게 구분한거를 깔끔하게 표시하고 싶다면 \nimport seaborn as sns\n\ntitanic=sns.load_dataset('titanic')\nsns.histplot(data=titanic, x='age', bins=10, hue='alive', multiple='stack');","metadata":{"execution":{"iopub.status.busy":"2022-07-16T08:12:40.984635Z","iopub.execute_input":"2022-07-16T08:12:40.985151Z","iopub.status.idle":"2022-07-16T08:12:41.284190Z","shell.execute_reply.started":"2022-07-16T08:12:40.985115Z","shell.execute_reply":"2022-07-16T08:12:41.283017Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# 커널밀도 추정함수 \n\n# 확률밀도 : 그 값을 가질 상대적인 가능성 \n# 커널밀도는 그 중에서도 원정음 중심으로 대칭이면서 적분값이 1이 나오는 뭐라구!??@\n\nimport 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-16T08:13:26.090443Z","iopub.execute_input":"2022-07-16T08:13:26.090841Z","iopub.status.idle":"2022-07-16T08:13:26.333038Z","shell.execute_reply.started":"2022-07-16T08:13:26.090806Z","shell.execute_reply":"2022-07-16T08:13:26.331906Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# 분포도\n\n\nimport seaborn as sns\n\ntitanic=sns.load_dataset('titanic')\nsns.displot(data=titanic, x='age')","metadata":{"execution":{"iopub.status.busy":"2022-07-16T09:35:31.024932Z","iopub.execute_input":"2022-07-16T09:35:31.025305Z","iopub.status.idle":"2022-07-16T09:35:31.306779Z","shell.execute_reply.started":"2022-07-16T09:35:31.025275Z","shell.execute_reply":"2022-07-16T09:35:31.306014Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# 히스토그램과 커널밀도함수를 동시에 그릴 수 도 있음. \n# 그럼 kdeplot안에다가 dis=True를 넣어도 되나?? \n# 답 ; sns.kdeplot 속성에는 dis 속성이 없음요 \n\n\nimport seaborn as sns\n\ntitanic=sns.load_dataset('titanic')\nsns.displot(data=titanic, x='age', kde=True);","metadata":{"execution":{"iopub.status.busy":"2022-07-16T08:20:23.679024Z","iopub.execute_input":"2022-07-16T08:20:23.679993Z","iopub.status.idle":"2022-07-16T08:20:24.006908Z","shell.execute_reply.started":"2022-07-16T08:20:23.679952Z","shell.execute_reply":"2022-07-16T08:20:24.005773Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"","metadata":{},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# 러그플롯 함수 \n# 단일피처가 어떻게 분포되어 있는지 작은 선분으로 표시 \n# 값이 밀집되어 있을 수록 작은 선분도 밀집 \nimport 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-16T08:21:38.067085Z","iopub.execute_input":"2022-07-16T08:21:38.067456Z","iopub.status.idle":"2022-07-16T08:21:38.318654Z","shell.execute_reply.started":"2022-07-16T08:21:38.067426Z","shell.execute_reply":"2022-07-16T08:21:38.317780Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"# 4.4 범주형 데이터 시각화 ","metadata":{}},{"cell_type":"code","source":"# 막대그래프 \n\nimport seaborn as sns\n\ntitanic=sns.load_dataset('titanic')\n\nsns.barplot(x='class', y='fare', data=titanic)","metadata":{"execution":{"iopub.status.busy":"2022-07-16T08:23:26.300453Z","iopub.execute_input":"2022-07-16T08:23:26.300826Z","iopub.status.idle":"2022-07-16T08:23:26.594303Z","shell.execute_reply.started":"2022-07-16T08:23:26.300795Z","shell.execute_reply":"2022-07-16T08:23:26.592961Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# 포인트 플롯 : 비교를 위해 여러그래프를 한 화면에 표현할 때 \n\nimport seaborn as sns\n\ntitanic=sns.load_dataset('titanic')\n\nsns.pointplot(x='class', y='fare', data=titanic)","metadata":{"execution":{"iopub.status.busy":"2022-07-16T08:56:48.526694Z","iopub.execute_input":"2022-07-16T08:56:48.527094Z","iopub.status.idle":"2022-07-16T08:56:48.812141Z","shell.execute_reply.started":"2022-07-16T08:56:48.527054Z","shell.execute_reply":"2022-07-16T08:56:48.811012Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# 박스 플롯 \n\nimport seaborn as sns\n\ntitanic=sns.load_dataset('titanic')\n\nsns.boxplot(x='class', y='age', data=titanic)","metadata":{"execution":{"iopub.status.busy":"2022-07-16T08:57:39.786601Z","iopub.execute_input":"2022-07-16T08:57:39.787015Z","iopub.status.idle":"2022-07-16T08:57:39.998983Z","shell.execute_reply.started":"2022-07-16T08:57:39.786978Z","shell.execute_reply":"2022-07-16T08:57:39.997837Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# 바이올린 플롯 \n# 예쁨!\n\nimport seaborn as sns\n\ntitanic=sns.load_dataset('titanic')\n\nsns.violinplot(x='class', y='age', data=titanic)","metadata":{"execution":{"iopub.status.busy":"2022-07-16T08:58:09.096373Z","iopub.execute_input":"2022-07-16T08:58:09.096775Z","iopub.status.idle":"2022-07-16T08:58:09.308889Z","shell.execute_reply.started":"2022-07-16T08:58:09.096741Z","shell.execute_reply":"2022-07-16T08:58:09.307908Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# 더 예뻐짐\n# 속성 순서는 상관없나봄\n\nimport seaborn as sns\n\ntitanic=sns.load_dataset('titanic')\n\nsns.violinplot(x='class', y='age', hue='sex', split=True, data=titanic)","metadata":{"execution":{"iopub.status.busy":"2022-07-16T09:01:06.235082Z","iopub.execute_input":"2022-07-16T09:01:06.236110Z","iopub.status.idle":"2022-07-16T09:01:06.500681Z","shell.execute_reply.started":"2022-07-16T09:01:06.236069Z","shell.execute_reply":"2022-07-16T09:01:06.499685Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"#카운트 플롯 \n\nimport seaborn as sns\n\ntitanic=sns.load_dataset('titanic')\n\nsns.countplot(x='class',data=titanic)","metadata":{"execution":{"iopub.status.busy":"2022-07-16T09:01:31.231898Z","iopub.execute_input":"2022-07-16T09:01:31.232282Z","iopub.status.idle":"2022-07-16T09:01:31.397635Z","shell.execute_reply.started":"2022-07-16T09:01:31.232253Z","shell.execute_reply":"2022-07-16T09:01:31.396507Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"import seaborn as sns\n\ntitanic=sns.load_dataset('titanic')\n\nsns.countplot(y='class',data=titanic)","metadata":{"execution":{"iopub.status.busy":"2022-07-16T09:01:59.024277Z","iopub.execute_input":"2022-07-16T09:01:59.024684Z","iopub.status.idle":"2022-07-16T09:01:59.195291Z","shell.execute_reply.started":"2022-07-16T09:01:59.024649Z","shell.execute_reply":"2022-07-16T09:01:59.194121Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# 파이그래프 \n\nimport matplotlib.pyplot as plt\n\nx=[10,60,30]\nlabels = ['A', 'B', 'C']\n\nplt.pie(x=x, labels=labels, autopct='%.1f%%')","metadata":{"execution":{"iopub.status.busy":"2022-07-16T09:06:01.162580Z","iopub.execute_input":"2022-07-16T09:06:01.162984Z","iopub.status.idle":"2022-07-16T09:06:01.262967Z","shell.execute_reply.started":"2022-07-16T09:06:01.162946Z","shell.execute_reply":"2022-07-16T09:06:01.261516Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"# 4.5 데이터 관계 시각화 ","metadata":{}},{"cell_type":"code","source":"# flight 데이터셋 확인 \n\nimport seaborn as sns\n\nflights=sns.load_dataset('flights')\nflights.head()\n","metadata":{"execution":{"iopub.status.busy":"2022-07-16T09:09:01.367693Z","iopub.execute_input":"2022-07-16T09:09:01.368062Z","iopub.status.idle":"2022-07-16T09:09:01.384125Z","shell.execute_reply.started":"2022-07-16T09:09:01.368032Z","shell.execute_reply":"2022-07-16T09:09:01.382539Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"#뒤집기.. 근데 안됨!! 교재 98쪽이랑 다른 모양임.. 뭐자? \nimport seaborn as sns\n\nflights=sns.load_dataset('flights')\nflights.head()\n\nflights_pivot = flights.pivot(index='month', columns='year', values='passengers')\nflights.pivot","metadata":{"execution":{"iopub.status.busy":"2022-07-16T09:10:07.605255Z","iopub.execute_input":"2022-07-16T09:10:07.605677Z","iopub.status.idle":"2022-07-16T09:10:07.624365Z","shell.execute_reply.started":"2022-07-16T09:10:07.605642Z","shell.execute_reply":"2022-07-16T09:10:07.623564Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"#히트맵\n#체고예쁘네\n\n\nimport seaborn as sns\n\nflights=sns.load_dataset('flights')\nflights.head()\n\nflights_pivot = flights.pivot(index='month', columns='year', values='passengers')\nsns.heatmap(data = flights_pivot)","metadata":{"execution":{"iopub.status.busy":"2022-07-16T09:11:56.757815Z","iopub.execute_input":"2022-07-16T09:11:56.758240Z","iopub.status.idle":"2022-07-16T09:11:57.086387Z","shell.execute_reply.started":"2022-07-16T09:11:56.758207Z","shell.execute_reply":"2022-07-16T09:11:57.085291Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# 라인플롯 \n# 두 수치형 데이터 사이의 관계를 나타낼 때 \n# 95% 신뢰구간 (x 값에 따라 y값에 전달한 값의 평균)\n\n# 아래그래프에서 해가 갈수록 승객수가 늘어난다고 볼 수 있음.\n\nimport seaborn as sns\n\nflights=sns.load_dataset('flights')\nflights.head()\n\nflights_pivot = flights.pivot(index='month', columns='year', values='passengers')\n\nsns.lineplot(x='year', y='passengers', data = flights)","metadata":{"execution":{"iopub.status.busy":"2022-07-16T09:13:50.759362Z","iopub.execute_input":"2022-07-16T09:13:50.759742Z","iopub.status.idle":"2022-07-16T09:13:51.266258Z","shell.execute_reply.started":"2022-07-16T09:13:50.759711Z","shell.execute_reply":"2022-07-16T09:13:51.265190Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"import seaborn as sns\n\nflights=sns.load_dataset('flights')\nflights.head()\n\nflights_pivot = flights.pivot(index='month', columns='year', values='passengers')\ntips=sns.load_dataset('tips')\n\ntips.head()","metadata":{"execution":{"iopub.status.busy":"2022-07-16T09:14:42.274381Z","iopub.execute_input":"2022-07-16T09:14:42.275525Z","iopub.status.idle":"2022-07-16T09:14:42.304634Z","shell.execute_reply.started":"2022-07-16T09:14:42.275486Z","shell.execute_reply":"2022-07-16T09:14:42.303263Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# 산점도 \n\n# 관계를 점으로 표현\n# 지불 총액이 늘면 팁도 느나봄 (50달러 먹고 2달러 팁 내면 양아치지)\n\n\nimport seaborn as sns\n\nflights=sns.load_dataset('flights')\nflights.head()\n\nflights_pivot = flights.pivot(index='month', columns='year', values='passengers')\ntips=sns.load_dataset('tips')\n\nsns.scatterplot(x='total_bill', y='tip', data=tips)","metadata":{"execution":{"iopub.status.busy":"2022-07-16T09:15:32.050224Z","iopub.execute_input":"2022-07-16T09:15:32.050596Z","iopub.status.idle":"2022-07-16T09:15:32.248984Z","shell.execute_reply.started":"2022-07-16T09:15:32.050567Z","shell.execute_reply":"2022-07-16T09:15:32.247868Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# 점심손님이 팁을 조금 줄 줄 알았는데 팀 조금 주는 손님은 저녁손님이 더 많네 .. 개체수가 많아서 그렇게 보이는건가...\n\n\nimport seaborn as sns\n\nflights=sns.load_dataset('flights')\nflights.head()\n\nflights_pivot = flights.pivot(index='month', columns='year', values='passengers')\ntips=sns.load_dataset('tips')\n\nsns.scatterplot(x='total_bill', y='tip', hue='time' ,data=tips)","metadata":{"execution":{"iopub.status.busy":"2022-07-16T09:15:57.586316Z","iopub.execute_input":"2022-07-16T09:15:57.586722Z","iopub.status.idle":"2022-07-16T09:15:57.852169Z","shell.execute_reply.started":"2022-07-16T09:15:57.586690Z","shell.execute_reply":"2022-07-16T09:15:57.850991Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"import seaborn as sns\n\nflights=sns.load_dataset('flights')\nflights.head()\n\nflights_pivot = flights.pivot(index='month', columns='year', values='passengers')\ntips=sns.load_dataset('tips')\n\nsns.regplot(x='total_bill', y = 'tip', data=tips)","metadata":{"execution":{"iopub.status.busy":"2022-07-16T09:16:46.707292Z","iopub.execute_input":"2022-07-16T09:16:46.707699Z","iopub.status.idle":"2022-07-16T09:16:47.019691Z","shell.execute_reply.started":"2022-07-16T09:16:46.707666Z","shell.execute_reply":"2022-07-16T09:16:47.018615Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# 상관관계 파악을 위한 \n# 회귀선을 포함한 산점도 import seaborn as sns\n\nflights=sns.load_dataset('flights')\nflights.head()\n\nflights_pivot = flights.pivot(index='month', columns='year', values='passengers')\ntips=sns.load_dataset('tips')\n\nsns.regplot(x='total_bill', y = 'tip', ci=99, data=tips)","metadata":{"execution":{"iopub.status.busy":"2022-07-16T09:17:05.975915Z","iopub.execute_input":"2022-07-16T09:17:05.977058Z","iopub.status.idle":"2022-07-16T09:17:06.272134Z","shell.execute_reply.started":"2022-07-16T09:17:05.976966Z","shell.execute_reply":"2022-07-16T09:17:06.270788Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"","metadata":{},"execution_count":null,"outputs":[]}]}