댓글 0조회 수 9687추천 수 0
?

단축키

이전 문서

다음 문서

+ - Up Down Comment Print
?

단축키

이전 문서

다음 문서

+ - Up Down Comment Print


예측(모델)이 얼마나 현상을 잘 설명하는지에 대한 척도로써 우린 R2 값을 주로 사용한다.


다음은  위키피디아의 설명이다. https://en.wikipedia.org/wiki/Coefficient_of_determination


A data set has n values marked y1...yn (collectively known as yi), each associated with a predicted (or modeled) value f1...fn (known as fi, or sometimes ŷi).

If \bar{y} is the mean of the observed data:

\bar{y}=\frac{1}{n}\sum_{i=1}^n y_i

then the variability of the data set can be measured using three sums of squares formulas:

SS_\text{tot}=\sum_i (y_i-\bar{y})^2,
SS_\text{reg}=\sum_i (f_i -\bar{y})^2,
SS_\text{res}=\sum_i (y_i - f_i)^2\,

The most general definition of the coefficient of determination is

R^2 \equiv 1 - {SS_{\rm res}\over SS_{\rm tot}}.\,


자 수식은 간단하게 설명되었다.

관측값의 평균

각 관측값과 관측값의 평균과의 편차의 제곱들의 합

각 예측값과 관측값의 평균과의 편차의 제곱들의 합,

각 관측값과 각 예측값에 대한 편차의 제곱들의 합,

그 중 SSres와 SStot 만을 사용하면 R2을 구할 수 있다.


global_m 모듈에 get_average() 함수로 평균을 구하는 함수로.. sp, dp도 선언되어있음..

sp용 dp용을 만들어 제네릭 프로그래밍


module regression_m
    use :: global_m
    implicit none

    interface rsquare
        module procedure rsquare_sp, rsquare_dp
    end interface

contains

    pure function rsquare_sp (y, f) result (rsquared)
        real(kind=sp), intent(in   ) :: y(:), f(:)
        real(kind=sp) :: rsquared, ssres, sstot, ym

        ym = get_average(y)
        sstot = sum((y - ym)**2)
        ssres = sum((y - f)**2)

        rsquared = 1.0_sp - (ssres/sstot)

    end function 

    pure function rsquare_dp (y, f) result (rsquared)
        real(kind=dp), intent(in   ) :: y(:), f(:)
        real(kind=dp) :: rsquared, ssres, sstot, ym

        ym = get_average(y)
        sstot = sum((y - ym)**2)
        ssres = sum((y - f)**2)

        rsquared = 1.0_dp - (ssres/sstot)

    end function
    
end module


?

번호 제목 글쓴이 날짜 조회 수
» R^2 (Coefficient of determination) 를 구해보자.   연필 2016.01.22 9687
Board Pagination ‹ Prev 1 Next ›
/ 1
Designed by hikaru100

나눔글꼴 설치 안내


이 PC에는 나눔글꼴이 설치되어 있지 않습니다.

이 사이트를 나눔글꼴로 보기 위해서는
나눔글꼴을 설치해야 합니다.

설치 취소

SketchBook5,스케치북5

SketchBook5,스케치북5

SketchBook5,스케치북5

SketchBook5,스케치북5

XE Login