Coefficient of Determination
데이터에 대한 현재 regression 모델의 성능(or 적합도)를 평가함 → 1에 가까울수록 좋은 모델임.
- 통계 (linear model)에서 사용되는 경우에는 최소값이 0이 보장되나,
- ML등에서 regression model의 성능 평가에서는 음수도 나올 수 있음(non-linear인 경우)
- ML 등에서 regression model이 얼마나 정확하게 data에 fitting 되었는지를 나타냄.
Linear model 을 사용하는 Regression Analysis 에서 중요하게 다루는 지표.
- Squared Correlaton Coefficient라고도 불림. (Multiple correlation coefficient인 R의 제곱)
coef. of determination이
multiple correlation coef.의 제곱과 같으려면
반드시 linear model이어야 함.
통계(linear model, 최소자승법)에서는 “데이터의 variability”를 모델이 얼마나 설명하고 있는지를 나타냄.
- 모델이 다루는 independent variables 로
- Dependent variable의 variability (변동성)를 어느 정도로 예측 가능한지 를 나타냄.
- 다시 말하면, dependent variable의 variability를 independet variables가 설명하고 있는지를 나타냄 (설명력).
수식은 다음과 같음.
R2=1−∑Ni=1(yi−ˆyi)2∑Ni=1(yi−μ)2(eq.1)=∑Ni=1(ˆyi−μ)2∑Ni=1(yi−μ)2(eq.2)
- eq.1는 ML 등에서 regression model의 performance를 나타내는 metric 으로 사용할 때 식임.
- non-linear에서도 적용되기 때문에 ML 등에서 활용도가 높음.
- 일종의 utility function 으로 볼 수 있음.
- eq.2은 통계적 관점에서 선형 모델의 설명력 을 의미함.
- 이는 linear model에서만 적용가능하며, 이 경우 residual의 expected value가 0이고, residual과 ˆY간에 covariance가 0임.
- 이 경우, 결정계수가 Multiple correlation coefficient의 제곱과 같음.
- 단, non-linear 인 경우엔 성립하지 않는다. 즉, 통계적 관점으로 mutiple correlaton coef.의 제곱으로 볼 수 없다.
위의 수식에서처럼 eq.1과 eq.2가 같으려면
- residual의 expected value가 0이라는 가정 과
- residual과 predicted value간의 covariance가 0이라는 가정 이 성립해야 한다.
이 두 가정은 linear model에서 성립: 최소자승법 기반의 regression 이 수행된 경우임.
2022.04.28 - [.../Math] - Ordinary Least Squares : OLS, 최소자승법
Ordinary Least Squares : OLS, 최소자승법
Solution을 구할 수 없는 Over-determined system에서 solution의 근사치(approximation)을 구할 수 있게 해주는 방법임. Machine Learning에서 Supervised Learning의 대표적인 task인 Regression을 해결하는 가장 간단한 알고
dsaint31.tistory.com
Residual의 관점에서 살펴본 R squared
residual=Y−ˆY 이므로, Y=ˆY+residual 이 성립함.
- Y: random variable Y. 측정치
- ˆY: predicted variable. 모델이 예측한 값.
즉, residuali=ϵi=yi−ˆyi
R2의 denominator를 residual로 나타내면 다음과 같음.
N∑i=1(yi−μ)2=N∑i=1(ˆyi−μ)2+N∑i=1residual2i=N∑i=1(ˆyi−μ)2+N∑i=1ϵ2iTotal Sum of Squares=Explained Sum of Squares+Residual Sum of SquaresTSS=ESS+RSS
- TSS 는 Y의 variability임 : Y와 평균 μ와의 difference 들의 제곱으로 표현할 수 있는데 (위 식의 left side)
- ESS 는 모델에 의해 설명된 variability임. (위 식의 right side의 첫번째 항)
- RSS 는 모델이 설명하지 못한 나머지 variability에 해당함.
결국, 위 식은
측정된 Y에서의 variability(TSS)가
- 모델이 설명하는 variability(ESS)와
- 설명치 못하는 RSS로 구성됨을 의미한다.
위의 식은
residual의 expected value가 0이라는 가정과
residual 과 모델의 예측치간의 공분산이 0이라는 가정 하에 유도됨.∑Ni=1residualiN=0⇒∑Ni=1residuali=0⇒∑Ni=1ϵi=0
위의 식의 유도는 다음을 참고하라.
N∑i=1(yi−μ)2=N∑i=1(yi−ˆyi+ˆy−μ)2=N∑i=1{(ˆyi−μ)+(yi−ˆyi)}2=N∑i=1{(ˆyi−μ)+residuali}2=N∑i=1{(ˆyi−μ)+ϵi}2=N∑i=1{(ˆyi−μ)2+ϵ2i+2(ˆyi−μ)ϵi}=N∑i=1(ˆyi−μ)2+N∑i=1ϵ2i+2N∑i=1(ˆyi−μ)ϵi=N∑i=1(ˆyi−μ)2+N∑i=1ϵ2i+2N∑i=1(β0+β1x1i+⋯+βpxpi−μ)ϵi=N∑i=1(ˆyi−μ)2+N∑i=1ϵ2i+2(β0−μ)N∑i=1ϵi+2β1N∑i=1ϵix1i+⋯+2βpN∑i=1ϵixpi=N∑i=1(ˆyi−μ)2+N∑i=1ϵ2i
이는 다음의 등식이 성립함을 의미함.
N∑i=1(yi−μ)2=N∑i=1(ˆyi−μ)2+N∑i=1residual2i
이를 R2의 식에 적용하면 다음이 성립함.
R2=1−∑Ni=1(yi−ˆyi)2∑Ni=1(yi−μ)2=1−∑Ni=1residual2i∑Ni=1(yi−μ)2=∑Ni=1(yi−μ)2−∑Ni=1(yi−ˆyi)2∑Ni=1(yi−μ)2=∑Ni=1(ˆyi−μ)2+∑Ni=1residual2i−∑Ni=1(yi−ˆyi)2∑Ni=1(yi−μ)2=∑Ni=1(ˆyi−μ)2∑Ni=1(yi−μ)2=ESSTSS
참고로,
Multiple regression에서 multiple correlation coefficient를 R로 주로 표기하고,
simple regression 에 사용되는 correlation coefficient는 주로 r로 표기됨.
같이 읽어보면 좋은 자료
아래 URL은 multiple correlation coef.와 coef. of determination이 엄밀하게는 다른 이유를 보다 쉽게 설명함.
결정계수 R^2, 상관계수의 제곱 r^2의 차이 증명(Coefficient of determination VS Squared correlation coefficient)
Introduction 많은 이들이 결정계수 R^2과 상관계수의 제곱 r^2을 동등하게 여긴다. 이는 통계학에서 두드러지는데, 실제로 책 에서는 결정계수를 r^2으로 계산하도록 하고, 통계학 특화 프로그래밍
rython.tistory.com
https://zetawiki.com/wiki/%EA%B2%B0%EC%A0%95%EA%B3%84%EC%88%98_R%C2%B2
결정계수 R² - 제타위키
다음 문자열 포함...
zetawiki.com
https://en.wikipedia.org/wiki/Partition_of_sums_of_squares
Partition of sums of squares - Wikipedia
From Wikipedia, the free encyclopedia Concept that permeates much of inferential statistics and descriptive statistics This article is about the partition of sums of squares in statistics. For other uses, see Sum of squares. The partition of sums of square
en.wikipedia.org
https://velog.io/@yoonene/R-squared%EB%9E%80
R-squared란?
Q: R square의 의미는 무엇인가요?
velog.io
2022.05.01 - [.../Math] - [Statistics] Covariance vs. Correlation
[Statistics] Covariance vs. Correlation
Covariance vs. CorrelationCovariance (공분산)"Covariance" is the raw version of correlation.두 random variable(확률변수)가 얼마나 (선형적으로) 같이 변하는 정도를 나타냄.여러 random variables 에서는 matrix로 기재
dsaint31.tistory.com