GIS

Python 종 분포 모델링(SDM) (1) - 종 분포 데이터셋

유병혁 2022. 3. 28. 01:10

안녕하세요? Python 언어용 자유 소프트웨어 머신러닝 라이브러리 'scikit-learn(사이킷런)'에서 제공하는 종 분포 모델링(species distribution modeling) 예제 코드를 시리즈 글로 다시 정리해 봅니다. 이번엔 첫번째 글로 실습용 종 분포 데이터셋을 확인해 보겠습니다.

 

Species distribution modeling

Modeling species’ geographic distributions is an important problem in conservation biology. In this example we model the geographic distribution of two south american mammals given past observation...

scikit-learn.org

종 분모 모델링(SDM: Species Distribution Modeling)

종의 지리적 분포를 모델링하는 것은 보전 생물학(conservation biology)에서 중요한 문제입니다. 이 예제에서 우리는 과거 관찰과 14개의 환경 변수가 주어진 남미 포유류 2종의 지리적 분포를 모델링합니다. 종 출현 데이터만 있기 때문에(비출현 관측은 없음) 이 문제를 밀도 추정 문제(density estimation problem)로 정하고 OneClassSVM을 모델링 도구로 사용합니다. 데이터셋 출처는 Phillips et. al. (2006)입니다.

 

“Maximum entropy modeling of species geographic distributions” S. J. Phillips, R. P. Anderson, R. E. Schapire - Ecological Modelling, 190:231-259, 2006.

 

포유류 2종은 다음과 같습니다:

  • Bradypus variegatus: 갈색목세발가락나무늘보(Brown-throated Sloth)
  • Microryzomys minutus: 숲작은쌀쥐(Forest Small Rice Rat)

https://www.iucnredlist.org/species/3038/47437046
https://inaturalist.nz/photos/50854603

sklearn.datasets.fetch_species_distributions

실습용 종 분포 데이터셋은 'sklearn.datasets.fetch_species_distributions'입니다.

 

sklearn.datasets.fetch_species_distributions

Examples using sklearn.datasets.fetch_species_distributions: Species distribution modeling Species distribution modeling, Kernel Density Estimate of Species Distributions Kernel Density Estimate of...

scikit-learn.org

종 분포 데이터셋은 아래와 같이 정의할 수 있는데요, 데이터셋 유형은 sklearn.utils.Bunch입니다.

from sklearn.datasets import fetch_species_distributions
# 종 분포 데이터셋
data = fetch_species_distributions()
type(data) # sklearn.utils.Bunch

sklearn.utils.Bunch

 

sklearn.utils.Bunch

Examples using sklearn.utils.Bunch: Species distribution modeling Species distribution modeling,

scikit-learn.org

Bunch 객체는 키(keys)를 속성으로 노출하는 컨테이너 객체(container object)입니다. key, bunch["value_key"], 또는 속성, bunch.value_key에 의해 값에 엑세스할 수 있도록 하여 딕셔너리를 확장합니다.

# sklearn.utils.Bunch
from sklearn.utils import Bunch
park = Bunch(bear=1, tree=2)
print('bunch.value_key: %s' % park.bear) # bunch.value_key: 1
print('bunch["value_key"]: %s' % park['bear']) # bunch["value_key"]: 1

종 분포 데이터셋도 Bunch 객체 유형이므로 키를 확인해 보겠습니다.

data.keys() # 키

coverages

coverages는 맵 그리드(map grid)의 각 지점에서 측정된 14개의 피처를 나타냅니다. 누락된 데이터는 -9999 값으로 표시됩니다. Bunch 객체를 쓰지 않는다면 *.tif나 *.asc 포맷으로 된 다수의 래스터 레이어를 사용할 수도 있겠습니다.

# coverages
print('coverages 유형: %s' % type(data.coverages)) # coverages 유형: <class 'numpy.ndarray'>
print('coverages 차원: %d' % data.coverages.ndim) # coverages 차원: 3
print('coverages 깊이, 행, 열: ' + str(data.coverages.shape)) # coverages 깊이, 행, 열: (14, 1592, 1212)

coverages[6]는 모든 육지 지점에서 측정값이 있어 육지와 물 사이를 결정하는 데 도움이 됩니다.

import matplotlib.pyplot as plt
plt.imshow(data.coverages[6])
plt.show()

train(훈련); test(시험)

훈련과 시험 데이터는 3개 필드(종 이름, 경도, 위도)로 구성되어 있습니다.

import pandas as pd
# train(훈련 데이터): (1624, 3)
print('훈련 데이터 행, 열: ' + str(pd.DataFrame(data.train).shape))
pd.DataFrame(data.train).head()

# test(시험 데이터): (620, 3)
print('시험 데이터 행, 열: ' + str(pd.DataFrame(data.test).shape))
pd.DataFrame(data.test).head()

x_left_lower_corner; y_left_lower_corner

왼쪽 하단 모서리 좌표를 경도, 위도로 나타냅니다.

# data.x_left_lower_corner (float); data.y_left_lower_corner (float)
print('x_left_lower_corner, 경도: %f' % data.x_left_lower_corner) # x_left_lower_corner, 경도: -94.800000
print('y_left_lower_corner, 위도: %f' % data.y_left_lower_corner) # y_left_lower_corner, 위도: -56.050000

Nx; Ny

맵 그리드의 경도(x) 및 위도(y) 수를 나타내며, 해당 수치는 coverages의 행(위도), 열(경도)과 동일합니다.

# data.Nx (int), data.Ny (int)
print('Nx, 경도 수: %d, Ny, 위도 수: %d' % (data.Nx, data.Ny)) # Nx, 경도 수: 1212, Ny, 위도 수: 1592

grid_size

그리드 점 사이의 간격(도)을 나타냅니다. Bunch 객체에서 우리는 왼쪽 하단 모서리 좌표(-94.8, -56.05), 맵 그리드의 행렬 개수(1212, 1592), 또한 그리드 점 간격이 0.05도라는 것을 알고 있습니다. 이 정보를 통해 맵 그리드의 위도, 경도 값을 설명할 수 있습니다. 여기까지 첫번째 글을 정리해 봤습니다.

# data.grid_size (float)
# 그리드 좌표 사이의 간격(도)
print('grid_size: %f' % data.grid_size) # grid_size: 0.050000