【发布时间】:2021-11-05 09:24:18
【问题描述】:
以下是我的代码,其中fit_transform() 始终转换为 0。我在模型训练时使用了相同的验证数据和代码,但是在测试中它的行为有所不同。
以下是我的验证数据:
| Date | P1 | P2 |
|---|---|---|
| 2021-01-04 00:00:13 | 2.343674 | 0.000909 |
| 2021-01-04 01:00:00 | -1.339256 | -0.001019 |
| 2021-01-04 02:00:00 | 6.485042 | 0.001654 |
| 2021-01-04 03:00:00 | -3.047014 | -0.002561 |
| 2021-01-04 04:00:00 | 2.308437 | -0.000279 |
测试数据:
| Date | P1 | P2 |
|---|---|---|
| 2021.01.04 00:00:13 | 2.343673841 | 0.0009093321465 |
from sklearn.preprocessing import MinMaxScaler
sc = MinMaxScaler(feature_range = (0, 1))
dataset_test = pd.read_csv("filePath.csv",index_col="Date",parse_dates=True)
test_x = np.array(dataset_test)
test_x = sc.fit_transform(test_x)
print("test_x: ", test_x)
以下是输出:
test_x: [[0. 0.]]
我做错了什么?
【问题讨论】:
-
MinMaxScaler转换每一列而不是行。您只有一行,因此每列中的每个值都是最小值并缩放为0.0。 -
我们不在测试数据上使用
fit_transform;只有transform,带有一个已经适合训练数据的缩放器。
标签: python scikit-learn deep-learning recurrent-neural-network