Python module for cohort data reading
Project description
PyKoges 데이터 분석 패키지
PyKoges는 Python 기반의 코호트 데이터 분석 도구로, 특히 Koges (한국인유전체역학조사사업) 데이터를 처리, 분석, 모델링하는데 특화되어 있습니다. 다음은 PyKoges 패키지를 사용하여 데이터를 읽고, 전처리하며, 분석 및 예측 모델을 구축하는 예시입니다.
:exclamation: 데이터가 포함되지 않은 분석 도구입니다. :exclamation:
pip install pykoges
시작하기 전에
PyKoges 패키지를 사용하기 전에 필요한 모듈을 임포트합니다.
from pykoges import codingbook, koges, stats, model
1. 코딩북 읽기
데이터 분석을 위해 먼저 코딩북을 읽어와야 합니다.
q = codingbook.read(folder_name='./data_fixed/')
# q.summary() # 코딩북의 요약 정보를 확인하고 싶다면 이 코드를 실행합니다.
2. 변수 설정
분석에 사용할 변수를 설정합니다.
x_list = {
# 여기에 입력 변수를 설정합니다...
}
y_list = {
# 여기에 출력 변수를 설정합니다...
}
patientinfo_list = {
# 환자를 구분할 수 있는 정보를 넣습니다...
}
# 변수 설정을 PyKoges에 적용합니다.
var = koges.Variables(
q=q,
x_list=x_list,
y_list=y_list,
patientinfo_list=patientinfo_list,
)
var.summary(
display_datainfo=True,
display_userinfo=True,
)
3. 데이터 읽기
설정된 변수를 바탕으로 데이터를 읽어옵니다.
kg = koges.read(
variables=var,
folder_name='./data_fixed/',
filter_patient=True,
)
4. 데이터 전처리
데이터를 전처리합니다. 여기에서는 몇 가지 전처리 옵션을 선택할 수 있습니다.
custom_functions = [
# 여기에 원하는 커스텀 함수를 설정할 수 있습니다.
# ([x, y], f)의 형태로 설정합니다.
]
kg_converted = koges.convert(
koges=kg,
muscle_weight_ratio=False, # muscle/weight
muscle_height_ratio=False, # muscle/height
muscle_bmi_ratio=False, # muscle/bmi
waist_hip_ratio=False, # waist/hip
fev_fvc_ratio=False, # fev1/fvc
grip_of_grwhich=True, # 주 사용손 악력
weight_height_bmi=False, # bmi
custom_functions=custom_functions,
)
5. 결측치 제거
결측치 처리 및 이상치 제거 등을 진행합니다.
kg_dropped = koges.drop(
koges=kg_converted,
drop_threshold=0.3, # drop_threshold 이상이 결측치인 변수 제거
filter_alpha=3, # 3SD를 벗어나느 데이터 제거
data_impute=False, # KNN알고리즘으로 결측치 채우기
display_result=True,
display_count=True,
)
6. 통계 분석
데이터 분리
kg_splitted = stats.split(
koges=kg_dropped,
n_class=4, # 그룹 개수
p_threshold=0.05,
with_normality=False,
with_homogenity=False,
isdisplay=True
)
통계 분석 수행
if kg_splitted.n_class == 2:
kg_stats = stats.t_test(koges=kg_splitted, p_threshold=.05)
else:
kg_stats = stats.anova(koges=kg_splitted, p_threshold=.05)
분석 결과 요약
stats.summary(koges=kg_stats, isdisplay=True)
분석 결과 boxplot
stats.boxplot(koges=kg_stats, isdisplay=True)
상관관계, 산점도 분석
stats.correlation(koges=kg_stats, isdisplay=True)
stats.scatter(koges=kg_stats, isdisplay=True)
7. 머신러닝
머신러닝 모델을 선택하여 훈련시키고 예측 진행을 합니다.
여/부는 로지스틱, 이산변수는 softmax, 연속변수는 선형 회귀를 진행합니다.
ml = model(
koges=kg_stats,
scalers=["minmax", "robust", "standard", "maxabs"],
)
if kg_stats.type == "binary":
ml.logistic(isdisplay=True)
elif kg_stats.type == "discrete":
ml.softmax(
display_roc_curve=True,
display_confusion_matrix=True,
)
elif kg_stats.type == "continuous":
ml.linear(isdisplay=True)
# regression의 결과가 안좋은 경우 quantile classification도 진행합니다.
if ml.r2 < 0.8:
ml.softmax(
display_roc_curve=True,
display_confusion_matrix=True,
)
예시이미지
8. 결과 저장
모든 작업의 결과물과 모델을 /result 폴더에 저장합니다.
ml.equation(isdisplay=True)
kg_stats.save(isdisplay=True)
이 문서는 PyKoges 패키지의 핵심 기능과 사용 방법을 제공하는 가이드라인을 제시합니다. 실제 데이터 분석 시 이 문서를 참고하여 PyKoges를 활용해보세요.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
File details
Details for the file pykoges-0.4.2.tar.gz.
File metadata
- Download URL: pykoges-0.4.2.tar.gz
- Upload date:
- Size: 25.3 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.2 CPython/3.11.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
b8d40be9e673be0a7e2d616cdef46b908a5a79de8d62f761d1e2fd492dbb7705
|
|
| MD5 |
8eceafde0fa981998a0d2d3bb0d52a1c
|
|
| BLAKE2b-256 |
fca15d16bef19aa43fe4bcdbc3bf1af634ff6d9e79a7520957c3d6b48c54291e
|