RuntimeWarning:Numpy遇到溢出

时间:2019-09-17 01:58:38

标签: python numpy overflow linear-regression

我正在得到RuntimeWarning:在执行线性回归算法时,Numpy函数遇到了溢出。这可以通过规范化解决,但是我不想规范化。我尝试了Dtype方法,但不知道将其放在哪里。

RuntimeWarning: overflow encountered in power
  inner = np.power(((X * theta.T) - y), 2)  
RuntimeWarning: overflow encountered in reduce
  return umr_sum(a, axis, dtype, out, keepdims)
RuntimeWarning: invalid value encountered in double_scalars
  temp[0,j] = theta[0,j] - ((alpha / len(X)) * np.sum(term)) 

您能告诉我为了避免错误我可以更改哪些内容。

def computeCost(X, y, theta):    
    inner = np.power(((X * theta.T) - y), 2)  
    return np.sum(inner) / (2 * len(X)) 

for j in range(parameters):

            term = np.multiply(error, X[:,j]) 
            temp[0,j] = theta[0,j] - ((alpha / len(X)) * np.sum(term)) 

添加了数据

150,100,0.73
159,200,1.39
170,350,2.03
175,400,1.45
179,500,1.82
180,180,1.32
189,159,0.83
199,110,0.53
199,400,1.95
199,230,1.27
235,120,0.49
239,340,1.03
239,360,1.24
249,145,0.55
249,400,1.3

0 个答案:

没有答案