diff --git a/src/core/modeling/modeling_batch.py b/src/core/modeling/modeling_batch.py index 5e27447..83f4eda 100644 --- a/src/core/modeling/modeling_batch.py +++ b/src/core/modeling/modeling_batch.py @@ -14,7 +14,7 @@ from sklearn.svm import SVR from sklearn.ensemble import RandomForestRegressor from sklearn.neighbors import KNeighborsRegressor from sklearn.linear_model import LinearRegression, Ridge, Lasso, ElasticNet -from sklearn.model_selection import RandomizedSearchCV, cross_val_score, KFold, train_test_split +from sklearn.model_selection import GridSearchCV, RandomizedSearchCV, cross_val_score, KFold, train_test_split from sklearn.metrics import mean_squared_error, mean_absolute_error, r2_score from sklearn.cross_decomposition import PLSRegression from sklearn.ensemble import GradientBoostingRegressor, AdaBoostRegressor, ExtraTreesRegressor @@ -646,23 +646,22 @@ class WaterQualityModelingBatch: X_train[~np.isfinite(X_train)] = np.nan X_test[~np.isfinite(X_test)] = np.nan - # RandomizedSearchCV 需要以「步骤名__参数名」的格式索引参数网格; - # 我们原有的 config['params'] 是模型层的(无 __),统一加 model__ 前缀。 + # 以「步骤名__参数名」的格式索引参数网格; + # config['params'] 是模型层的(无 __),统一加 model__ 前缀。 prefixed_params = { f"model__{k}": v for k, v in config['params'].items() } - # 随机搜索:直接对 Pipeline 调优(scaler 仅在 train fold 上 fit) + # 全量网格搜索:SVR 超参组合仅 216 种(4×6×3×3), + # 穷举远优于 RandomizedSearchCV(n_iter=10) 的随机抽样 cv_strategy = KFold(n_splits=cv_folds, shuffle=True, random_state=random_state) - grid_search = RandomizedSearchCV( + grid_search = GridSearchCV( pipeline, prefixed_params, - n_iter=10, cv=cv_strategy, scoring=scoring, n_jobs=safe_n_jobs, - random_state=random_state, verbose=1, )