python对二维数组[[-1, 5], [-0.1, 6], [5, 21], [1, 12]]分别实现数据归一化与数据标准化完整代码
时间: 2023-03-12 10:02:42 浏览: 69
Python库 | im2dhist-0.1.0.6-py3-none-any.whl
对二维数组[[-1, 5], [-0.1, 6], [5, 21], [1, 12]]归一化实现代码:def normalization(data):
norm_data = []
for item in data:
norm_data.append([(item[0] - min(data, key=lambda x: x[0])) / (max(data, key=lambda x: x[0]) - min(data, key=lambda x: x[0])), (item[1] - min(data, key=lambda x: x[1])) / (max(data, key=lambda x: x[1]) - min(data, key=lambda x: x[1]))])
return norm_data对二维数组[[-1, 5], [-0.1, 6], [5, 21], [1, 12]]标准化实现代码:def standardization(data):
std_data = []
for item in data:
std_data.append([(item[0] - sum(data, key=lambda x: x[0]) / len(data)) / (max(data, key=lambda x: x[0]) - min(data, key=lambda x: x[0])), (item[1] - sum(data, key=lambda x: x[1]) / len(data)) / (max(data, key=lambda x: x[1]) - min(data, key=lambda x: x[1]))])
return std_data
阅读全文