머신 러닝 - Iris Classification(1)

이상해씨·2021년 11월 13일
0

머신 러닝

목록 보기
2/27
  • Iris Classification : 아이리스 꽃의 품종을 맞추는 문제, 머신 러닝의 기초 예제로 많이 활용된다.
    • IRIS : 프랑스의 국화, 꽃말 (좋은 소식, 잘 전해 주세요, 사랑의 메시지)
    • Versicolor, Virqinica, Setosa 3가지 품종 구분(꽃잎, 꽃받침의 길이/너비 정보 이용)

◾데이터 관찰

  • Iris 데이터 불러오기
# 사이킷런의 데이터 사용
from sklearn.datasets import load_iris

iris = load_iris()
iris.keys()

  • 기존 3종에 대해 먼저 공부
    • Sepal/Petal의 Width/Length에 파악
# iris 데이터 프레임 생성
import pandas as pd

iris_pd = pd.DataFrame(iris.data, columns=iris.feature_names)
iris_pd['species'] = iris.target
iris_pd.head()

import seaborn as sns
import matplotlib.pyplot as plt
import set_matplotlib_korean
  • sepal length Box Plot
    • 3 품종이 겹치는 구간이 있다.
    • 2번(virginica)의 경우 Outlier가 있다.
    • sepal length만으로는 구분할 수 없다.
# 그래프 그리기
plt.figure(figsize=(12, 6))
sns.boxplot(x='sepal length (cm)', y = 'species', data=iris_pd, orient='h');

  • sepal width Box Plot
    • sepal length보다 겹치는 구간이 많다.
    • 0번과 2번의 경우 outlier가 있다.
# 그래프 그리기
plt.figure(figsize=(12, 6))
sns.boxplot(x='sepal width (cm)', y = 'species', data=iris_pd, orient='h');

  • petal length Box Plot
    • 0번(setosa)의 경우 구분할 수 있다.
    • 1번(Versicolor), 2번(virginica)의 경우 겹치는 구간이 있다.
# 그래프 그리기
plt.figure(figsize=(12, 6))
sns.boxplot(x='petal length (cm)', y = 'species', data=iris_pd, orient='h');

  • petal width Box Plot
    • 0번(setosa)의 경우 구분할 수 있다.
    • 1번(versicolor), 2번(virginica)의 경우 겹치는 구간이 있다.
# 그래프 그리기
plt.figure(figsize=(12, 6))
sns.boxplot(x='petal width (cm)', y = 'species', data=iris_pd, orient='h');

  • pairplot을 활용한 시각화
    • petal length, petal width를 활용할 경우 잘 구분할 수 잇음을 알 수 있다.
# 그래프 그리기
sns.pairplot(iris_pd, hue='species', palette='Set2');

  • petal 정보에 집중한 pairplot
    • petal length < 2.5 : 대부분 Setosa
    • 2.5 <= petal length and 1.6 > petal width : 대부분 Versicolor
    • 2.5 <= petal length and 1.6 <= petal width : 대부분 Virginica
    • 조건을 순차적으로 표현하여 탐색하는 방법 : Decision Tree
# 그래프 그리기
sns.pairplot(data = iris_pd, 
             vars = ['petal length (cm)', 'petal width (cm)'],
             hue = 'species', 
             height= 4, palette ='Set2');

profile
후라이드 치킨

0개의 댓글