2017-04-05 1 views
0

R 제곱 추정에 대한이 함수의 오차는 무엇입니까?제곱근 추정

def R2(X, Y, model): 
    Y_mean = np.mean(Y, axis=0) 
    pred = model.predict(X) 
    res = np.sum(np.square(Y - pred)) 
    tot = np.sum(np.square(Y - Y_mean)) 
    r2 = 1 - res/tot 

    return r2 

답변

1

좋은 소식은 결정 계수 R2를 계산하는 기능이 올바르다는 것입니다. 예상대로 Y에 대해 Y에 대해 R2를 계산하여이를 테스트 할 수 있습니다.

문제는 Y와 pred의 모양이 같지 않다는 점입니다. pred를 Y 모양으로 일치 시키면 수학 연산이 예상대로 작동합니다.

def R2(X, Y, model): 
    Y_mean = np.mean(Y, axis=0) 
    pred = model.predict(X) 
    print Y.shape, pred.shape 
    pred = pred.reshape(Y.shape[0]) 
    print Y.shape, pred.shape 
    res = np.sum(np.square(Y - pred)) 
    tot = np.sum(np.square(Y - Y_mean)) 
    r2 = 1 - res/tot 

    return r2 
+0

고마워요. 내 잘못이야. 질문과 태그를 수정하여 동일한 문제가있는 사람들이 찾아 사용할 수있게했습니다. – volatile