본문 바로가기
Ai/Keggle

EDA - Plant Pathology 2020 - [ 머신러닝-딥러닝 문제해결 전략 ]

by yooom 2023. 10. 2.

12.2.1 데이터 둘러보기

import pandas as pd

# 데이터 경로
data_path = '/kaggle/input/plant-pathology-2020-fgvc7/'

train = pd.read_csv(data_path + 'train.csv')
test = pd.read_csv(data_path + 'test.csv')
submission = pd.read_csv(data_path + 'sample_submission.csv')
train.shape, test.shape

train.head()

 

test.head()

submission.head()

12.2.2 데이터 시각화

타깃값 분포

# 데이터를 타깃값별로 추출
healthy = train.loc[train['healthy']==1]
multiple_diseases = train.loc[train['multiple_diseases']==1]
rust = train.loc[train['rust']==1]
scab = train.loc[train['scab']==1]
import matplotlib as mpl
import matplotlib.pyplot as plt
%matplotlib inline

mpl.rc('font', size=15)
plt.figure(figsize=(7, 7))

label = ['healthy', 'multiple diseases', 'rust', 'scab'] # 타깃값 레이블
# 타깃값 분포 파이 그래프
plt.pie([len(healthy), len(multiple_diseases), len(rust), len(scab)], 
        labels=label, 
        autopct='%.1f%%');

이미지 출력

import matplotlib.gridspec as gridspec
import cv2 # OpenCV 라이브러리

def show_image(img_ids, rows=2, cols=3): 
    assert len(img_ids) <= rows*cols # 이미지가 행/열 개수보다 많으면 오류 발생

    plt.figure(figsize=(15, 8))          # 전체 Figure 크기 설정
    grid = gridspec.GridSpec(rows, cols) # 서브플롯 배치

    # 이미지 출력
    for idx, img_id in enumerate(img_ids):
        img_path = f'{data_path}/images/{img_id}.jpg'  # 이미지 파일 경로 
        image = cv2.imread(img_path)                   # 이미지 파일 읽기 
        image = cv2.cvtColor(image, cv2.COLOR_BGR2RGB) # 이미지 색상 보정 
        ax = plt.subplot(grid[idx])
        ax.imshow(image) # 이미지 출력
# 각 타깃값별 image_id(마지막 6개)
num_of_imgs = 6
last_healthy_img_ids = healthy['image_id'][-num_of_imgs:]
last_multiple_diseases_img_ids = multiple_diseases['image_id'][-num_of_imgs:]
last_rust_img_ids = rust['image_id'][-num_of_imgs:]
last_scab_img_ids = scab['image_id'][-num_of_imgs:]
show_image(last_healthy_img_ids) # 건강한 잎사귀 출력

show_image(last_multiple_diseases_img_ids) # 여러 질병에 걸린 잎사귀 출력

show_image(last_rust_img_ids) # 녹병에 걸린 잎사귀 출력

show_image(last_scab_img_ids) # 붉은곰팡이병에 걸린 잎사귀

728x90

댓글