0

안녕하세요. 회귀 알고리즘에 대해 배우려고했지만 그로부터 기울기 강하가있는 선형 회귀를 구현하고 잔여 합계를 사용하여 수렴을 결정했습니다. 반복의 어느 시점에서 잔여 제곱합에 대한 평가가 나왔다는 것을 알았지 만이 문제를 해결하는 방법을 모르겠습니다. 내가 뭔가 잘못하고 있는거야?그래디언트 descendet의 선형 회귀, 제곱의 오버플로 합계

import math 
import numpy as num 

def get_regression_predictions(input_feature, intercept, slope): 
    predicted_output = [intercept + xi*slope for xi in input_feature] 
    return(predicted_output) 

def get_residual_sum_of_squares(input_feature, output, intercept,slope): 
    return num.sum([(output.iloc[i] - (intercept + slope*input_feature.iloc[i]))**2 for i in range(0,len(output))]) 

def train(input_feature,output,intercept,slope): 
#the start value of intercept and slope are 0 
    last = 0 
    now = math.sqrt(get_residual_sum_of_squares(input_feature,output,intercept,slope)) 

    while abs(last - now) >= 0.01: 
     last = now 
     predictions = get_regression_predictions(input_feature,intercept,slope) 
     errors = [output.iloc[i] - predictions[i] for i in range(0,len(predictions))] 


     adjustements = (sum(errors)*0.05,sum([errors[i]*output.iloc[i] for i in range(0,len(errors))]) *0.05) 

     intercept ,slope = (intercept - adjustements[0],slope - adjustements[1]) 
     now = math.sqrt(get_residual_sum_of_squares(input_feature,output,intercept,slope)) 

return intercept,slope 
+0

"있는 그대로"실행되도록 게시 된 코드를 가져올 수 없으며 적합 할만한 데이터가없는 것으로 보입니다. –

답변

0

확률적인 그래디언트 강하를 시도하십시오. 오버플로로 이어지는 많은 인스턴스 오류를 합산 한 것일 수 있습니다.