【发布时间】:2021-06-14 11:52:55
【问题描述】:
我阅读了解释“Why feature scaling only to training set?”的答案 " 答案是“使用训练集均值和标准差标准化任何测试集”
因此,我尝试修复我之前的错误操作。但是,我检查了 StandardScaler() 的 official document,它不支持使用给定的均值和标准进行缩放。像这样:
from sklearn.preprocessing import StandardScaler
sc = StandardScaler(mean = train_x.mean(), var_x = train.std())
sc.fit(test_x)
# this code is incorrect, but what is the correct code?
所以,我的问题是如何根据 python 中训练集的均值和标准来扩展测试集。
【问题讨论】:
-
它将缩放默认值,因为 with_mean 和 with_std 被赋予 True。所以当你通过 test_x 时,它会自动计算平均值和标准,然后处理缩放。你的代码应该是这样的。 sc= StandardScaler() sc.fit(test_x)
标签: python scale normalization standardized