{"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":"# 6.3 자전거 대여 수요 예측 경진대회 탐색적 데이터 분석","metadata":{"papermill":{"duration":0.027285,"end_time":"2021-09-01T15:20:11.391138","exception":false,"start_time":"2021-09-01T15:20:11.363853","status":"completed"},"tags":[]}},{"cell_type":"markdown","source":"- [자전거 대여 수요 예측 경진대회 링크](https://www.kaggle.com/c/bike-sharing-demand)\n\n- [탐색적 데이터 분석 코드 참고 링크](https://www.kaggle.com/viveksrinivasan/eda-ensemble-model-top-10-percentile)","metadata":{"papermill":{"duration":0.029144,"end_time":"2021-09-01T15:20:11.447375","exception":false,"start_time":"2021-09-01T15:20:11.418231","status":"completed"},"tags":[]}},{"cell_type":"markdown","source":"## 6.3.1 캐글 노트북 환경 설정","metadata":{}},{"cell_type":"markdown","source":"## 6.3.2 데이터 둘러보기","metadata":{"papermill":{"duration":0.02567,"end_time":"2021-09-01T15:20:11.571783","exception":false,"start_time":"2021-09-01T15:20:11.546113","status":"completed"},"tags":[]}},{"cell_type":"code","source":"import numpy as np\nimport pandas as pd # 판다스 임포트\n\n# 데이터 경로\ndata_path = '/kaggle/input/bike-sharing-demand/'\n\ntrain = pd.read_csv(data_path + 'train.csv') # 훈련 데이터\ntest = pd.read_csv(data_path + 'test.csv')   # 테스트 데이터\nsubmission = pd.read_csv(data_path + 'sampleSubmission.csv') # 제출 샘플 데이터","metadata":{"_cell_guid":"057b1690-5b93-9f14-eafe-fad12c00da69","papermill":{"duration":0.202376,"end_time":"2021-09-01T15:20:11.800197","exception":false,"start_time":"2021-09-01T15:20:11.597821","status":"completed"},"tags":[],"execution":{"iopub.status.busy":"2022-08-05T04:30:52.219662Z","iopub.execute_input":"2022-08-05T04:30:52.220650Z","iopub.status.idle":"2022-08-05T04:30:52.389891Z","shell.execute_reply.started":"2022-08-05T04:30:52.220524Z","shell.execute_reply":"2022-08-05T04:30:52.388524Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"train.shape, test.shape","metadata":{"_cell_guid":"4b5eee60-635b-e053-97cd-62f3e9e8acac","papermill":{"duration":0.039018,"end_time":"2021-09-01T15:20:11.866423","exception":false,"start_time":"2021-09-01T15:20:11.827405","status":"completed"},"tags":[],"execution":{"iopub.status.busy":"2022-08-05T04:30:52.392487Z","iopub.execute_input":"2022-08-05T04:30:52.392851Z","iopub.status.idle":"2022-08-05T04:30:52.402986Z","shell.execute_reply.started":"2022-08-05T04:30:52.392811Z","shell.execute_reply":"2022-08-05T04:30:52.401855Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"train.head()","metadata":{"_cell_guid":"664d34ff-4580-aeb1-18ea-6dca2b5ae078","papermill":{"duration":0.05687,"end_time":"2021-09-01T15:20:11.950157","exception":false,"start_time":"2021-09-01T15:20:11.893287","status":"completed"},"tags":[],"execution":{"iopub.status.busy":"2022-08-05T04:47:19.241989Z","iopub.execute_input":"2022-08-05T04:47:19.242448Z","iopub.status.idle":"2022-08-05T04:47:19.267562Z","shell.execute_reply.started":"2022-08-05T04:47:19.242408Z","shell.execute_reply":"2022-08-05T04:47:19.266355Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"test.head()","metadata":{"papermill":{"duration":0.045392,"end_time":"2021-09-01T15:20:12.02443","exception":false,"start_time":"2021-09-01T15:20:11.979038","status":"completed"},"tags":[],"execution":{"iopub.status.busy":"2022-08-05T04:47:19.631552Z","iopub.execute_input":"2022-08-05T04:47:19.632635Z","iopub.status.idle":"2022-08-05T04:47:19.650867Z","shell.execute_reply.started":"2022-08-05T04:47:19.632578Z","shell.execute_reply":"2022-08-05T04:47:19.649701Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"submission.head()","metadata":{"papermill":{"duration":0.041105,"end_time":"2021-09-01T15:20:12.092925","exception":false,"start_time":"2021-09-01T15:20:12.05182","status":"completed"},"tags":[],"execution":{"iopub.status.busy":"2022-08-05T04:47:19.994674Z","iopub.execute_input":"2022-08-05T04:47:19.995608Z","iopub.status.idle":"2022-08-05T04:47:20.008432Z","shell.execute_reply.started":"2022-08-05T04:47:19.995570Z","shell.execute_reply":"2022-08-05T04:47:20.007161Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"train.info()","metadata":{"papermill":{"duration":0.055312,"end_time":"2021-09-01T15:20:12.177068","exception":false,"start_time":"2021-09-01T15:20:12.121756","status":"completed"},"tags":[],"execution":{"iopub.status.busy":"2022-08-05T04:47:20.149728Z","iopub.execute_input":"2022-08-05T04:47:20.150096Z","iopub.status.idle":"2022-08-05T04:47:20.175870Z","shell.execute_reply.started":"2022-08-05T04:47:20.150066Z","shell.execute_reply":"2022-08-05T04:47:20.174881Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"test.info()","metadata":{"papermill":{"duration":0.047382,"end_time":"2021-09-01T15:20:12.252438","exception":false,"start_time":"2021-09-01T15:20:12.205056","status":"completed"},"tags":[],"execution":{"iopub.status.busy":"2022-08-05T04:47:25.409693Z","iopub.execute_input":"2022-08-05T04:47:25.409988Z","iopub.status.idle":"2022-08-05T04:47:25.431899Z","shell.execute_reply.started":"2022-08-05T04:47:25.409961Z","shell.execute_reply":"2022-08-05T04:47:25.430603Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"## 6.3.3 더 효과적인 분석을 위한 피처 엔지니어링","metadata":{"_cell_guid":"25e226ba-1c12-3fd3-08d8-fe69f9748b73","papermill":{"duration":0.028318,"end_time":"2021-09-01T15:20:12.309194","exception":false,"start_time":"2021-09-01T15:20:12.280876","status":"completed"},"tags":[]}},{"cell_type":"code","source":"print(train['datetime'][100]) # datetime 100번째 요소\nprint(train['datetime'][100].split()) # 공백 기준으로 문자열 나누기\nprint(train['datetime'][100].split()[0]) # 날짜\nprint(train['datetime'][100].split()[1]) # 시간","metadata":{"papermill":{"duration":0.039471,"end_time":"2021-09-01T15:20:12.377498","exception":false,"start_time":"2021-09-01T15:20:12.338027","status":"completed"},"tags":[],"execution":{"iopub.status.busy":"2022-08-05T04:48:00.258378Z","iopub.execute_input":"2022-08-05T04:48:00.258808Z","iopub.status.idle":"2022-08-05T04:48:00.270239Z","shell.execute_reply.started":"2022-08-05T04:48:00.258765Z","shell.execute_reply":"2022-08-05T04:48:00.268885Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"print(train['datetime'][100].split()[0]) # 날짜\nprint(train['datetime'][100].split()[0].split('-')) # \"_\" 기준으로 문자열 나누기\nprint(train['datetime'][100].split()[0].split('-')[0]) # 연도\nprint(train['datetime'][100].split()[0].split('-')[1]) # 월\nprint(train['datetime'][100].split()[0].split('-')[2]) # 일","metadata":{"papermill":{"duration":0.039819,"end_time":"2021-09-01T15:20:12.44678","exception":false,"start_time":"2021-09-01T15:20:12.406961","status":"completed"},"tags":[],"execution":{"iopub.status.busy":"2022-08-05T04:56:48.476372Z","iopub.execute_input":"2022-08-05T04:56:48.476902Z","iopub.status.idle":"2022-08-05T04:56:48.494767Z","shell.execute_reply.started":"2022-08-05T04:56:48.476862Z","shell.execute_reply":"2022-08-05T04:56:48.493311Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"print(train['datetime'][100].split()[1]) # 시간\nprint(train['datetime'][100].split()[1].split(':')) # \":\" 기준으로 문자열 나누기\nprint(train['datetime'][100].split()[1].split(':')[0]) # 시간\nprint(train['datetime'][100].split()[1].split(':')[1]) # 분\nprint(train['datetime'][100].split()[1].split(':')[2]) # 초","metadata":{"papermill":{"duration":0.0505,"end_time":"2021-09-01T15:20:12.52892","exception":false,"start_time":"2021-09-01T15:20:12.47842","status":"completed"},"tags":[],"execution":{"iopub.status.busy":"2022-08-05T04:56:51.457389Z","iopub.execute_input":"2022-08-05T04:56:51.458158Z","iopub.status.idle":"2022-08-05T04:56:51.467628Z","shell.execute_reply.started":"2022-08-05T04:56:51.458129Z","shell.execute_reply":"2022-08-05T04:56:51.466353Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"train['date'] = train['datetime'].apply(lambda x: x.split()[0]) # 날짜 피처 생성\n\n# 연도, 월, 일, 시, 분, 초 피처를 차례로 생성\ntrain['year'] = train['datetime'].apply(lambda x: x.split()[0].split('-')[0]) \ntrain['month'] = train['datetime'].apply(lambda x: x.split()[0].split('-')[1])\ntrain['day'] = train['datetime'].apply(lambda x: x.split()[0].split('-')[2]) \ntrain['hour'] = train['datetime'].apply(lambda x: x.split()[1].split(':')[0])\ntrain['minute'] = train['datetime'].apply(lambda x: x.split()[1].split(':')[1])\ntrain['second'] = train['datetime'].apply(lambda x: x.split()[1].split(':')[2])","metadata":{"_cell_guid":"18f7c3fc-ffdf-4bc6-1d4c-c455fb4e0141","papermill":{"duration":0.114489,"end_time":"2021-09-01T15:20:12.681748","exception":false,"start_time":"2021-09-01T15:20:12.567259","status":"completed"},"tags":[],"execution":{"iopub.status.busy":"2022-08-05T04:57:08.740308Z","iopub.execute_input":"2022-08-05T04:57:08.740632Z","iopub.status.idle":"2022-08-05T04:57:08.805581Z","shell.execute_reply.started":"2022-08-05T04:57:08.740601Z","shell.execute_reply":"2022-08-05T04:57:08.804552Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"from datetime import datetime # datatime 라이브러리 임포트\nimport calendar\n\nprint(train['date'][100]) # 날짜\nprint(datetime.strptime(train['date'][100], '%Y-%m-%d')) # datetime 타입으로 변경\nprint(datetime.strptime(train['date'][100], '%Y-%m-%d').weekday()) # 정수로 요일 반환\nprint(calendar.day_name[datetime.strptime(train['date'][100], '%Y-%m-%d').weekday()]) # 문자열로 요일 반환","metadata":{"papermill":{"duration":0.042242,"end_time":"2021-09-01T15:20:12.753699","exception":false,"start_time":"2021-09-01T15:20:12.711457","status":"completed"},"tags":[],"execution":{"iopub.status.busy":"2022-08-05T05:01:09.162538Z","iopub.execute_input":"2022-08-05T05:01:09.162911Z","iopub.status.idle":"2022-08-05T05:01:09.174864Z","shell.execute_reply.started":"2022-08-05T05:01:09.162880Z","shell.execute_reply":"2022-08-05T05:01:09.173602Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"train['weekday'] = train['date'].apply(\n    lambda dateString: \n    calendar.day_name[datetime.strptime(dateString,\"%Y-%m-%d\").weekday()])","metadata":{"papermill":{"duration":0.220254,"end_time":"2021-09-01T15:20:13.004206","exception":false,"start_time":"2021-09-01T15:20:12.783952","status":"completed"},"tags":[],"execution":{"iopub.status.busy":"2022-08-05T05:01:46.747125Z","iopub.execute_input":"2022-08-05T05:01:46.747533Z","iopub.status.idle":"2022-08-05T05:01:46.914549Z","shell.execute_reply.started":"2022-08-05T05:01:46.747501Z","shell.execute_reply":"2022-08-05T05:01:46.913385Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"train['season'] = train['season'].map({1: 'Spring', \n                                       2: 'Summer', \n                                       3: 'Fall', \n                                       4: 'Winter' })\ntrain['weather'] = train['weather'].map({1: 'Clear', \n                                         2: 'Mist, Few clouds', \n                                         3: 'Light Snow, Rain, Thunder', \n                                         4: 'Heavy Snow, Rain, Thunder'})","metadata":{"papermill":{"duration":0.044251,"end_time":"2021-09-01T15:20:13.078499","exception":false,"start_time":"2021-09-01T15:20:13.034248","status":"completed"},"tags":[],"execution":{"iopub.status.busy":"2022-08-05T05:01:47.440734Z","iopub.execute_input":"2022-08-05T05:01:47.441086Z","iopub.status.idle":"2022-08-05T05:01:47.455921Z","shell.execute_reply.started":"2022-08-05T05:01:47.441057Z","shell.execute_reply":"2022-08-05T05:01:47.454767Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"train.head()","metadata":{"papermill":{"duration":0.057887,"end_time":"2021-09-01T15:20:13.166613","exception":false,"start_time":"2021-09-01T15:20:13.108726","status":"completed"},"tags":[],"execution":{"iopub.status.busy":"2022-08-05T05:01:48.880169Z","iopub.execute_input":"2022-08-05T05:01:48.880474Z","iopub.status.idle":"2022-08-05T05:01:48.909609Z","shell.execute_reply.started":"2022-08-05T05:01:48.880431Z","shell.execute_reply":"2022-08-05T05:01:48.908399Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"## 6.3.4 데이터 시각화","metadata":{"papermill":{"duration":0.02997,"end_time":"2021-09-01T15:20:13.227506","exception":false,"start_time":"2021-09-01T15:20:13.197536","status":"completed"},"tags":[]}},{"cell_type":"code","source":"import seaborn as sns\nimport matplotlib as mpl\nimport matplotlib.pyplot as plt\n%matplotlib inline","metadata":{"papermill":{"duration":0.914174,"end_time":"2021-09-01T15:20:14.171954","exception":false,"start_time":"2021-09-01T15:20:13.25778","status":"completed"},"tags":[],"execution":{"iopub.status.busy":"2022-08-05T05:02:38.346712Z","iopub.execute_input":"2022-08-05T05:02:38.347016Z","iopub.status.idle":"2022-08-05T05:02:39.313616Z","shell.execute_reply.started":"2022-08-05T05:02:38.346988Z","shell.execute_reply":"2022-08-05T05:02:39.312432Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"### 분포도","metadata":{"papermill":{"duration":0.030405,"end_time":"2021-09-01T15:20:14.233234","exception":false,"start_time":"2021-09-01T15:20:14.202829","status":"completed"},"tags":[]}},{"cell_type":"code","source":"mpl.rc('font', size=15)      # 폰트 크기를 15로 설정 \nsns.displot(train['count']); # 분포도 출력","metadata":{"papermill":{"duration":0.432078,"end_time":"2021-09-01T15:20:14.69585","exception":false,"start_time":"2021-09-01T15:20:14.263772","status":"completed"},"tags":[],"execution":{"iopub.status.busy":"2022-08-05T05:02:40.106514Z","iopub.execute_input":"2022-08-05T05:02:40.106871Z","iopub.status.idle":"2022-08-05T05:02:40.943073Z","shell.execute_reply.started":"2022-08-05T05:02:40.106841Z","shell.execute_reply":"2022-08-05T05:02:40.941938Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"sns.displot(np.log(train['count']));","metadata":{"papermill":{"duration":0.35686,"end_time":"2021-09-01T15:20:15.084463","exception":false,"start_time":"2021-09-01T15:20:14.727603","status":"completed"},"tags":[],"execution":{"iopub.status.busy":"2022-08-05T05:02:40.945229Z","iopub.execute_input":"2022-08-05T05:02:40.946044Z","iopub.status.idle":"2022-08-05T05:02:41.450210Z","shell.execute_reply.started":"2022-08-05T05:02:40.945955Z","shell.execute_reply":"2022-08-05T05:02:41.448991Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"### 막대 그래프","metadata":{"papermill":{"duration":0.032107,"end_time":"2021-09-01T15:20:15.149183","exception":false,"start_time":"2021-09-01T15:20:15.117076","status":"completed"},"tags":[]}},{"cell_type":"code","source":"# 스텝 1 : m행 n열 Figure 준비\nmpl.rc('font', size=14)       # 폰트 크기 설정\nmpl.rc('axes', titlesize=15)  # 각 축의 제목 크기 설정\nfigure, axes = plt.subplots(nrows=3, ncols=2) # 3행 2열 Figure 생성 \nplt.tight_layout()            # 그래프 사이에 여백 확보 \nfigure.set_size_inches(10, 9) # 전체 Figure 크기를 10x9인치로 설정 \n\n# 스텝 2 : 각 축에 서브플롯 할당\n# 각 축에 연도, 월, 일, 시간, 분, 초별 평균 대여 수량 막대 그래프 할당\nsns.barplot(x='year', y='count', data=train, ax=axes[0, 0])\nsns.barplot(x='month', y='count', data=train, ax=axes[0, 1])\nsns.barplot(x='day', y='count', data=train, ax=axes[1, 0])\nsns.barplot(x='hour', y='count', data=train, ax=axes[1, 1])\nsns.barplot(x='minute', y='count', data=train, ax=axes[2, 0])\nsns.barplot(x='second', y='count', data=train, ax=axes[2, 1])\n\n# 스텝 3 : 세부 설정\n# 3-1 : 서브플롯에 제목 달기\naxes[0, 0].set(title='Rental amounts by year')\naxes[0, 1].set(title='Rental amounts by month')\naxes[1, 0].set(title='Rental amounts by day')\naxes[1, 1].set(title='Rental amounts by hour')\naxes[2, 0].set(title='Rental amounts by minute')\naxes[2, 1].set(title='Rental amounts by second')\n\n# 3-2 : 1행에 위치한 서브플롯들의 x축 라벨 90도 회전\naxes[1, 0].tick_params(axis='x', labelrotation=90)\naxes[1, 1].tick_params(axis='x', labelrotation=90)","metadata":{"papermill":{"duration":4.120295,"end_time":"2021-09-01T15:20:19.302167","exception":false,"start_time":"2021-09-01T15:20:15.181872","status":"completed"},"tags":[],"execution":{"iopub.status.busy":"2022-08-05T05:03:59.605399Z","iopub.execute_input":"2022-08-05T05:03:59.605754Z","iopub.status.idle":"2022-08-05T05:04:03.747278Z","shell.execute_reply.started":"2022-08-05T05:03:59.605725Z","shell.execute_reply":"2022-08-05T05:04:03.746253Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"### 박스플롯","metadata":{"papermill":{"duration":0.033072,"end_time":"2021-09-01T15:20:19.369304","exception":false,"start_time":"2021-09-01T15:20:19.336232","status":"completed"},"tags":[]}},{"cell_type":"code","source":"# 스텝 1 : m행 n열 Figure 준비\nfigure, axes = plt.subplots(nrows=2, ncols=2) # 2행 2열\nplt.tight_layout()\nfigure.set_size_inches(10, 10)\n\n# 스텝 2 : 서브플롯 할당\n# 계절, 날씨, 공휴일, 근무일별 대여 수량 박스플롯\nsns.boxplot(x='season', y='count', data=train, ax=axes[0, 0])\nsns.boxplot(x='weather', y='count', data=train, ax=axes[0, 1])\nsns.boxplot(x='holiday', y='count', data=train, ax=axes[1, 0])\nsns.boxplot(x='workingday', y='count', data=train, ax=axes[1, 1])\n\n# 스텝 3 : 세부 설정\n# 3-1 : 서브플롯에 제목 달기\naxes[0, 0].set(title='Box Plot On Count Across Season')\naxes[0, 1].set(title='Box Plot On Count Across Weather')\naxes[1, 0].set(title='Box Plot On Count Across Holiday')\naxes[1, 1].set(title='Box Plot On Count Across Working Day')\n\n# 3-2 : x축 라벨 겹침 해결\naxes[0, 1].tick_params('x', labelrotation=10) # 10도 회전","metadata":{"_cell_guid":"e17e9a96-2d8f-5ba7-19b8-9f1f35709bb9","papermill":{"duration":0.825902,"end_time":"2021-09-01T15:20:20.228627","exception":false,"start_time":"2021-09-01T15:20:19.402725","status":"completed"},"tags":[],"execution":{"iopub.status.busy":"2022-08-05T05:04:03.749437Z","iopub.execute_input":"2022-08-05T05:04:03.750714Z","iopub.status.idle":"2022-08-05T05:04:04.649664Z","shell.execute_reply.started":"2022-08-05T05:04:03.750674Z","shell.execute_reply":"2022-08-05T05:04:04.648591Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"### 포인트플롯","metadata":{"papermill":{"duration":0.035955,"end_time":"2021-09-01T15:20:20.300416","exception":false,"start_time":"2021-09-01T15:20:20.264461","status":"completed"},"tags":[]}},{"cell_type":"code","source":"# 스텝 1 : m행 n열 Figure 준비\nmpl.rc('font', size=11)\nfigure, axes = plt.subplots(nrows=5) # 5행 1열\nfigure.set_size_inches(12, 18)\n\n# 스텝 2 : 서브플롯 할당\n# 근무일, 공휴일, 요일, 계절, 날씨에 따른 시간대별 평균 대여 수량 포인트플롯\nsns.pointplot(x='hour', y='count', data=train, hue='workingday', ax=axes[0])\nsns.pointplot(x='hour', y='count', data=train, hue='holiday', ax=axes[1])\nsns.pointplot(x='hour', y='count', data=train, hue='weekday', ax=axes[2])\nsns.pointplot(x='hour', y='count', data=train, hue='season', ax=axes[3])\nsns.pointplot(x='hour', y='count', data=train, hue='weather', ax=axes[4]);","metadata":{"papermill":{"duration":18.5255,"end_time":"2021-09-01T15:20:38.861756","exception":false,"start_time":"2021-09-01T15:20:20.336256","status":"completed"},"tags":[],"execution":{"iopub.status.busy":"2022-08-05T05:04:04.651764Z","iopub.execute_input":"2022-08-05T05:04:04.652134Z","iopub.status.idle":"2022-08-05T05:04:24.350475Z","shell.execute_reply.started":"2022-08-05T05:04:04.652092Z","shell.execute_reply":"2022-08-05T05:04:24.349590Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"### 회귀선을 포함한 산점도 그래프","metadata":{"papermill":{"duration":0.042257,"end_time":"2021-09-01T15:20:38.946635","exception":false,"start_time":"2021-09-01T15:20:38.904378","status":"completed"},"tags":[]}},{"cell_type":"code","source":"# 스텝 1 : m행 n열 Figure 준비\nmpl.rc('font', size=15)\nfigure, axes = plt.subplots(nrows=2, ncols=2) # 2행 2열\nplt.tight_layout()\nfigure.set_size_inches(7, 6)\n\n# 스텝 2 : 서브플롯 할당\n# 온도, 체감 온도, 풍속, 습도 별 대여 수량 산점도 그래프\nsns.regplot(x='temp', y='count', data=train, ax=axes[0, 0], \n            scatter_kws={'alpha': 0.2}, line_kws={'color': 'blue'})\nsns.regplot(x='atemp', y='count', data=train, ax=axes[0, 1], \n            scatter_kws={'alpha': 0.2}, line_kws={'color': 'blue'})\nsns.regplot(x='windspeed', y='count', data=train, ax=axes[1, 0], \n            scatter_kws={'alpha': 0.2}, line_kws={'color': 'blue'})\nsns.regplot(x='humidity', y='count', data=train, ax=axes[1, 1], \n            scatter_kws={'alpha': 0.2}, line_kws={'color': 'blue'});","metadata":{"papermill":{"duration":3.467997,"end_time":"2021-09-01T15:20:42.457258","exception":false,"start_time":"2021-09-01T15:20:38.989261","status":"completed"},"tags":[],"execution":{"iopub.status.busy":"2022-08-05T05:04:24.352742Z","iopub.execute_input":"2022-08-05T05:04:24.354091Z","iopub.status.idle":"2022-08-05T05:04:27.653365Z","shell.execute_reply.started":"2022-08-05T05:04:24.354055Z","shell.execute_reply":"2022-08-05T05:04:27.652210Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"### 히트맵","metadata":{"papermill":{"duration":0.045675,"end_time":"2021-09-01T15:20:42.548858","exception":false,"start_time":"2021-09-01T15:20:42.503183","status":"completed"},"tags":[]}},{"cell_type":"code","source":"train[['temp', 'atemp', 'humidity', 'windspeed', 'count']].corr()","metadata":{"papermill":{"duration":0.068902,"end_time":"2021-09-01T15:20:42.664051","exception":false,"start_time":"2021-09-01T15:20:42.595149","status":"completed"},"tags":[],"execution":{"iopub.status.busy":"2022-08-05T05:04:27.655454Z","iopub.execute_input":"2022-08-05T05:04:27.655793Z","iopub.status.idle":"2022-08-05T05:04:27.682519Z","shell.execute_reply.started":"2022-08-05T05:04:27.655754Z","shell.execute_reply":"2022-08-05T05:04:27.681582Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# 피처 간 상관관계 매트릭스\ncorrMat = train[['temp', 'atemp', 'humidity', 'windspeed', 'count']].corr() \nfig, ax= plt.subplots() \nfig.set_size_inches(10, 10)\nsns.heatmap(corrMat, annot=True) # 상관관계 히트맵 그리기\nax.set(title='Heatmap of Numerical Data');","metadata":{"papermill":{"duration":0.392404,"end_time":"2021-09-01T15:20:43.102786","exception":false,"start_time":"2021-09-01T15:20:42.710382","status":"completed"},"tags":[],"execution":{"iopub.status.busy":"2022-08-05T05:04:27.684092Z","iopub.execute_input":"2022-08-05T05:04:27.684519Z","iopub.status.idle":"2022-08-05T05:04:28.123759Z","shell.execute_reply.started":"2022-08-05T05:04:27.684480Z","shell.execute_reply":"2022-08-05T05:04:28.122795Z"},"trusted":true},"execution_count":null,"outputs":[]}]}