# Show GN: Google CausalImpact R 패키지를 Python으로 포팅 (Gibbs 샘플러는 Rust)

> Clean Markdown view of GeekNews topic #27767. Use the original source for factual precision when an external source URL is present.

## Metadata

- GeekNews HTML: [https://news.hada.io/topic?id=27767](https://news.hada.io/topic?id=27767)
- GeekNews Markdown: [https://news.hada.io/topic/27767.md](https://news.hada.io/topic/27767.md)
- Type: show
- Author: [merumeru](https://news.hada.io/@merumeru)
- Published: 2026-03-23T11:26:11+09:00
- Updated: 2026-03-23T11:26:11+09:00
- Original source: [github.com/YuminosukeSato](https://github.com/YuminosukeSato/bsts-causalimpact)
- Points: 1
- Comments: 1

## Topic Body

Google의 CausalImpact R 패키지를 Python으로 포팅했습니다.  
Gibbs 샘플러를 Rust로 구현하고 PyO3로 Python에서 호출합니다.  
TensorFlow 불필요, R 대비 약 30배 빠릅니다.  
만든 이유:  
기존 Python 포팅들에 문제가 있었습니다. pycausalimpact는  
MLE를 사용해서 R과 결과가 다릅니다. tfcausalimpact는  
TensorFlow(3GB+)가 필요합니다. 그리고 어떤 포팅도  
spike-and-slab 변수 선택을 구현하지 않았습니다.  
R의 bsts가 여러 control 시계열 중 적합한 것을 자동으로  
골라내는 핵심 기능이 바로 이것입니다.  
이 라이브러리는 R의 bsts 패키지와 동일한 Gibbs 샘플러를  
재현합니다. 칼만 필터, 시뮬레이션 스무더, spike-and-slab  
사전분포까지 전부 동일합니다. 매 커밋마다 R CausalImpact  
1.4.1과의 수치 동등성 테스트가 CI에서 실행됩니다  
(포인트 효과 ±3%, CI 범위 ±5%).  
가장 어려웠던 부분은 spike-and-slab이었습니다.  
Coordinate-wise 샘플링과 StudentSpikeSlabPrior 기본값  
(expected.r2=0.8, prior.df=50)을 R 출력과 맞추는 데  
몇 주가 걸렸습니다.  
지원 기능:  
- Spike-and-slab 변수 선택 (R bsts와 동일한 사전분포)  
- 계절성 컴포넌트 (nseasons, season_duration)  
- 동적 회귀 (시변 계수)  
- Local linear trend  
벤치마크 (T=1000, niter=1000):  
- 공변량 없음: 0.07초 (R: 2.1초, 30배)  
- 공변량 5개: 0.20초 (R: 2.2초, 11배)  
  pip install bsts-causalimpact  
GitHub: https://github.com/YuminosukeSato/bsts-causalimpact  
문서: https://yuminosukesato.github.io/bsts-causalimpact/  
시계열 인과추론을 하시는 분들의 피드백을 기다립니다.  
특히 테스트해야 할 edge case가 있다면 알려주세요.

## Comments



### Comment 53701

- Author: shw00
- Created: 2026-03-24T11:27:17+09:00
- Points: 1

멋지네요. 지금 당장 써볼만한 데이터가 없긴 한데 생긴다면 한번 테스트 해보겠습니다.
