清洗实验数据,对数据进行归一化

从第40列开始,之后所有列的数据,都需要进行归一化。data是 torch.FloatTensor(data[indices])格式的数据,跟numpy 差不太多哈。
1、减去均值;
2、除上这一列的std(标准差);


# Normalize features (you may remove this part to see what will happen)
self.data[:, 40:] = \
    (self.data[:, 40:] - self.data[:, 40:].mean(dim=0, keepdim=True)) \
    / self.data[:, 40:].std(dim=0, keepdim=True)

以上的应该是对pandas数据类型进行归一化。

下边的是对numpy数组进行归一化

test_dlc_result = list(csv.reader(fp))
test_dlc_result = np.array(test_dlc_result).astype(float) #需要对结果进行归一化
mean = test_dlc_result.mean(axis=1, keepdims=True)
std = test_dlc_result.std(axis=1, keepdims=True)
test_dlc_result= (test_dlc_result - mean) / std
posted @ 2022-03-20 21:37  bH1pJ  阅读(187)  评论(0编辑  收藏  举报