E:\pycharm\代码\.venv\Scripts\python.exe E:\pycharm\代码\代码调试9.py
⚠️ skopt未安装!贝叶斯优化不可用。请运行: pip install scikit-optimize
⚠️ shap未安装!SHAP可解释性不可用。请运行: pip install shap
==========================================================================================
【增强版机器学习分析系统】
基于张继权教授‘四因子理论’:致灾因子、孕灾环境、承灾体、防灾减灾能力
功能:自动区分分类/回归 + 多模型 + PCA降维 + 贝叶斯超参优化 + SHAP可解释性 + 中文可视化
==========================================================================================
📁 数据路径: E:\pycharm\meta\整合数据.csv
🎯 目标变量: PFOA
1. 加载数据...
❌ 编码 'utf-8' 解码失败,尝试下一个...
✅ 数据加载成功!编码: gbk | 形状: (137, 111)
🧹 已删除 96 个 'Unnamed' 列。
2.1 应用张继权教授四因子理论进行特征分组...
【四因子特征分组表】
风险因子 特征数量 特征列表
致灾因子 2 PFBA;PFOS
孕灾环境 2 经度;纬度
承灾体 2 城市;作物类型
防灾减灾能力 0 无
其他 8 样本编号;PFPeA;PFHxA;PFHpA;PFNA;PFDA;PFBS;PFHxS
2. 探索性数据分析(EDA)...
数据基本信息:
统计项 值
样本数 137
特征数 14
目标变量 PFOA
类别数/唯一值 111
🔍 检测到目标变量 'PFOA' 为连续型变量(唯一值占比0.81),切换为回归任务。
3. 数据预处理与标准化...
🧹 检测到 21 个异常值,已限制在合理范围。
训练集: (109, 14), 测试集: (28, 14)
4. 初始化 回归 模型...
✅ 已加载 10 个回归模型
5. 模型训练与评分评估...
➜ 训练 线性回归...
❌ 线性回归 失败: Input y contains NaN.
➜ 训练 决策树回归...
❌ 决策树回归 失败: Input y contains NaN.
➜ 训练 随机森林回归...
❌ 随机森林回归 失败: Input y contains NaN.
➜ 训练 梯度提升回归...
❌ 梯度提升回归 失败: Input y contains NaN.
➜ 训练 XGBoost回归...
❌ XGBoost回归 失败: [16:00:55] C:\buildkite-agent\builds\buildkite-windows-cpu-autoscaling-group-i-08cbc0333d8d4aae1-1\xgboost\xgboost-ci-windows\src\data\data.cc:514: Check failed: valid: Label contains NaN, infinity or a value too large.
➜ 训练 LightGBM回归...
File "E:\pycharm\代码\.venv\lib\site-packages\joblib\externals\loky\backend\context.py", line 257, in _count_physical_cores
cpu_info = subprocess.run(
File "C:\Users\hp\AppData\Local\Programs\Python\Python38\lib\subprocess.py", line 493, in run
with Popen(*popenargs, **kwargs) as process:
File "C:\Users\hp\AppData\Local\Programs\Python\Python38\lib\subprocess.py", line 858, in __init__
self._execute_child(args, executable, preexec_fn, close_fds,
File "C:\Users\hp\AppData\Local\Programs\Python\Python38\lib\subprocess.py", line 1311, in _execute_child
hp, ht, pid, tid = _winapi.CreateProcess(executable, args,
[LightGBM] [Info] Auto-choosing col-wise multi-threading, the overhead of testing was 0.000098 seconds.
You can set `force_col_wise=true` to remove the overhead.
[LightGBM] [Info] Total Bins 270
[LightGBM] [Info] Number of data points in the train set: 109, number of used features: 11
[LightGBM] [Info] Start training from score 0.152646
[LightGBM] [Warning] No further splits with positive gain, best gain: -inf
[LightGBM] [Warning] No further splits with positive gain, best gain: -inf
[LightGBM] [Warning] No further splits with positive gain, best gain: -inf
[LightGBM] [Warning] No further splits with positive gain, best gain: -inf
[LightGBM] [Warning] No further splits with positive gain, best gain: -inf
[LightGBM] [Warning] No further splits with positive gain, best gain: -inf
[LightGBM] [Warning] No further splits with positive gain, best gain: -inf
[LightGBM] [Warning] No further splits with positive gain, best gain: -inf
[LightGBM] [Warning] No further splits with positive gain, best gain: -inf
[LightGBM] [Warning] No further splits with positive gain, best gain: -inf
[LightGBM] [Warning] No further splits with positive gain, best gain: -inf
[LightGBM] [Warning] No further splits with positive gain, best gain: -inf
[LightGBM] [Warning] No further splits with positive gain, best gain: -inf
[LightGBM] [Warning] No further splits with positive gain, best gain: -inf
[LightGBM] [Warning] No further splits with positive gain, best gain: -inf
[LightGBM] [Warning] No further splits with positive gain, best gain: -inf
[LightGBM] [Warning] No further splits with positive gain, best gain: -inf
[LightGBM] [Warning] No further splits with positive gain, best gain: -inf
[LightGBM] [Warning] No further splits with positive gain, best gain: -inf
[LightGBM] [Warning] No further splits with positive gain, best gain: -inf
[LightGBM] [Warning] No further splits with positive gain, best gain: -inf
[LightGBM] [Warning] No further splits with positive gain, best gain: -inf
[LightGBM] [Warning] No further splits with positive gain, best gain: -inf
[LightGBM] [Warning] No further splits with positive gain, best gain: -inf
[LightGBM] [Warning] No further splits with positive gain, best gain: -inf
[LightGBM] [Warning] No further splits with positive gain, best gain: -inf
[LightGBM] [Warning] No further splits with positive gain, best gain: -inf
[LightGBM] [Warning] No further splits with positive gain, best gain: -inf
[LightGBM] [Warning] No further splits with positive gain, best gain: -inf
[LightGBM] [Warning] No further splits with positive gain, best gain: -inf
[LightGBM] [Warning] No further splits with positive gain, best gain: -inf
[LightGBM] [Warning] No further splits with positive gain, best gain: -inf
[LightGBM] [Warning] No further splits with positive gain, best gain: -inf
[LightGBM] [Warning] No further splits with positive gain, best gain: -inf
[LightGBM] [Warning] No further splits with positive gain, best gain: -inf
[LightGBM] [Warning] No further splits with positive gain, best gain: -inf
[LightGBM] [Warning] No further splits with positive gain, best gain: -inf
[LightGBM] [Warning] No further splits with positive gain, best gain: -inf
[LightGBM] [Warning] No further splits with positive gain, best gain: -inf
[LightGBM] [Warning] No further splits with positive gain, best gain: -inf
[LightGBM] [Warning] No further splits with positive gain, best gain: -inf
[LightGBM] [Warning] No further splits with positive gain, best gain: -inf
[LightGBM] [Warning] No further splits with positive gain, best gain: -inf
[LightGBM] [Warning] No further splits with positive gain, best gain: -inf
[LightGBM] [Warning] No further splits with positive gain, best gain: -inf
[LightGBM] [Warning] No further splits with positive gain, best gain: -inf
[LightGBM] [Warning] No further splits with positive gain, best gain: -inf
[LightGBM] [Warning] No further splits with positive gain, best gain: -inf
[LightGBM] [Warning] No further splits with positive gain, best gain: -inf
[LightGBM] [Warning] No further splits with positive gain, best gain: -inf
[LightGBM] [Warning] No further splits with positive gain, best gain: -inf
[LightGBM] [Warning] No further splits with positive gain, best gain: -inf
[LightGBM] [Warning] No further splits with positive gain, best gain: -inf
[LightGBM] [Warning] No further splits with positive gain, best gain: -inf
[LightGBM] [Warning] No further splits with positive gain, best gain: -inf
[LightGBM] [Warning] No further splits with positive gain, best gain: -inf
[LightGBM] [Warning] No further splits with positive gain, best gain: -inf
[LightGBM] [Warning] No further splits with positive gain, best gain: -inf
[LightGBM] [Warning] No further splits with positive gain, best gain: -inf
[LightGBM] [Warning] No further splits with positive gain, best gain: -inf
[LightGBM] [Warning] No further splits with positive gain, best gain: -inf
[LightGBM] [Warning] No further splits with positive gain, best gain: -inf
[LightGBM] [Warning] No further splits with positive gain, best gain: -inf
[LightGBM] [Warning] No further splits with positive gain, best gain: -inf
[LightGBM] [Warning] No further splits with positive gain, best gain: -inf
[LightGBM] [Warning] No further splits with positive gain, best gain: -inf
[LightGBM] [Warning] No further splits with positive gain, best gain: -inf
[LightGBM] [Warning] No further splits with positive gain, best gain: -inf
[LightGBM] [Warning] No further splits with positive gain, best gain: -inf
[LightGBM] [Warning] No further splits with positive gain, best gain: -inf
[LightGBM] [Warning] No further splits with positive gain, best gain: -inf
[LightGBM] [Warning] No further splits with positive gain, best gain: -inf
[LightGBM] [Warning] No further splits with positive gain, best gain: -inf
[LightGBM] [Warning] No further splits with positive gain, best gain: -inf
[LightGBM] [Warning] No further splits with positive gain, best gain: -inf
[LightGBM] [Warning] No further splits with positive gain, best gain: -inf
[LightGBM] [Warning] No further splits with positive gain, best gain: -inf
[LightGBM] [Warning] No further splits with positive gain, best gain: -inf
[LightGBM] [Warning] No further splits with positive gain, best gain: -inf
[LightGBM] [Warning] No further splits with positive gain, best gain: -inf
[LightGBM] [Warning] No further splits with positive gain, best gain: -inf
[LightGBM] [Warning] No further splits with positive gain, best gain: -inf
[LightGBM] [Warning] No further splits with positive gain, best gain: -inf
[LightGBM] [Warning] No further splits with positive gain, best gain: -inf
[LightGBM] [Warning] No further splits with positive gain, best gain: -inf
[LightGBM] [Warning] No further splits with positive gain, best gain: -inf
[LightGBM] [Warning] No further splits with positive gain, best gain: -inf
[LightGBM] [Warning] No further splits with positive gain, best gain: -inf
[LightGBM] [Warning] No further splits with positive gain, best gain: -inf
[LightGBM] [Warning] No further splits with positive gain, best gain: -inf
[LightGBM] [Warning] No further splits with positive gain, best gain: -inf
[LightGBM] [Warning] No further splits with positive gain, best gain: -inf
[LightGBM] [Warning] No further splits with positive gain, best gain: -inf
[LightGBM] [Warning] No further splits with positive gain, best gain: -inf
[LightGBM] [Warning] No further splits with positive gain, best gain: -inf
[LightGBM] [Warning] No further splits with positive gain, best gain: -inf
[LightGBM] [Warning] No further splits with positive gain, best gain: -inf
[LightGBM] [Warning] No further splits with positive gain, best gain: -inf
[LightGBM] [Warning] No further splits with positive gain, best gain: -inf
[LightGBM] [Warning] No further splits with positive gain, best gain: -inf
❌ LightGBM回归 失败: Input contains NaN.
➜ 训练 KNN回归...
❌ KNN回归 失败: Input y contains NaN.
➜ 训练 SVR...
❌ SVR 失败: Input y contains NaN.
➜ 训练 MLP回归...
❌ MLP回归 失败: Input y contains NaN.
➜ 训练 CatBoost回归...
❌ CatBoost回归 失败: catboost/libs/metrics/metric.cpp:6956: metric/loss-function RMSE do not allows nan value on target
Traceback (most recent call last):
File "E:\pycharm\代码\代码调试9.py", line 390, in <module>
pipeline.run_complete_pipeline()
File "E:\pycharm\代码\代码调试9.py", line 376, in run_complete_pipeline
self.train_and_evaluate()
File "E:\pycharm\代码\代码调试9.py", line 350, in train_and_evaluate
results_df.sort_values('r2', ascending=False, inplace=True)
File "E:\pycharm\代码\.venv\lib\site-packages\pandas\core\frame.py", line 6758, in sort_values
k = self._get_label_or_level_values(by, axis=axis)
File "E:\pycharm\代码\.venv\lib\site-packages\pandas\core\generic.py", line 1778, in _get_label_or_level_values
raise KeyError(key)
KeyError: 'r2'
进程已结束,退出代码为 1
继续解决报错并安装未安装的代码,生成完整代码
最新发布