fix: 修复 Step8 模型生成路径错误及特征分离未过滤坐标列导致的 0 模型 Bug
- view 层 Step8View.update_work_directory 不再生成 <work_dir>/indices/<basename>_indices.csv,改为生成标准的 <work_dir>/8_Modeling/ 模型存放目录;FileSelectWidget 标签与文件过滤器同步调整为目录语义(输出模型目录 / All Files (*.*)),消除'保存目录被存成 csv 文件'导致的 train_models 跳过判定。
This commit is contained in:
@ -288,11 +288,24 @@ class WaterQualityModelingBatch:
|
|||||||
# 提取所有目标列(从0列到feature_start_index-1列)
|
# 提取所有目标列(从0列到feature_start_index-1列)
|
||||||
y_dict = {}
|
y_dict = {}
|
||||||
target_columns = data.columns[:feature_start_index]
|
target_columns = data.columns[:feature_start_index]
|
||||||
|
print(f"检测到的潜在目标列: {list(target_columns)}")
|
||||||
|
|
||||||
print(f"检测到的目标列: {list(target_columns)}")
|
# 新增:跳过非预测目标的系统保留列
|
||||||
|
ignore_cols = {'ID', 'id', 'Id', 'Longitude', 'Latitude', 'Lon', 'Lat', 'longitude', 'latitude', 'lon', 'lat', 'Station', 'station'}
|
||||||
|
|
||||||
for col_name in target_columns:
|
for col_name in target_columns:
|
||||||
|
# 过滤黑名单列
|
||||||
|
if col_name in ignore_cols:
|
||||||
|
print(f" 跳过目标列 '{col_name}': 属于系统保留列或空间坐标")
|
||||||
|
continue
|
||||||
|
|
||||||
y_series = data[col_name]
|
y_series = data[col_name]
|
||||||
|
|
||||||
|
# 过滤非数值类型列 (避免将纯文本备注等拿去回归)
|
||||||
|
if not pd.api.types.is_numeric_dtype(y_series):
|
||||||
|
print(f" 跳过目标列 '{col_name}': 非数值类型")
|
||||||
|
continue
|
||||||
|
|
||||||
# 检查是否有非空值
|
# 检查是否有非空值
|
||||||
if not y_series.isna().all():
|
if not y_series.isna().all():
|
||||||
y_dict[col_name] = y_series
|
y_dict[col_name] = y_series
|
||||||
|
|||||||
@ -141,10 +141,10 @@ class Step8View(BaseView):
|
|||||||
|
|
||||||
# 输出文件路径
|
# 输出文件路径
|
||||||
self.output_path = FileSelectWidget(
|
self.output_path = FileSelectWidget(
|
||||||
"输出文件:",
|
"输出模型目录:",
|
||||||
"CSV Files (*.csv);;All Files (*.*)",
|
"All Files (*.*)",
|
||||||
)
|
)
|
||||||
self.output_path.line_edit.setPlaceholderText("自动生成,或手动指定输出文件路径...")
|
self.output_path.line_edit.setPlaceholderText("自动生成模型存放目录...")
|
||||||
layout.addWidget(self.output_path)
|
layout.addWidget(self.output_path)
|
||||||
|
|
||||||
# 启用步骤
|
# 启用步骤
|
||||||
@ -301,17 +301,11 @@ class Step8View(BaseView):
|
|||||||
step6_training_csv = os.path.join(step6_dir, "training_spectra.csv").replace("\\", "/")
|
step6_training_csv = os.path.join(step6_dir, "training_spectra.csv").replace("\\", "/")
|
||||||
if not self.training_csv_file.get_path():
|
if not self.training_csv_file.get_path():
|
||||||
self.training_csv_file.set_path(step6_training_csv)
|
self.training_csv_file.set_path(step6_training_csv)
|
||||||
# 自动填输出路径
|
|
||||||
indices_dir = _resolve_subdir(work_dir, "indices")
|
# ⬇️ 修复:生成标准的输出目录路径
|
||||||
os.makedirs(indices_dir, exist_ok=True)
|
models_dir = _resolve_subdir(work_dir, "8_Modeling")
|
||||||
training_csv = self.training_csv_file.get_path()
|
os.makedirs(models_dir, exist_ok=True)
|
||||||
if training_csv:
|
self.output_path.set_path(models_dir)
|
||||||
basename = os.path.splitext(os.path.basename(training_csv))[0]
|
|
||||||
output_file = f"{basename}_indices.csv"
|
|
||||||
else:
|
|
||||||
output_file = "training_spectra_indices.csv"
|
|
||||||
output_path = os.path.join(indices_dir, output_file).replace("\\", "/")
|
|
||||||
self.output_path.set_path(output_path)
|
|
||||||
|
|
||||||
# ------------------------------------------------------------------
|
# ------------------------------------------------------------------
|
||||||
# 执行入口
|
# 执行入口
|
||||||
|
|||||||
Reference in New Issue
Block a user