You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

应用MinMax缩放是否需独立处理各列及建模效果差问题咨询

问题解答

关于MinMax缩放的列处理规则

MinMaxScaler默认对输入的每一列独立计算最大值、最小值完成缩放,不需要额外对单列做单独处理,你拆分特征、目标分别用两个scaler的逻辑本身是正确的。

现有流程的核心错误

你当前建模结果不佳的核心原因是流程顺序错误,存在严重的数据泄露问题,具体问题如下:

  • 预处理时机错误:你在拆分训练集、测试集之前就对全量数据集做了缩放和平滑,相当于测试集的数据特征提前泄露给了预处理环节,模型学到的分布包含了测试集的信息,泛化能力会严重下降,最终预测结果必然失真。
  • 操作顺序颠倒:你先做缩放再做卡尔曼平滑的逻辑是错误的。平滑是针对原始时序的噪声、趋势做修正,应该先对原始数据做平滑,再做缩放。如果先把数据压缩到0-1区间再平滑,你预设的噪声参数(level:0.1、trend:0.1)和原始数据的噪声特征完全不匹配,平滑效果会大幅下降。

正确的实现流程参考

# 第一步:先按时间顺序拆分训练集、测试集(时序数据禁止随机打乱拆分)
train_size = int(len(raw_df) * 0.8)
train_df = raw_df.iloc[:train_size, :]
test_df = raw_df.iloc[train_size:, :]

# 第二步:拆分特征、目标列
train_features = train_df.iloc[:, :5].values
train_targets = train_df.iloc[:, 5:].values
test_features = test_df.iloc[:, :5].values
test_targets = test_df.iloc[:, 5:].values

# 第三步:对特征、目标分别做卡尔曼平滑
smoother=tsmoothie.KalmanSmoother(component='level_trend',  component_noise={'level':0.1, 'trend':0.1})
# 处理训练特征
smoother.smooth(train_features)
smoothed_train_features = smoother.smooth_data
# 处理测试特征
smoother.smooth(test_features)
smoothed_test_features = smoother.smooth_data
# 处理训练目标
smoother.smooth(train_targets)
smoothed_train_targets = smoother.smooth_data
# 处理测试目标
smoother.smooth(test_targets)
smoothed_test_targets = smoother.smooth_data

# 第四步:做MinMax缩放,scaler仅在训练集数据上拟合
scaler_features = MinMaxScaler(feature_range=(0,1))
scaler_targets = MinMaxScaler(feature_range=(0,1))
norm_train_features = scaler_features.fit_transform(smoothed_train_features)
norm_test_features = scaler_features.transform(smoothed_test_features)
norm_train_targets = scaler_targets.fit_transform(smoothed_train_targets)
norm_test_targets = scaler_targets.transform(smoothed_test_targets)

# 第五步:训练模型
model.fit(norm_train_features, norm_train_targets)

# 第六步:预测并执行逆缩放
test_predict = model.predict(norm_test_features)
inv_test_predict = scaler_targets.inverse_transform(test_predict)

额外注意事项

需要确认模型的预测输出维度和目标列的维度一致(3列),否则逆缩放操作会报错或者得到错误结果。

内容的提问来源于stack exchange,提问作者Sandeep Kumar Kushwaha

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.09.25 04:54:02