LLM 기반 상관관계 분석의 Semantic Causality 평가
Semantic Causality Evaluation of Correlation Analysis Utilizing Large Language Models
TL;DR Highlight
LLM을 전문가 대역으로 써서 상관관계 데이터에서 '진짜 인과관계'만 자동으로 골라내는 방법
Who Should Read
데이터 분석 결과에서 의미 있는 상관관계와 우연한 상관관계를 구분하고 싶은 데이터 분석가 또는 ML 엔지니어. 특히 도메인 전문가 없이 미지의 데이터셋을 탐색해야 하는 상황에 유용.
Core Mechanics
- 상관관계(correlation)는 인과관계(causality)가 아닌데, 지금까지는 이걸 구분하려면 도메인 전문가가 직접 봐야 했음
- GPT 계열 LLM을 도메인 전문가 대역으로 써서 각 상관관계가 실제 인과적 의미가 있는지 자동 판별
- 결과를 'Causal heatmap'이라는 시각화 모델로 표현 — 의미 있는 관계는 강조, 우연한 관계는 억제
- 모르는 데이터셋(unknown dataset)에서도 작동 — 전문 지식 없이 탐색적 분석 가능
- 시각적 품질, 인과 판별 품질, 비교 분석 세 가지 축으로 모델 평가 수행
Evidence
- 실험 결과에서 Causal heatmap이 흥미로운 관계를 명확히 부각하고 무관한 관계를 억제하는 효과가 입증됨 (논문 내 실험적 평가 근거)
- LLM이 인과 평가 태스크에서 사용 가능한 수준의 품질을 보임을 비교 분석으로 확인 — 단, 구체적 수치는 abstract에 미포함
- 미지의 데이터셋에서도 접근법의 잠재적 유용성(potential)이 확인됨
How to Apply
- 기존 상관관계 행렬(correlation matrix)을 만든 뒤, 각 (변수 A, 변수 B) 쌍을 LLM에 넘겨 '이 두 변수 간 인과관계가 실제로 존재하는가?'를 물어보는 파이프라인을 추가하면 됨
- LLM 응답을 점수화해서 heatmap에 오버레이 — 인과 가능성 높은 셀만 강조하도록 시각화 레이어를 수정하는 경우에 적용 가능
- 도메인 전문가가 없는 해커톤, PoC, 탐색적 EDA 단계에서 '일단 LLM한테 물어보고 필터링'하는 빠른 스크리닝 도구로 활용
Code Example
import openai
import pandas as pd
import seaborn as sns
import matplotlib.pyplot as plt
import numpy as np
def causal_score(var_a: str, var_b: str, context: str = "") -> float:
"""LLM에게 두 변수 간 인과 가능성을 0~1로 평가하도록 요청"""
prompt = f"""두 변수 사이에 실제 인과관계(causality)가 존재할 가능성을 평가하세요.
변수 A: {var_a}
변수 B: {var_b}
{f'컨텍스트: {context}' if context else ''}
0.0(완전히 우연/무관) ~ 1.0(명확한 인과관계) 사이의 숫자 하나만 출력하세요."""
response = openai.chat.completions.create(
model="gpt-4",
messages=[{"role": "user", "content": prompt}],
temperature=0
)
try:
return float(response.choices[0].message.content.strip())
except:
return 0.0
def causal_heatmap(df: pd.DataFrame, context: str = ""):
"""상관관계 행렬에 LLM 인과 점수를 곱해 Causal heatmap 생성"""
corr = df.corr()
cols = corr.columns.tolist()
causal_matrix = pd.DataFrame(np.zeros_like(corr.values), index=cols, columns=cols)
for i, a in enumerate(cols):
for j, b in enumerate(cols):
if i < j:
score = causal_score(a, b, context)
causal_matrix.loc[a, b] = score
causal_matrix.loc[b, a] = score
elif i == j:
causal_matrix.loc[a, b] = 1.0
# 상관관계 * 인과 점수 = Causal heatmap
weighted = corr.abs() * causal_matrix
plt.figure(figsize=(10, 8))
sns.heatmap(weighted, annot=True, fmt=".2f", cmap="YlOrRd", vmin=0, vmax=1)
plt.title("Causal Heatmap (correlation × causal score)")
plt.tight_layout()
plt.show()
return weighted
# 사용 예시
# causal_heatmap(df, context="의료 환자 데이터, 변수는 나이/혈압/콜레스테롤 등")Terminology
Original Abstract (Expand)
: It is known that correlation does not imply causality. Some relationships identified in the analysis of data are coincidental or unknown, and some are produced by real-world causality of the situation, which is problematic, since there is a need to differentiate between these two scenarios. Until recently, the proper − semantic − causality of the relationship could have been determined only by human experts from the area of expertise of the studied data. This has changed with the advance of large language models, which are often utilized as surrogates for such human experts, making the process automated and readily available to all data analysts. This motivates the main objective of this work, which is to introduce the design and implementation of a large language model-based semantic causality evaluator based on correlation analysis, together with its visual analysis model called Causal heatmap. After the implementation itself, the model is evaluated from the point of view of the quality of the visual model, from the point of view of the quality of causal evaluation based on large language models, and from the point of view of comparative analysis, while the results reached in the study highlight the usability of large language models in the task and the potential of the proposed approach in the analysis of unknown datasets. The results of the experimental evaluation demonstrate the usefulness of the Causal heatmap method, supported by the evident highlighting of interesting relationships, while suppressing irrelevant ones.