fix: PhysicalFeatureExtractor 修复 ndarray 输入时波长丢失问题
- SimpleImputer 把 DataFrame → ndarray,PhysicalFeatureExtractor.fit() 收不到列名导致 ValueError: 必须在 __init__ 中提供 wavelengths - get_preprocessing_transformer 新增 wavelengths 可选参数 - train_single_model 在 DualStream_MNF 时提取 X_raw 波长列表传入工厂 - PhysicalFeatureExtractor 已有 ndarray + wavelengths 参数的处理分支
This commit is contained in:
@ -611,7 +611,11 @@ class WaterQualityModelingBatch:
|
||||
base_model.set_params(verbose=-1)
|
||||
|
||||
# ============ 关键:把预处理器塞进 Pipeline ============
|
||||
preproc = get_preprocessing_transformer(preprocess_method)
|
||||
# DualStream_MNF 需要传入波长列表,供 PhysicalFeatureExtractor 定位波段
|
||||
_wl_list = None
|
||||
if preprocess_method == "DualStream_MNF":
|
||||
_wl_list = self._extract_train_wavelengths(X_raw.columns)
|
||||
preproc = get_preprocessing_transformer(preprocess_method, wavelengths=_wl_list)
|
||||
pipeline = Pipeline([
|
||||
('imputer', SimpleImputer(strategy='median')),
|
||||
('preproc', preproc),
|
||||
|
||||
@ -501,7 +501,7 @@ _PREPROCESSING_TRANSFORMERS = {
|
||||
}
|
||||
|
||||
|
||||
def get_preprocessing_transformer(method: str):
|
||||
def get_preprocessing_transformer(method: str, wavelengths=None):
|
||||
"""根据预处理方法名返回 sklearn 兼容的 Transformer 实例。
|
||||
|
||||
- method 为 "None" 或 None:返回 IdentityTransformer
|
||||
@ -512,6 +512,8 @@ def get_preprocessing_transformer(method: str):
|
||||
|
||||
Args:
|
||||
method: 预处理方法名
|
||||
wavelengths: DualStream_MNF 时需要传入波长列表(float),
|
||||
供 PhysicalFeatureExtractor 定位波段列
|
||||
|
||||
Returns:
|
||||
sklearn 兼容的 Transformer 实例(可直接放入 Pipeline)
|
||||
@ -521,7 +523,7 @@ def get_preprocessing_transformer(method: str):
|
||||
if method == "DualStream_MNF":
|
||||
from sklearn.pipeline import FeatureUnion
|
||||
return FeatureUnion([
|
||||
('physical', PhysicalFeatureExtractor()),
|
||||
('physical', PhysicalFeatureExtractor(wavelengths=wavelengths)),
|
||||
('mnf', MNFTransformer(n_components=10)),
|
||||
])
|
||||
if method not in _PREPROCESSING_TRANSFORMERS:
|
||||
|
||||
Reference in New Issue
Block a user