y_hat1(x,y) 把他的所以数据按normalize中的最后一列反归一. 看如何修改: def FNormalize_Single(data,norm): listlow = norm[0] listhigh = norm[1] delta = listhigh - listlow if delta != 0: for i in range(len(data)): data[i,0] = data[i,0]*delta + listlow return data #使用训练数据的归一化 def NormalizeMultUseData(data,normalize): data = np.array(data) for i in range(0, data.shape[1]): #第i列 listlow = normalize[i, 0] listhigh = normalize[i, 1] delta = listhigh - listlow if delta != 0: #第j行 for j in range(0,data.shape[0]): data[j,i] = (data[j,i] - listlow)/delta return data
时间: 2024-03-29 07:37:26 浏览: 91
要实现对数据按照normalize中的最后一列进行反归一,需要对函数NormalizeMultUseData进行修改。具体修改如下:
1.首先在函数NormalizeMultUseData中获取最后一列的归一化范围,即listlow和listhigh:
listlow = normalize[-1, 0]
listhigh = normalize[-1, 1]
2.接着对最后一列进行反归一:
delta = listhigh - listlow
if delta != 0:
for j in range(0,data.shape[0]):
data[j,-1] = (data[j,-1] - listlow)/delta
data[j,-1] = data[j,-1]*(normalize[-1,1]-normalize[-1,0])+normalize[-1,0]
注意,这里对最后一列进行反归一后,还需要将数据重新归一化到原来的范围内。
完整的函数修改如下:
def NormalizeMultUseData(data,normalize):
data = np.array(data)
listlow = normalize[-1, 0]
listhigh = normalize[-1, 1]
delta = listhigh - listlow
if delta != 0:
for j in range(0,data.shape[0]):
data[j,-1] = (data[j,-1] - listlow)/delta
data[j,-1] = data[j,-1]*(normalize[-1,1]-normalize[-1,0])+normalize[-1,0]
for i in range(0, data.shape[1]-1):
listlow = normalize[i, 0]
listhigh = normalize[i, 1]
delta = listhigh - listlow
if delta != 0:
for j in range(0,data.shape[0]):
data[j,i] = (data[j,i] - listlow)/delta
return data
阅读全文