数据处理、机器学习基础与降维技术
1. 数据缩放与新数据集创建
在数据处理中,我们常常需要对数据进行缩放操作,以确保各维度数据具有合适的均值和标准差。例如,给定如下向量组:
vectors = [[-3, -1, 1], [-1, 0, 1], [1, 1, 1]]
我们可以使用 scale 函数计算其均值和标准差:
means, stdevs = scale(vectors)
assert means == [-1, 0, 1]
assert stdevs == [2, 1, 0]
接着,我们可以定义一个 rescale 函数来创建新的数据集,该函数会将输入数据重新缩放,使得每个位置的均值为 0,标准差为 1(若某位置标准差为 0,则保持不变):
from typing import List
def rescale(data: List[Vector]) -> List[Vector]:
"""
Rescales the input data so that each position has
mean 0 and standard deviation 1. (Leaves a position
as is if its standard deviation is 0.)
"""
di
超级会员免费看
订阅专栏 解锁全文

被折叠的 条评论
为什么被折叠?



