반응형
[Python & Matplotlib] 아이리스(iris) 붓꽃 데이터셋을 활용하여 산점도 그래프 그리기 !!
Iris 데이터셋을 사용한 산점도 그래프 예시를 그려보았습니다....
Iris 데이터셋은 붓꽃(iris)의 세 종류(Setosa, Versicolour, Virginica)에 대한 150개의 샘플을 포함하며, 각 샘플은 꽃받침(sepal)과 꽃잎(petal)의 길이와 너비를 측정한 데이터입니다.
이 예시에서는 붓꽃 데이터셋의 꽃잎 길이와 너비를 사용하여 산점도 그래프를 그리고, 각 종류별로 점의 색을 다르게 하여 분류를 시각적으로 확인할 수 있습니다.
import matplotlib.pyplot as plt
import seaborn as sns
from sklearn.datasets import load_iris
import pandas as pd
# Iris 데이터셋 로드
iris = load_iris()
iris_df = pd.DataFrame(iris.data, columns=iris.feature_names)
# 종(species) 정보를 DataFrame에 추가
iris_df['species'] = pd.Categorical.from_codes(iris.target, iris.target_names)
# 산점도 그래프 그리기
sns.scatterplot(x='petal length (cm)', y='petal width (cm)', hue='species', style='species', data=iris_df)
# 제목과 축 라벨 추가
plt.title('Iris Petal Length vs. Width')
plt.xlabel('Petal Length (cm)')
plt.ylabel('Petal Width (cm)')
# 범례 표시
plt.legend(title='Species')
# 그래프 보여주기
plt.show()
결과
이 그래프는 각 붓꽃 종 사이의 꽃잎 길이와 너비에 따른 분포 차이를 명확하게 보여주네요 ㅎ
728x90
반응형
'Coding > 데이터 시각화' 카테고리의 다른 글
[Python & Matplotlib] 명사 추출 후 그래프로 시각화하는 방법 !! (0) | 2024.11.27 |
---|---|
[Python & Matplotlib] 타이타닉 생존자 데이터를 활용한 데이터 시각화 그리기 !! (0) | 2024.03.04 |
[Python & Matplotlib] seaborn 'tips' 데이터셋을 활용하여 산점도 그래프 그리기 !! (0) | 2024.03.03 |
[Python & Matplotlib] Matplotlib라이브러리를 활용한 산점도 그래프 그리기 !! (0) | 2024.02.28 |
댓글