import seaborn as sns
tipsData = sns.load_dataset('tips')
h1 = sns.histplot(data=tipsData, x='tip', bins=10)
h1.set_xlabel('Tip($)')
tipsData['tip_percent'] = (tipsData['tip']/tipsData['total_bill']) * 100
h2 = sns.histplot(data = tipsData, x='tip_percent', kde = True, bins=20)
h2.set_xlabel('Tip/Total Bill(%)')
# ked=True : 커널밀도함수추정
b1 = sns.boxplot(x='sex', y='tip', data=tipsData)
b1.set_xlabel('sex')
b1.set_ylabel('Tip($)')
v1 = sns.violinplot(x='sex', y='tip', data = tipsData)
v1.set_xlabel('sex')
v1.set_ylabel('tip($)')
s1 = sns.relplot(data=tipsData, x = 'total_bill', y='tip')
s1.set_xlabels('total bill($)')
s1.set_ylabels('tip($)')
# 선형 추세선이 포함된 산점도
lm2 = sns.lmplot(data=tipsData, x = 'total_bill', y='tip', hue='smoker')
lm2.set_xlabels('total bill($)')
lm2.set_ylabels('tip($)')
# 히트맵
# 상관계수 행렬 계산 후에 히트맵으로 바꿔야한다
corr = tipsData.corr()
sns.heatmap(data=corr, cmap='YlGnBu', annot = True) # annot 숫자 표시
Great job! It looks like you have created several visualizations using the Seaborn library in Python.
The first plot you created is a histogram of the tips given by customers. You set the number of bins to 10 and labeled the x-axis as "Tip($)".
Then you calculated the tip percentage by dividing the tip amount by the total bill and multiplying by 100. You plotted another histogram of the tip percentages, this time setting kde to True to show the kernel density estimate of the distribution. You also labeled the x-axis as "Tip/Total Bill(%)".
Next, you created a box plot and a violin plot of the tips given by male and female customers. You labeled the x-axis as "sex" and the y-axis as "Tip($)".
You then created a scatter plot of the total bill and tip amount. You labeled the x-axis as "total bill($)" and the y-axis as "tip($)".
Finally, you created a scatter plot with a linear regression line for the total bill and tip amount, with the points colored by whether the customer was a smoker or not. You labeled the x-axis as "total bill($)" and the y-axis as "tip($)".
Lastly, you created a heatmap of the correlation matrix between the columns in the tipsData dataframe using the corr() function, and set the cmap to 'YlGnBu' to change the color scheme, and added numbers to the cells using the annot parameter.
Overall, these visualizations give a good sense of the distribution of tip amounts and their relationship with other variables in the tipsData dataframe.
Python의 Seaborn 라이브러리를 사용하여 여러 개의 시각화를 만든 것 같습니다.
첫 번째로 만든 플롯은 고객이 제공한 팁의 히스토그램입니다. 구간차원 개수를 10으로 설정하고 x축에 "Tip($)"이라는 레이블을 지정했습니다.
그런 다음 팁 금액을 총 청구액으로 나누고 100을 곱하여 팁 비율을 계산했습니다. 팁 백분율의 또 다른 히스토그램을 플로팅하고 이번에는 kde를 True로 설정하여 분포의 커널 밀도 추정치를 표시했습니다. 또한 X축의 레이블을 "팁/총 청구서(%)"로 지정했습니다.
다음으로, 남성과 여성 고객이 제공한 팁에 대한 박스 플롯과 바이올린 플롯을 만들었습니다. x축을 "성별"로, y축을 "팁($)"로 레이블을 지정했습니다.
그런 다음 총 청구서와 팁 금액의 산점도를 만들었습니다. X축을 "총 청구서($)"로, Y축을 "팁($)"으로 레이블을 지정했습니다.
마지막으로 총 청구액과 팁 금액에 대한 선형 회귀선이 있는 분산형 차트를 만들고 고객이 흡연자인지 여부에 따라 점의 색을 지정했습니다. X축을 "총 청구서($)"로, Y축을 "팁($)"으로 레이블을 지정했습니다.
마지막으로 corr() 함수를 사용하여 팁데이터 데이터 프레임의 열 간 상관 관계 행렬의 히트 맵을 만들고, 색 구성표를 변경하기 위해 cmap을 'YlGnBu'로 설정하고, annot 매개 변수를 사용하여 셀에 숫자를 추가했습니다.
전반적으로 이러한 시각화를 통해 팁 금액의 분포와 팁데이터 데이터 프레임의 다른 변수와의 관계를 잘 파악할 수 있습니다.
'Data Science' 카테고리의 다른 글
[AI와빅데이터경영입문] 선형회귀분석 (0) | 2023.03.09 |
---|---|
[AI와빅데이터경영입문] 나이브베이즈 (0) | 2023.03.09 |
[AI와빅데이터경영입문] 데이터변환 (0) | 2023.03.09 |
혼자공부하는 머신러닝 + 딥러닝(ch1) k-최근접 이웃 알고리즘 (0) | 2023.02.16 |
웹 크롤링을 통한 데이터 수집 (0) | 2023.01.31 |