归一化特征值
程序员文章站
2022-07-15 10:55:22
...
def autoNorm(dataSet):
minVals = dataSet.min(0)
maxVals = dataSet.max(0)
ranges = maxVals - minVals
normDataSet = zeros(shape(dataSet))
m = dataSet.shape[0]
normDataSet = dataSet - tile(minVals, (m, 1))
normDataSet = normDataSet / tile(ranges, (m, 1)) # element wise divide
return normDataSet, ranges, minVals
dataset.min(0)是提取一个矩阵的每列的最小值,然后组成一个行向量,例如:
[[1,2,5],
[4,8,8],
[0,6,4]] 结果为[0,2,4]
tile(minVals, (m, 1))是把一个矩阵搞成m行倍,列为1倍,例如::tile(minVals, (4, 1))
结果为: [[0,2,4],
[0,2,4],
[0,2,4],
[0,2,4]]