Skip to main content

Corporate Credit Survival Analysis · 기업 신용 생존분석

한국 기업 신용위험 평가를 위한 생존모형 라이브러리 — numpy·scipy만으로 구현 Dependency-light survival models for Korean corporate credit risk, implemented in pure numpy/scipy

CI Python Coverage Validated against lifelines License

개요 · Overview

전통적 신용평가(로지스틱 회귀)는 부도를 이진 결과로만 다뤄 사건까지의 시간(time-to-event) 동학을 무시합니다. 본 저장소는 검열(censoring)을 올바르게 처리하는 생존모형과 생존 ML을, 무거운 의존성 없이 numpy·scipy만으로 구현한 신용위험 분석 패키지입니다. 의존성이 3개(numpy, pandas, scipy)뿐이라 폐쇄망 금융 환경에도 설치하기 쉽습니다.

Traditional credit scoring treats default as a binary outcome and ignores time-to-event dynamics. This package implements censoring-aware survival models and a random survival forest from scratch on numpy/scipy, so the core install has only three dependencies.

설치 · Installation

pip install "git+https://github.com/DongsooJung/credit-survival-analysis"
# 개발 환경
git clone https://github.com/DongsooJung/credit-survival-analysis.git
cd credit-survival-analysis && pip install -e ".[dev]"

빠른 시작 · Quick Start

import credit_surv as cs

df = cs.load_synthetic_credit_panel(n_firms=2000, seed=42)   # 참값이 알려진 합성 패널
covs = ["debt_ratio", "roa"]

cox = cs.CoxModel()
print(cox.fit(df, covs).summary())            # 계수·HR·표준오차·p·C-index·AIC/BIC
print(cox.check_proportional_hazards())       # Schoenfeld 잔차 비례위험 검정

aft = cs.AFTModel("weibull").fit(df, covs)    # 시간비(TR), Weibull 형상 k
rsf = cs.RSFModel(n_estimators=200)
res = rsf.fit(df[covs], df[["duration", "event"]])
print(res.concordance_index, res.feature_importance)   # OOB C-index, 순열 중요도

구현 현황 · Implementation Status

기능 모듈 상태 검증
Kaplan-Meier 생존함수 models.KaplanMeier ✅ 구현 교과서 예제
Cox PH (Breslow 부분우도, 해석적 헤시안, L2 벌점) models.CoxModel ✅ 구현 lifelines 계수·표준오차 일치
Breslow 기저위험 · 개인별 생존곡선 CoxModel.predict_survival_function ✅ 구현 단조성·경계값
Schoenfeld 잔차 · 비례위험 검정 (rank/identity/log/km) CoxModel.check_proportional_hazards ✅ 구현 lifelines 통계량 일치, 위반 데이터 검출
AFT (Weibull / Log-normal / Log-logistic) models.AFTModel ✅ 구현 lifelines 계수·로그우도 일치
Random Survival Forest (로그순위 분할) models.RSFModel ✅ 구현 OOB C-index, 잡음 변수 판별
OOB 순열 변수중요도 RSFModel.feature_importance ✅ 구현 잡음 변수 ≈ 0
Harrell's C-index (벡터화, 동점 처리) models.concordance_index ✅ 구현 완전탐색 구현과 일치
IPCW Brier · 통합 Brier 점수 models.brier_score, integrated_brier_score ✅ 구현 해석적 경계값
실데이터 로더 (KED·DART parquet) data_loader.load_credit_panel ✅ 구현 필터 단위테스트 (데이터는 비공개)
시점별 AUC (Uno) — 🗺 로드맵 —
DeepSurv · 공간 frailty · 경쟁위험 — 🗺 로드맵 —

정확성 검증 · Validation

같은 합성 패널(n=2,000, 사건 608건)을 lifelines 0.30으로 적합한 결과와 대조해, 아래 값을 회귀 테스트(tests/test_models.py::LIFELINES_REF)로 고정했습니다. CI는 lifelines를 설치하지 않습니다.

항목 본 패키지 lifelines 참값
Cox β(debt_ratio) / SE 0.50275 / 0.04239 0.50275 / 0.04239 0.5
Cox β(roa) / SE −0.31371 / 0.04115 −0.31371 / 0.04115 −0.3
Cox 부분 로그우도 −3978.162 −3978.162 —
비례위험 검정 통계량 (debt_ratio, roa) 0.0958, 0.5515 0.0958, 0.5515 귀무가설 참
Weibull AFT β(debt_ratio) −0.3394 −0.3394 −0.5/1.5 = −0.333
Weibull 형상 k 1.496 1.496 1.5

검증 데이터(30% 분할) 성능 — notebooks/01_credit_survival.ipynb:

모형 C-index 통합 Brier (IPCW)
Kaplan-Meier (기준선) 0.500 0.168
Cox PH 0.637 0.157
Weibull AFT 0.637 0.157
Random Survival Forest 0.626 0.160

데이터가 비례위험 Weibull에서 생성되었으므로 Cox·AFT가 최선이고, RSF는 분포 가정 없이 근접합니다.

프로젝트 구조 · Repository Structure

credit-survival-analysis/
├── src/credit_surv/
│   ├── data_loader.py      # 실데이터 로더, 합성 패널, long → 생존형식 변환
│   └── models.py           # KM, Cox, AFT, RSF, C-index, Brier
├── notebooks/01_credit_survival.ipynb   # KM → Cox → PH 검정 → AFT → RSF → 검증 비교 (실행 결과 포함)
├── tests/test_models.py    # 64개 테스트, 커버리지 90% 미만이면 CI 실패
├── docs/ARCHITECTURE.md    # 수식과 설계
└── pyproject.toml

개발 · Development

pip install -e ".[dev]"
ruff check src tests
pytest --cov --cov-fail-under=90

CI는 Python 3.11·3.12에서 린트·테스트·커버리지를 검사하고, sdist·wheel을 빌드해 twine check와 설치 스모크 테스트를 수행합니다.

참고문헌 · References

  • Cox, D. R. (1972). Regression models and life-tables. JRSS-B, 34(2), 187–202.
  • Breslow, N. (1974). Covariance analysis of censored survival data. Biometrics, 30(1), 89–99.
  • Harrell, F. E. et al. (1982). Evaluating the yield of medical tests. JAMA, 247(18), 2543–2546.
  • Grambsch, P. M., & Therneau, T. M. (1994). Proportional hazards tests and diagnostics based on weighted residuals. Biometrika, 81(3), 515–526.
  • Graf, E. et al. (1999). Assessment and comparison of prognostic classification schemes for survival data. Statistics in Medicine, 18(17–18), 2529–2545.
  • Ishwaran, H. et al. (2008). Random survival forests. Annals of Applied Statistics, 2(3), 841–860.
  • Hosmer, D. W., Lemeshow, S., & May, S. (2008). Applied Survival Analysis. Wiley.

인용 · Citation

CITATION.cff를 참고하세요. GitHub 저장소 화면의 "Cite this repository"에서 BibTeX를 바로 받을 수 있습니다.

라이선스 · License

MIT License

저자 · Author

정동수 (Dongsoo Jung) — 서울대학교 박사과정 · 공간계량 & 금융위험

Metadata

Release files for credit-survival 0.2.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for credit-survival 0.2.0
File Size Uploaded Provenance Actions
credit_survival-0.2.0.tar.gz 30.3 kB With provenance Details for credit_survival-0.2.0.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for credit-survival 0.2.0
File Interpreter ABI Platform Actions
credit_survival-0.2.0-py3-none-any.whl Python 3 none any Details for credit_survival-0.2.0-py3-none-any.whl

Total release size: 52.2 kB

Release files / credit_survival-0.2.0.tar.gz

Download URL credit_survival-0.2.0.tar.gz
Size 30.3 kB
Tags Source
SHA-256 checksum
How to use checksums
14da0247f8a13c159db695b2e4d4b92b23ae7303155a016e01d43484a1936662
BLAKE2b-256 checksum
How to use checksums
a4952b924e30117cc61db6b349d148cd5783440eab2745775d98b62b30eb9634
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Dec 6, 2026.

Transparency log

Release files / credit_survival-0.2.0-py3-none-any.whl

Download URL credit_survival-0.2.0-py3-none-any.whl
Size 21.9 kB
Tags Python 3
SHA-256 checksum
How to use checksums
e6e22e77f63adb98ac9f0abffa713ff26025192b02fca1f1d5be0313f6b7219f
BLAKE2b-256 checksum
How to use checksums
5396021c7b08edc52d5b9d87708c3cf6ee6db9e85db6a395218acb6018a88dba
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Dec 6, 2026.

Transparency log

Security for credit-survival 0.2.0

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

Full provenance

Both files in this release have been uploaded with provenance metadata.

Select from 2 files

Attestation for credit_survival-0.2.0.tar.gz

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Dec 6, 2026.

Transparency log

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Release history Release notifications | RSS feed

This release

0.2.0 This release

2 release files Full provenance

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page