Skip to content

Instantly share code, notes, and snippets.

View yonghanjung's full-sized avatar

Yonghan Jung yonghanjung

View GitHub Profile

2. 인과관계란?

이번 글에서는, 인과관계 (Causation)의 개념을 구체화하고자 합니다.

일반적으로 경제학/예방의학 등의 학문에서는 ceterius paribus ('다른 모든 조건이 동일할 때' 를 뜻하는 라틴어) 라는 널리 사용되는 가정이 있습니다. $X,Y$ 두 변수 사이의 관계를 설명할 때, 제 3의 변수 ($Z$) 가 개입하여 $(X,Y)$ 사이의 관계를 혼동시키는 것을 막기 위해서, 다른 모든 조건 (i.e., $Z$)이 동일할 때, $X$가 변하면 $Y$가 어떻게 변하는지 설명하기 위한 조건입니다. 위의 예시에 이 조건을 적용하면 ‘연령’ 이라는 제 3의 변수가 (운동, 콜레스테롤) 의 관계를 혼동시키고 있는 것을 알 수 있습니다. 이를 막기 위해서 우리는 ‘다른 모든 조건 (i.e., 연령) 가 동일할 때’ 운동과 콜레스테롤의 관계를 보아야 합니다.

Ceterius Paribus 를 수학적 개념으로 정의하고 이론으로 발전시킨 사람은 Donald Rudin (https://en.wikipedia.org/wiki/Donald_Rubin) 입니다. $X,Y$ 가 각각 관심있는 원인, 결과에 해당하는 변수일 때, Rudin 은 다른 모든 조건이 동일할 때, $X=x$ 일 때 확률변수 $Y$ 을 표현하기 위해 $Y_x$ 라는 변수를 도입했습니다.

이 새로운 변수 $Y_x$ 는 처음에는 상당히 생소하고 이질적으로 보일 것입니다. 구체적으로, $X=x$ 가 주어져있을 때 확률변수 $Y$ (즉, $Y\vert x$) 와 무엇이 다른지 언뜻 구분이 가지 않을 것입니다. 따라서, $Y_x$$Y \vert x$ 를 명징히 구분해 보겠습니다. 논의를 실제 예시와 연관지어 진행하기 위해서, 이 글에서는 $X=1$ 은 운동을 함 / $X=0$ 은 운동을 안함이라고 정의하겠습니다. 또한, $Y$ 는 콜레스테롤 수치라고 가정하겠습니다. 우리가 수집한 환자집단을 $\Pi$ 라고 적겠습니다.

@yonghanjung
yonghanjung / SGD.py
Last active November 11, 2018 06:18
SGD
import struct
import numpy as np
import gzip
import copy
import matplotlib.pyplot as plt
from sklearn.linear_model import LogisticRegression
''' Preprocessing: Train, Test '''
# Train and Test
def read_idx(filename):
@yonghanjung
yonghanjung / experiment_SGD.py
Last active November 11, 2018 06:19
SGD experiment
import struct
import numpy as np
import gzip
import pickle
import copy.copy
''' Preprocessing: Train, Test '''
# Train and Test
def read_idx(filename):
with gzip.open(filename, 'rb') as f:
@yonghanjung
yonghanjung / experiment_GD.py
Last active November 11, 2018 03:47
GD experiment
import struct
import numpy as np
import gzip
import pickle
''' Preprocessing: Train, Test '''
# Train and Test
def read_idx(filename):
with gzip.open(filename, 'rb') as f:
zero, data_type, dims = struct.unpack('>HBB', f.read(4))
@yonghanjung
yonghanjung / CS590_HW3_Prob2.py
Created April 15, 2018 01:33
CS590 HW3 Prob 2-a
import numpy as np
def binarize(num):
binnum = bin(num)[2:]
if len(binnum) < 3:
rem_num = 3 - len(binnum)
return '0'*rem_num + binnum
else:
return binnum
@yonghanjung
yonghanjung / Example_pcalg.R
Last active July 28, 2017 22:55
Example: pcalg
library(pcalg)
df <- read.csv("Data/reduce_final_R.csv") # Load CSV file as dataframe format.
# re-encode into matrix format.
matrix_df = data.matrix(df[,c(2:20)])
# PC Algorithm
## Parameters
SuffStat = list(C=cor(matrix_df),n=nrow(matrix_df))
@yonghanjung
yonghanjung / Hoons.py
Last active September 24, 2015 01:34
# -*- coding: utf-8 -*-
__author__ = 'jeong-yonghan'
import csv
import numpy as np
import urllib
import re
import time
HoonsName = "Loc.txt"
@yonghanjung
yonghanjung / HW1.m
Created September 6, 2015 05:00
(2015.09.06) ConvexOpt Hw1 Yonghan Jung
function FunVal = HW1(x, Mat_A, Vec_b )
% A : n dimensional vector, m vectors
% b : b(n by 1)
[m,n] = size(Mat_A);
SumVal = 0;
for idx = (1:n)
Val = Vec_b(idx) - dot(Mat_A(:,idx), x) ;
Val = log(Val);
SumVal = SumVal + Val;
end
// g++ -std=c++11 $(pkg-config --cflags --libs opencv) Letter_Detect_ver0.0.cpp -o letter
// "A" 2, 6, 7, 85, 10
// "B", 1, 3, 6, 7, 8, 10
// "C" 1, 3, 7, 10
// "D" 0, 2, 3, 4, 5, 6, 7, 8, 10
// "E": 1, 3, 4, 5, 7, 8, 9, 10
/* ============== Library ================= */
@yonghanjung
yonghanjung / EM_Algorithm.cpp
Created November 18, 2014 05:43
EM Algorithm
#include <iostream>
#include <fstream>
#include <string>
#include <vector>
#include <cstdlib>
#include <cmath>
#define MAX_TOK 10
#define PI 3.14159265359