【问题标题】:StandardScaler in PythonPython 中的标准缩放器
【发布时间】:2021-12-14 14:16:43
【问题描述】:
我想标准化“x_train”。
图中第一个'x_train'是原始数据集,前一个下面的'x_train'是标准化的。
我只是想把前六列标准化,所以标准化的时候写了x_train[:,0:6]。
但是,标准化的结果显然是不合理的。此外,当我使用“x_train”的均值和标准差来标准化 x_test 时,结果是正确的。有点奇怪。我不知道我的代码有什么问题。
以下是我的标准化代码。
【问题讨论】:
标签:
python
arrays
pandas
machine-learning
standardized
【解决方案1】:
试试-
scaler = preprocessing.StandardScaler().fit(x_train.iloc[:, 0:6])
#returning the scaled values to a new variable
X_train_first_six = scaler.transform(x_train.iloc[:, 0:6])
X_test_first_six = scaler.transform(x_test.iloc[:, 0:6])
参考。 pandas iloc
【讨论】:
-
-
@CHIAYI 如果我的回答可能对您有所帮助,请随时单击复选标记 (✔️) 将其标记为已接受,也可以随时使用向上的三角形进行投票。请阅读此link,了解有关接受和支持答案的更多信息。