변수의 차이 이해하기
이번에는 각 변수의 평균과 표준편차를 막대그래프로 그려서 분석해 보세요. 이는 앞 단계의 보완 작업으로, 변수들의 스케일과 분산 차이를 시각적으로 살펴보는 과정이에요.
pandas 라이브러리는 pd, matplotlib.pyplot은 plt로 불러와져 있어요. 또한 wholesale 데이터셋은 pandas DataFrame으로 로드되어 있으며, 각 열의 평균과 표준편차는 각각 averages와 std_devs라는 이름의 pandas Series로 준비되어 있어요. 콘솔에서 미리 살펴보세요.
이 연습은 강의의 일부입니다
Python으로 배우는 마케팅용 Machine Learning
연습 안내
wholesale의 열 이름으로 리스트를 만들고, 0부터wholesale의 열 개수까지 정렬된 값으로 또 하나의 리스트를 만드세요.averages는 회색,std_devs는 주황색으로 그리되 x축을 0.2만큼 조정하세요.- 눈금으로는
x_ix, 레이블로는x_names를 추가하고, 레이블은 90도로 회전하세요. - 범례를 추가하고 차트를 표시하세요.
실습형 인터랙티브 연습
이 예제를 이 샘플 코드를 완성하여 풀어보세요.
# Create column names list and same length integer list
x_names = wholesale.___
x_ix = np.arange(wholesale.shape[1])
# Plot the averages data in gray and standard deviations in orange
plt.bar(x=x_ix-___, height=averages, color='grey', label='Average', width=0.4)
plt.bar(x=x_ix+___, height=std_devs, color='orange', label='Standard Deviation', width=0.4)
# Add x-axis labels and rotate
plt.xticks(ticks=___, labels=x_names, rotation=90)
# Add the legend and display the chart
plt.legend()
plt.___()