[kaggle] 선인장 식별하기 - EDA

youznn·2023년 2월 20일
0

Must Have - 머신러닝, 딥러닝 문제해결 전략__(신백균 저)
11장 항공 사진 내 선인장 식별 경진대회에 대한 내용

주어진 Data

train.zip, test.zip : jpg 압축 파일
train.csv: 파일명 및 타깃값(0,1)
sample_submission.csv : 샘플 제출 파일

google colab에서 진행하였기 때문에 드라이브 마운트 과정을 거쳐주었다. 찾아보니 따로 kaggle에서 notebook을 제공하는 듯하다

# 드라이브 마운트
from google.colab import drive
drive.mount('/content/drive')

탐색적 데이터 분석 (EDA)

import pandas as pd
data_path = '/content/drive/MyDrive/cactus'
labels = pd.read_csv(data_path+'train.csv')
submission = pd.read_csv(data_path + 'sample_submission.csv')

레이블 읽어오면

이렇게 보인다. 1이면 선인장 있는 이미지, 0이면 없는 이미지이다.

submission 읽어보면

->제출용 샘플. 아직 타깃값은 의미가 없고, 갱신시키는 것이 목표

데이터 시각화

import matplotlib as mpl
import matplotlib.pyplot as plt
%matplotlib inline

mpl.rc('font', size = 15)
plt.figure(figsize=(7,7))
label = ['has cactus', 'hasnt cactus'] 
plt.pie(labels['has_cactus'].value_counts(),labels = label , autopct='%.1f%%');

압축 풀기

from zipfile import ZipFile

with ZipFile(data_path + 'train.zip') as zipper:
  zipper.extractall()

with ZipFile(data_path + 'test.zip') as zipper:
  zipper.extractall()

이미지 출력

for idx, img_name in enumerate(last_has_cactus_img_name):
  img_path = 'train/' + img_name
  image = cv2.imread(img_path)
  image = cv2.cvtColor(image, cv2.COLOR_BGR2RGB)
  ax = plt.subplot(grid[idx])
  ax.imshow(image)

선인장을 포함하는 이미지를 출력했다. has_cactus 피처가 1인 것이다. 멋지다.

labels[labels['has_cactus'] == 1]
여기서 1만 0으로 바꿔주면 선인장을 포함하지 않는 이미지가 출력된다.

출처: Must Have 머신러닝·딥러닝 문제해결 전략 캐글 수상작 리팩터링으로 배우는 문제해결 프로세스와 전략

https://www.kaggle.com/code/werooring/ch11-eda/notebook

profile
https://github.com/youznn

0개의 댓글