旧 GUI 张冠李戴修复:step6/step8 ML 训练 CSV 强制读 Step 6 特征结果 + step3 默认算法切到 goodman

This commit is contained in:
DXC
2026-06-16 17:53:55 +08:00
parent afe9eaff2c
commit bd4263d2ca
4 changed files with 77 additions and 36 deletions

View File

@ -137,6 +137,15 @@ class Step8MlTrainPanel(QWidget):
self.feature_start.setText("374.285004")
params_layout.addRow("特征起始列:", self.feature_start)
# 特征起始列名提示:用记事本打开 training_spectra.csv 确认首个波长的精确表头
feature_start_hint = QLabel(
"提示:请使用记事本打开 training_spectra.csv 确认首个波长的精确表头名称"
"(如 374.285 或 374.285004)并在此填入,避免因浮点精度差异导致列名匹配失败。"
)
feature_start_hint.setWordWrap(True)
feature_start_hint.setStyleSheet("color: #666; font-size: 10px;")
params_layout.addRow(feature_start_hint)
self.cv_folds = QSpinBox()
self.cv_folds.setRange(2, 10)
self.cv_folds.setValue(3)
@ -357,30 +366,20 @@ class Step8MlTrainPanel(QWidget):
else:
self.work_dir = None
# 1. 尝试从 Step5 界面读取训练数据路径,并确保为绝对路径
# 修复张冠李戴:原代码 main_window.step5_panel 不存在,正确属性是 step5_clean_panel
# 1. 强制读 Step 6 的 training_spectra.csv(光谱特征提取结果)
# 修复张冠李戴:原链路 STEP_DATA_SOURCE['training_spectra_csv'] → step5_clean_panel
# 错误地指向了 Step 5 的 processed_data.csv(纯清洗数据,不含光谱特征),
# 实际 ML 训练需要的特征数据来自 Step 6 的 6_Spectral_Feature_Extraction/training_spectra.csv
main_window = self.window()
step5_output = get_step_output_path(
main_window, 'training_spectra_csv', work_dir=self.work_dir,
widget_attr='output_file', fallback_key='step6_feature',
)
if step5_output:
self.training_csv_file.set_path(step5_output)
else:
# 回退:从 Step5 的 config 字典中查找可能的键名
step5_panel = getattr(main_window, 'step5_clean_panel', None)
if step5_panel and hasattr(step5_panel, 'get_config'):
step5_cfg = step5_panel.get_config()
step5_csv = (
step5_cfg.get('training_csv_path')
or step5_cfg.get('output_file')
or step5_cfg.get('csv_path')
or step5_cfg.get('output_csv')
)
if step5_csv:
if not os.path.isabs(step5_csv):
step5_csv = os.path.join(self.work_dir or '', step5_csv).replace('\\', '/')
self.training_csv_file.set_path(step5_csv)
existing_training_csv = self.training_csv_file.get_path()
if not existing_training_csv or not existing_training_csv.strip():
if self.work_dir:
step6_dir = resolve_subdir(self.work_dir, 'spectral_feature')
step6_training_csv = os.path.join(
step6_dir, 'training_spectra.csv'
).replace('\\', '/')
if step6_training_csv:
self.training_csv_file.set_path(step6_training_csv)
# 2. 自动填充输出文件路径(基于工作目录和输入文件名)
# 输入是 training_spectra.csv → 输出 {work_dir}/7_Water_Quality_Indices/training_spectra_indices.csv