当前位置:首页>python>TabPFN六种机器学习+性能对比图-Python

TabPFN六种机器学习+性能对比图-Python

  • 2026-08-19 17:15:50
TabPFN六种机器学习+性能对比图-Python

点击上方蓝字关注我们

做机器学习预测时,只展示一个模型的R²,往往很难判断它到底是真的预测得好,还是只在训练数据上表现优秀。尤其是同时使用多种模型时,如果训练集、测试集和交叉验证结果分散在不同表格和图片中,模型之间的差异很难被直观比较。
这套代码同时建立ElasticNet、随机森林、XGBoost、LightGBM、CatBoost和TabPFN六种回归模型,通过网格搜索优化模型参数,并分别计算训练集R²、测试集R²、交叉验证R²、RMSE和MAE。最终,上方条形图集中比较六个模型的三类R²,下方六张散点图分别展示真实值与预测值之间的对应关系。
除了模型训练和绘图,代码还加入了GPU自动识别和模型缓存功能。数据和参数没有发生变化时,程序可以直接读取已经训练好的模型,避免重复执行耗时的网格搜索。模型性能、最优参数、预测值、特征重要性和缓存信息也会统一导出到Excel,比较适合环境、生态、遥感和社会经济指标的回归预测研究。下面是完整代码拆解:
数据代码均文末免费获取,无套路!
测试数据格式:
    1.先导入数据处理、机器学习、模型缓存和绘图需要的全部库。代码通过try/except检查XGBoost、LightGBM、CatBoost和TabPFN是否已经安装,缺少依赖时会直接给出对应的安装命令。随后使用PyTorch检测CUDA环境:如果电脑上存在可用的NVIDIA显卡,TabPFN、XGBoost和CatBoost会自动启用GPU;否则全部使用CPU运行。
    # -*- coding: utf-8 -*-”””========================================================================脚本功能: 复现论文图(Train/Test/CV R² 条形图 + 6个模型 Truth vs Predicted 散点图) 因变量:HQ 自变量:DEM, dist_waterway, TEMP, PRCP, Population, LHGI, GPP, FTI, LE, ETP, Nightlight, RX5day, CDD, TNn, TXx 模型:ElasticNet、RandomForest、XGBoost、 LightGBM、CatBoost、TabPFN依赖库(如未安装,请先在命令行执行下列命令安装): pip install pandas numpy scikit-learn matplotlib seaborn openpyxl pip install xgboost lightgbm catboost pip install tabpfn公众号、小红薯、dou音:地数空间  -微信小程序:地学小助手作者:太阳花🌻# ------------------------------------------------------------------# 第一部分:导入所需的库# ------------------------------------------------------------------import os# 用于处理文件路径、创建文件夹import warnings# 用于屏蔽不影响结果的警告信息import hashlib# 用于生成数据/配置指纹,判断模型缓存是否仍然有效import json# 用于保存模型缓存的元数据from datetime import datetime# 用于记录模型缓存创建时间from importlib.metadata import version as package_versionimport numpy as np# 数值计算import pandas as pd# 数据读取与表格处理import joblib# 保存和加载训练完成的模型import matplotlib.pyplot as plt# 绘图import matplotlib as mpl# 用于全局字体等参数设置from matplotlib.ticker import MaxNLocator, MultipleLocatorimport seaborn as sns# 用于绘制带置信区间的回归趋势线from sklearn.model_selection import train_test_split, KFold, cross_val_score, GridSearchCV# train_test_split:划分训练集/测试集# KFold, cross_val_score:交叉验证# GridSearchCV:网格搜索超参数from sklearn.linear_model import ElasticNet# 弹性网络回归(替代原文LR)from sklearn.ensemble import RandomForestRegressor# 随机森林from sklearn.metrics import r2_score, mean_squared_error, mean_absolute_error# r2_score, mean_squared_error, mean_absolute_error:评价指标# 下面几个是第三方梯度提升库和TabPFN库,如未安装会报错,故用try/except提示用户try: from xgboost import XGBRegressor# XGBoost回归器except ImportError: raise ImportError(”未检测到xgboost,请先执行: pip install xgboost”)try: from lightgbm import LGBMRegressor# LightGBM回归器except ImportError: raise ImportError(”未检测到lightgbm,请先执行: pip install lightgbm”)try: from catboost import CatBoostRegressor# CatBoost回归器except ImportError: raise ImportError(”未检测到catboost,请先执行: pip install catboost”)try: from tabpfn import TabPFNRegressor# TabPFN回归器(基础模型)except ImportError: raise ImportError(”未检测到tabpfn,请先执行: pip install tabpfn”)warnings.filterwarnings(”ignore”)# 屏蔽无关紧要的警告(不影响结果正确性)# ------------------------------------------------------------------# 第一.五部分:检测本机是否有可用的CUDA GPU,供TabPFN与树模型调用# ------------------------------------------------------------------try: import torch# TabPFN底层依赖torch,用torch判断CUDA是否可用 USE_CUDA = torch.cuda.is_available()# True表示检测到可用的NVIDIA GPUexcept ImportError: USE_CUDA = False# 未安装torch时,视为无GPU,全部走CPUDEVICE = ”cuda” if USE_CUDA else ”cpu”# TabPFN使用的设备字符串if USE_CUDA: gpu_name = torch.cuda.get_device_name(0) print(f”检测到可用GPU:{gpu_name},TabPFN与支持GPU的树模型将使用CUDA加速。”)else: print(”未检测到可用的CUDA GPU(或未安装torch/GPU版驱动),所有模型将使用CPU运行。”)
      2.这一部分统一控制整张图的字体、字号、坐标轴和文件输出参数。PDF字体类型设为42,可以将文字以TrueType形式嵌入,方便后期在Illustrator等软件中继续编辑。实际使用时,主要修改input_dir,将其替换为自己的数据目录;程序会自动创建outputs和models两个结果文件夹。
      # ------------------------------------------------------------------# 第二部分:全局绘图参数设置(按用户要求)# ------------------------------------------------------------------mpl.rcParams.update({ ”font.family”: ”serif”, ”font.serif”: [”Times New Roman”], ”mathtext.fontset”: ”custom”, ”mathtext.rm”: ”Times New Roman”, ”mathtext.it”: ”Times New Roman:italic”, ”mathtext.bf”: ”Times New Roman:bold”, ”font.size”: 11.5, ”axes.titlesize”: 13, ”axes.labelsize”: 12, ”xtick.labelsize”: 10.5, ”ytick.labelsize”: 10.5, ”legend.fontsize”: 10, ”pdf.fonttype”: 42,# PDF嵌入TrueType字体,便于后期编辑 ”ps.fonttype”: 42, ”axes.unicode_minus”: False, ”axes.linewidth”: 0.8, ”savefig.facecolor”: ”white”,})# ------------------------------------------------------------------# 第三部分:定义输入/输出目录(要求输入输出目录不同,且输出目录若不存在则自动创建)# ------------------------------------------------------------------input_dir = r”E:\data_study5”# 数据所在的输入目录output_dir = os.path.join(input_dir, ”outputs”)# 所有结果均保存在工作空间内部models_dir = os.path.join(output_dir, ”models”)# 已训练模型及缓存元数据# 如果输出目录不存在,则递归创建if not os.path.exists(output_dir): os.makedirs(output_dir) print(f”输出目录不存在,已自动创建:{output_dir}”)else: print(f”输出目录已存在,将直接使用:{output_dir}”)os.makedirs(models_dir, exist_ok=True)# 定义输入数据文件的完整路径input_file = os.path.join(input_dir, ”data.xlsx”)# 定义最终输出文件的完整路径output_pdf_path = os.path.join(output_dir, ”model_comparison_figure.pdf”)# 图形PDF输出路径output_jpg_path = os.path.join(output_dir, ”model_comparison_figure.jpg”)# 高分辨率JPG输出路径output_excel_path = os.path.join(output_dir, ”model_process_data.xlsx”)# 过程数据Excel输出路径
        3.代码从data.xlsx中读取数据,将DEM、气温、降水、人口、夜间灯光和极端气候指数等15个变量作为自变量,将HQ作为因变量。含缺失值的记录会被整体删除,然后按照80%和20%的比例划分训练集与测试集,并固定随机种子为42。这里还定义了5折交叉验证,并根据训练数据生成SHA-256指纹,为后面的模型缓存校验提供依据。
        # ------------------------------------------------------------------# 第四部分:读取数据# ------------------------------------------------------------------df = pd.read_excel(input_file)# 读取Excel数据到DataFrame# 定义自变量(特征)列表,严格按照用户提供的列名feature_cols = [”DEM”, ”dist_waterway”, ”TEMP”, ”PRCP”, ”Population”, ”LHGI”, ”GPP”, ”FTI”, ”LE”, ”ETP”, ”Nightlight”, ”RX5day”, ”CDD”, ”TNn”, ”TXx”]target_col = ”HQ”# 因变量列名# 提取特征矩阵X和目标向量y,并丢弃含缺失值的行(保证建模数据完整)model_df = df[feature_cols + [target_col]].dropna().reset_index(drop=True)X = model_df[feature_cols].values# 自变量矩阵y = model_df[target_col].values# 因变量向量print(f”建模数据量:{X.shape[0]} 行,{X.shape[1]} 个特征”)# ------------------------------------------------------------------# 第五部分:划分训练集与测试集(80% 训练,20% 测试)# ------------------------------------------------------------------X_train, X_test, y_train, y_test = train_test_split( X, y, test_size=0.2, random_state=42# random_state固定,保证结果可复现)# 定义5折交叉验证方案,用于计算CV Val R²kfold = KFold(n_splits=5, shuffle=True, random_state=42)# 训练数据指纹:只要数据内容或划分发生变化,旧模型缓存就会自动失效training_data_hasher = hashlib.sha256()for array in (X_train, y_train): contiguous_array = np.ascontiguousarray(array) training_data_hasher.update(str(contiguous_array.shape).encode(”utf-8”)) training_data_hasher.update(str(contiguous_array.dtype).encode(”utf-8”)) training_data_hasher.update(contiguous_array.tobytes())TRAINING_DATA_HASH = training_data_hasher.hexdigest()
          4.这里设置训练集、测试集和交叉验证结果的三组颜色,并为前五个模型建立超参数搜索空间。ElasticNet主要搜索正则化强度和L1/L2混合比例,其余树模型重点调整树的数量、深度和学习率。TabPFN保持默认配置,不参加网格搜索。XGBoost和CatBoost会根据前面检测到的CUDA环境自动切换计算设备,随机森林和LightGBM则使用CPU。
          # ------------------------------------------------------------------# 第六部分:定义配色方案(严格按用户指定的三个颜色)# ------------------------------------------------------------------color_train = ”#1254a7”# 深蓝色,代表训练集 Traincolor_test = ”#82adcc”# 浅蓝色,代表测试集 Testcolor_cv = ”#ffffe4”# 浅黄色,代表交叉验证 CV Val# ------------------------------------------------------------------# 第七部分:定义各模型的超参数搜索网格(网格搜索得到最优超参数,并记录下来用于论文)# ------------------------------------------------------------------# 说明:TabPFN按论文要求保持默认配置,不做超参数搜索param_grids = { ”ElasticNet”: { ”alpha”: [0.001, 0.01, 0.1, 1.0, 10.0],# 正则化强度 ”l1_ratio”: [0.1, 0.3, 0.5, 0.7, 0.9]# L1/L2混合比例 }, ”RF”: { ”n_estimators”: [200, 400],# 树的数量 ”max_depth”: [None, 5, 10],# 树的最大深度 ”min_samples_leaf”: [1, 2, 4]# 叶节点最小样本数 }, ”XGBoost”: { ”n_estimators”: [200, 400], ”max_depth”: [3, 5, 7], ”learning_rate”: [0.05, 0.1] }, ”LightGBM”: { ”n_estimators”: [200, 400], ”max_depth”: [-1, 5, 7], ”learning_rate”: [0.05, 0.1] }, ”CatBoost”: { ”iterations”: [300, 500], ”depth”: [4, 6, 8], ”learning_rate”: [0.05, 0.1] }}# 各模型的基础实例(未调参前的默认对象,网格搜索时会克隆并调整参数)# 说明:RF(随机森林)原生不支持GPU;当前通过pip安装的LightGBM也是CPU构建,# 因此二者使用CPU。XGBoost和CatBoost在检测到CUDA时切换到GPU。base_estimators = { ”ElasticNet”: ElasticNet(random_state=42, max_iter=5000), ”RF”: RandomForestRegressor(random_state=42, n_jobs=-1), ”XGBoost”: XGBRegressor( random_state=42, n_jobs=-1, objective=”reg:squarederror”, verbosity=0,# XGBoost新版本用 device=”cuda” 启用GPU;老版本可能需要 tree_method=”gpu_hist” tree_method=”hist”, device=(”cuda” if USE_CUDA else ”cpu”) ), ”LightGBM”: LGBMRegressor( random_state=42, n_jobs=-1, verbose=-1,# 标准Windows pip wheel未启用GPU Tree Learner,强制使用CPU以避免全部拟合失败 device=”cpu” ), ”CatBoost”: CatBoostRegressor( random_state=42, verbose=0,# CatBoost官方原生支持GPU,task_type=”GPU”即可,无需额外编译 task_type=(”GPU” if USE_CUDA else ”CPU”) )}
            5.六个模型全部重新训练可能需要较长时间,尤其是TabPFN和参与网格搜索的集成模型。这里根据训练数据、特征名称、模型参数、软件版本和计算设备生成唯一缓存签名。下次运行时,如果数据和配置没有变化,程序会直接加载已经保存的模型和交叉验证结果;只要其中一项发生变化,原缓存就会自动失效并重新训练。
            # ------------------------------------------------------------------# 第七.五部分:模型缓存(数据和参数不变时直接加载,避免重复训练)# ------------------------------------------------------------------CACHE_SCHEMA_VERSION = 1PACKAGE_VERSIONS = { name: package_version(name) for name in [”scikit-learn”, ”xgboost”, ”lightgbm”, ”catboost”, ”tabpfn”, ”torch”]}def get_model_cache_signature(model_name): ”””根据训练数据、模型参数、软件版本和设备生成稳定的缓存签名。””” signature_payload = { ”cache_schema”: CACHE_SCHEMA_VERSION, ”model_name”: model_name, ”training_data_hash”: TRAINING_DATA_HASH, ”feature_cols”: feature_cols, ”target_col”: target_col, ”test_size”: 0.2, ”random_state”: 42, ”cv”: 5, ”param_grid”: param_grids.get(model_name, ”default”), ”estimator_params”: base_estimators.get(model_name, None).get_params(deep=False) if model_name in base_estimators else {”device”: DEVICE}, ”device”: DEVICE if model_name in {”XGBoost”, ”CatBoost”, ”TabPFN”} else ”cpu”, ”package_versions”: PACKAGE_VERSIONS, } serialized = json.dumps( signature_payload, sort_keys=True, ensure_ascii=False, default=str ).encode(”utf-8”) return hashlib.sha256(serialized).hexdigest()def get_model_cache_paths(model_name): ”””返回模型文件与元数据文件路径。””” safe_name = model_name.lower().replace(” ”, ”_”) return ( os.path.join(models_dir, f”{safe_name}.joblib”), os.path.join(models_dir, f”{safe_name}_metadata.json”), )def load_cached_model(model_name): ”””签名一致时加载模型与CV结果;缓存无效或损坏时返回None。””” model_path, metadata_path = get_model_cache_paths(model_name) if not (os.path.isfile(model_path) and os.path.isfile(metadata_path)): return None try: with open(metadata_path, ”r”, encoding=”utf-8”) as file: metadata = json.load(file) expected_signature = get_model_cache_signature(model_name) if ( metadata.get(”signature”) != expected_signature or ”cv_r2” not in metadata ): print(f” {model_name}缓存与当前数据/配置不一致,将重新训练。”) return None model = joblib.load(model_path) print(f” 已加载模型缓存:{model_path}”) return model, metadata except Exception as error: print(f” {model_name}缓存加载失败,将重新训练:{error}”) return Nonedef save_model_cache(model_name, model, best_params, cv_r2): ”””原子保存模型及其元数据,避免中断时留下不完整缓存。””” model_path, metadata_path = get_model_cache_paths(model_name) temporary_model_path = model_path + ”.tmp” temporary_metadata_path = metadata_path + ”.tmp” metadata = { ”model_name”: model_name, ”signature”: get_model_cache_signature(model_name), ”best_params”: best_params, ”cv_r2”: float(cv_r2), ”created_at”: datetime.now().isoformat(timespec=”seconds”), ”model_file”: os.path.basename(model_path), ”training_data_hash”: TRAINING_DATA_HASH, ”package_versions”: PACKAGE_VERSIONS, } try: joblib.dump(model, temporary_model_path, compress=0) with open(temporary_metadata_path, ”w”, encoding=”utf-8”) as file: json.dump(metadata, file, ensure_ascii=False, indent=2, default=str) os.replace(temporary_model_path, model_path) os.replace(temporary_metadata_path, metadata_path) print(f” 模型缓存已保存:{model_path}”) except Exception: for temporary_path in (temporary_model_path, temporary_metadata_path): if os.path.exists(temporary_path): os.remove(temporary_path) raise# 模型显示顺序(与原图保持一致的排布逻辑:简单模型 -> 集成模型 -> TabPFN)model_order = [”ElasticNet”, ”RF”, ”XGBoost”, ”LightGBM”, ”CatBoost”, ”TabPFN”]
              6.程序按照设定顺序依次处理六个模型。前五个模型通过GridSearchCV寻找最优参数,TabPFN使用默认设置。模型完成训练后,分别计算训练集和测试集R²,以及测试集RMSE和MAE;同时使用5折交叉验证获得CV R²。每完成一个模型就立即保存缓存,即使后面的步骤意外中断,已经完成的模型也不需要重新训练。
              # ------------------------------------------------------------------# 第八部分:训练所有模型,并收集评价指标、预测结果、最优超参数# ------------------------------------------------------------------results_summary = []# 用于存储每个模型的Train/Test/CV R²及RMSE、MAEbest_params_records = []# 用于存储每个模型网格搜索得到的最优超参数train_pred_dict = {}# 存储每个模型在训练集上的预测值,便于后续绘图和导出test_pred_dict = {}# 存储每个模型在测试集上的预测值,便于后续绘图和导出fitted_models = {}# 存储训练好的模型对象,供后续特征重要性等分析使用for model_name in model_order: print(f”正在处理模型:{model_name} ...”) cached_result = load_cached_model(model_name) loaded_from_cache = cached_result is not None if loaded_from_cache: model, cache_metadata = cached_result best_params = cache_metadata[”best_params”] cv_r2 = float(cache_metadata[”cv_r2”]) else: print(f” 未找到有效缓存,开始训练:{model_name}”) if model_name == ”TabPFN”:# TabPFN不做超参数搜索,直接使用默认配置进行拟合 model = TabPFNRegressor(device=DEVICE) model.fit(X_train, y_train) best_params = f”default (device={DEVICE})” else:# 其余模型使用网格搜索寻找最优超参数(5折交叉验证,评价指标为R²)# 单张GPU不能安全地并行训练多个XGBoost/CatBoost任务,否则容易显存不足。 grid_n_jobs = ( 1 if (USE_CUDA and model_name in {”XGBoost”, ”CatBoost”}) else 2 ) grid = GridSearchCV( estimator=base_estimators[model_name], param_grid=param_grids[model_name], scoring=”r2”, cv=kfold, n_jobs=grid_n_jobs, ) grid.fit(X_train, y_train) model = grid.best_estimator_ best_params = grid.best_params_# 用训练好的最终模型分别预测训练集和测试集 y_train_pred = model.predict(X_train) y_test_pred = model.predict(X_test)# 计算训练集R² train_r2 = r2_score(y_train, y_train_pred)# 计算测试集R² test_r2 = r2_score(y_test, y_test_pred)# 计算测试集RMSE(均方根误差) test_rmse = np.sqrt(mean_squared_error(y_test, y_test_pred))# 计算测试集MAE(平均绝对误差) test_mae = mean_absolute_error(y_test, y_test_pred)# 仅在首次训练时计算5折CV;缓存命中时直接复用已保存的CV结果 if not loaded_from_cache: if model_name == ”TabPFN”: cv_scores = [] for train_idx, val_idx in kfold.split(X_train): cv_model = TabPFNRegressor(device=DEVICE) cv_model.fit(X_train[train_idx], y_train[train_idx]) cv_pred = cv_model.predict(X_train[val_idx]) cv_scores.append(r2_score(y_train[val_idx], cv_pred)) cv_r2 = np.mean(cv_scores) else: cv_scores = cross_val_score( model, X_train, y_train, scoring=”r2”, cv=kfold ) cv_r2 = np.mean(cv_scores)# 每完成一个模型就立即保存,后续步骤即使中断也无需重训该模型 save_model_cache(model_name, model, best_params, cv_r2)# 将本模型的评价结果汇总记录 results_summary.append({ ”Model”: model_name, ”Train_R2”: round(train_r2, 4), ”Test_R2”: round(test_r2, 4), ”CV_Val_R2”: round(cv_r2, 4), ”Test_RMSE”: round(test_rmse, 4), ”Test_MAE”: round(test_mae, 4) })# 记录最优超参数(TabPFN记为default) best_params_records.append({ ”Model”: model_name, ”Best_Params”: str(best_params) })# 保存预测结果,供绘图和导出使用 train_pred_dict[model_name] = y_train_pred test_pred_dict[model_name] = y_test_pred fitted_models[model_name] = model# 将模型评价结果汇总为DataFrame,便于绘图和导出results_df = pd.DataFrame(results_summary).set_index(”Model”).loc[model_order].reset_index()best_params_df = pd.DataFrame(best_params_records)print(”\n模型性能汇总:”)print(results_df)
                7.整张组合图采用三行三列的网格布局,第一行横跨三列,用来集中展示六个模型的性能。每个模型对应三根柱子,分别表示训练集R²、测试集R²和交叉验证R²,柱顶直接标注数值。比较三类R²不仅能判断模型的总体表现,还能初步观察训练集精度是否明显高于测试集和交叉验证结果。
                # ------------------------------------------------------------------# 第九部分:绘制图形(上方为R²条形图,下方为2行3列的散点图)# ------------------------------------------------------------------fig = plt.figure(figsize=(13.5, 11.8), constrained_layout=True)gs = fig.add_gridspec(3, 3, height_ratios=[0.68, 1, 1])# 第一行压缩为性能概览,下方两行用于6个等比例散点图,避免原图顶部留白过大# ---------- 9.1 绘制顶部条形图(Train/Test/CV Val R²对比) ----------ax_bar = fig.add_subplot(gs[0, :])# 第一行合并全部3列,作为条形图的绘图区域n_models = len(model_order)# 模型数量bar_width = 0.25# 每个柱子的宽度x_pos = np.arange(n_models)# 每个模型在x轴上的基准位置# 依次绘制Train/Test/CV R²三组柱子;使用Unicode上标确保R²也是Times New Romanbar_groups = [ ax_bar.bar( x_pos - bar_width, results_df[”Train_R2”], width=bar_width, color=color_train, label=”Train R²”, edgecolor=”#333333”, linewidth=0.55, ), ax_bar.bar( x_pos, results_df[”Test_R2”], width=bar_width, color=color_test, label=”Test R²”, edgecolor=”#333333”, linewidth=0.55, ), ax_bar.bar( x_pos + bar_width, results_df[”CV_Val_R2”], width=bar_width, color=color_cv, label=”CV R²”, edgecolor=”#333333”, linewidth=0.55, ),]for bars in bar_groups: ax_bar.bar_label( bars, fmt=”%.3f”, padding=2.5, fontsize=9.5, fontweight=”bold” )ax_bar.set_xticks(x_pos)# 设置x轴刻度位置ax_bar.set_xticklabels(model_order)ax_bar.set_ylabel(”R² score”)ax_bar.set_ylim(0, 1.10)ax_bar.yaxis.set_major_locator(MultipleLocator(0.2))ax_bar.grid(axis=”y”, linestyle=”--”, linewidth=0.55, alpha=0.35)ax_bar.set_axisbelow(True)ax_bar.legend( loc=”upper left”, frameon=True, framealpha=0.95, edgecolor=”#CCCCCC”, ncol=1)ax_bar.text( -0.035, 1.04, ”(a)”, transform=ax_bar.transAxes, fontsize=13, fontweight=”bold”, va=”bottom”)
                  8.下方六个子图按照两行三列排列,每张图对应一个模型。深蓝色散点表示训练集,浅蓝色散点表示测试集,黑色虚线是理想状态下的1∶1参考线。测试集还添加了线性趋势线及95%置信区间,并在图中标注RMSE、MAE和测试集R²。散点越集中在1∶1线附近,说明模型预测值与真实值越接近。
                  # ---------- 9.2 绘制下方2行3列共6个模型的 Truth vs Predicted 散点图 ----------# 定义每个模型在网格中的位置(第2、3行,每行3列)subplot_positions = [(10), (11), (12), (20), (21), (22)]scatter_train_color = color_trainscatter_test_color = color_testpanel_letters = [”b”, ”c”, ”d”, ”e”, ”f”, ”g”]for model_name, pos, panel_letter in zip( model_order, subplot_positions, panel_letters): ax = fig.add_subplot(gs[pos[0], pos[1]])# 在指定网格位置创建子图 y_train_pred = train_pred_dict[model_name]# 取出该模型训练集预测值 y_test_pred = test_pred_dict[model_name]# 取出该模型测试集预测值 all_truth = np.concatenate([y_train, y_test]) all_pred = np.concatenate([y_train_pred, y_test_pred])# 恢复原图的散点大小与透明度 ax.scatter( y_train, y_train_pred, s=14, color=scatter_train_color, alpha=0.50, label=”Train”, edgecolors=”none”, rasterized=True ) ax.scatter( y_test, y_test_pred, s=18, color=scatter_test_color, alpha=0.85, label=”Test”, edgecolors=”none”, rasterized=True ) sns.regplot( x=y_test, y=y_test_pred, scatter=False, ci=95, color=scatter_test_color, line_kws={”linewidth”: 1.25}, ax=ax, )# 每个模型根据自身真实值和预测值设置坐标范围 min_val = float(min(all_truth.min(), all_pred.min())) max_val = float(max(all_truth.max(), all_pred.max())) axis_padding = max((max_val - min_val) * 0.020.005) axis_limits = (min_val - axis_padding, max_val + axis_padding)# 绘制1:1对角虚线,代表理想的”预测值=真实值” ax.plot( axis_limits, axis_limits, linestyle=”--”, color=”#222222”, linewidth=1.0, zorder=1 )# 各子图独立使用最合适的坐标范围,不强制统一纵横比 ax.set_xlim(axis_limits) ax.set_ylim(axis_limits) ax.xaxis.set_major_locator(MaxNLocator(5)) ax.yaxis.set_major_locator(MaxNLocator(5)) ax.set_xlabel(”Observed HQ”) ax.set_ylabel(”Predicted HQ”) ax.set_title( f”({panel_letter}) {model_name}”, color=”#174A7E”, fontweight=”bold”, pad=5, ) ax.grid(linestyle=”:”, linewidth=0.45, alpha=0.28) ax.set_axisbelow(True)# 取出该模型对应的评价指标,用于文本标注 row = results_df[results_df[”Model”] == model_name].iloc[0] annotation_text = (f'RMSE: {row[”Test_RMSE”]:.4f}\n' f'MAE: {row[”Test_MAE”]:.4f}\n' f'Test R²: {row[”Test_R2”]:.3f}') ax.legend( loc=”upper left”, bbox_to_anchor=(0.020.98), fontsize=9, frameon=True, framealpha=0.92, edgecolor=”#CCCCCC”, ) ax.text( 0.02, 0.79, annotation_text, transform=ax.transAxes, fontsize=9.5, va=”top”, ha=”left”, bbox=dict( boxstyle=”round,pad=0.3”, facecolor=”white”, alpha=0.90, edgecolor=”#B5B5B5”, linewidth=0.6, ), )
                    9.完成所有子图后,为组合图添加总标题,并同时导出PDF和JPG两种格式。PDF适合论文排版和后期编辑,JPG则以600 dpi保存,可以直接用于公众号展示或插入文档。保存完成后主动关闭画布,避免批量运行多个绘图任务时占用过多内存。
                    # 整体图标题fig.suptitle( ”Model Performance Comparison for HQ Prediction”, fontsize=17, fontweight=”bold”,)# 同时保存PDF矢量图和600 dpi JPG;所有文字统一使用Times New Romanfig.savefig(output_pdf_path, format=”pdf”, bbox_inches=”tight”, pad_inches=0.08)fig.savefig( output_jpg_path, format=”jpg”, dpi=600, bbox_inches=”tight”, pad_inches=0.08, pil_kwargs={”quality”: 95, ”optimize”: True},)print(f”PDF图形已保存至:{output_pdf_path}”)print(f”JPG图形已保存至:{output_jpg_path}”)plt.close(fig)# 关闭图形,释放内存
                      10.最后将建模过程中产生的重要结果写入同一个Excel文件,包括模型性能、最优超参数、训练集和测试集预测值、变量说明、数据划分信息以及模型缓存清单。对于具有内置特征重要性或回归系数的模型,代码还会同步导出特征重要性结果;TabPFN没有对应的内置属性,因此不会强行生成,后续可以另外使用SHAP或置换重要性进行解释。
                      # ------------------------------------------------------------------# 第十部分:导出所有过程数据到Excel(供论文写作、复核使用)# ------------------------------------------------------------------with pd.ExcelWriter(output_excel_path, engine=”openpyxl”) as writer:# 10.1 模型性能汇总表(Train/Test/CV R²、RMSE、MAE) results_df.to_excel(writer, sheet_name=”模型性能汇总”, index=False)# 10.2 各模型最优超参数(网格搜索得到,TabPFN为默认配置) best_params_df.to_excel(writer, sheet_name=”最优超参数”, index=False)# 10.3 训练集真实值与各模型预测值对照表 train_compare_df = pd.DataFrame({”Truth_HQ”: y_train}) for model_name in model_order: train_compare_df[f”{model_name}_Pred”] = train_pred_dict[model_name] train_compare_df.to_excel(writer, sheet_name=”训练集预测对照”, index=False)# 10.4 测试集真实值与各模型预测值对照表 test_compare_df = pd.DataFrame({”Truth_HQ”: y_test}) for model_name in model_order: test_compare_df[f”{model_name}_Pred”] = test_pred_dict[model_name] test_compare_df.to_excel(writer, sheet_name=”测试集预测对照”, index=False)# 10.5 建模所用特征与因变量列表,便于论文方法部分核对 feature_info_df = pd.DataFrame({ ”变量类型”: [”自变量”] * len(feature_cols) + [”因变量”], ”变量名”: feature_cols + [target_col] }) feature_info_df.to_excel(writer, sheet_name=”变量说明”, index=False)# 10.6 数据划分信息(训练集/测试集样本量、划分比例、随机种子、本次运行所用计算设备) split_info_df = pd.DataFrame({ ”项目”: [ ”总样本量”, ”训练集样本量”, ”测试集样本量”, ”测试集比例”, ”随机种子”, ”交叉验证折数”, ”GPU模型计算设备”, ”结果目录”, ”模型缓存目录”, ], ”值”: [ X.shape[0], X_train.shape[0], X_test.shape[0], 0.2, 425, DEVICE.upper(), output_dir, models_dir, ], }) split_info_df.to_excel(writer, sheet_name=”数据划分信息”, index=False)# 10.7 模型缓存清单(文件、大小、创建时间和签名) cache_records = [] for model_name in model_order: model_path, metadata_path = get_model_cache_paths(model_name) with open(metadata_path, ”r”, encoding=”utf-8”) as file: cache_metadata = json.load(file) cache_records.append({ ”Model”: model_name, ”Model_File”: model_path, ”Size_MB”: round(os.path.getsize(model_path) / (1024 ** 2), 2), ”Created_At”: cache_metadata.get(”created_at”, ””), ”Cache_Signature”: cache_metadata.get(”signature”, ””), }) pd.DataFrame(cache_records).to_excel( writer, sheet_name=”模型缓存清单”, index=False )# 10.8 若树模型/线性模型支持特征重要性(或回归系数),一并导出,便于论文中SHAP之外的补充说明 importance_records = [] for model_name in model_order: model = fitted_models[model_name] if hasattr(model, ”feature_importances_”):# 树模型(RF/XGBoost/LightGBM/CatBoost)自带特征重要性 importances = model.feature_importances_ elif hasattr(model, ”coef_”):# ElasticNet等线性模型使用回归系数的绝对值近似重要性 importances = np.abs(model.coef_) else:# TabPFN等无内置重要性属性的模型,此处跳过(如需可另行用SHAP或置换重要性计算) importances = None if importances is not None: for feat, imp in zip(feature_cols, importances): importance_records.append({”Model”: model_name, ”Feature”: feat, ”Importance”: imp}) if len(importance_records) > 0: importance_df = pd.DataFrame(importance_records) importance_df.to_excel(writer, sheet_name=”特征重要性(内置)”, index=False)print(f”过程数据已保存至:{output_excel_path}”)print(”全部流程运行完毕!”)
                      出图:
                      “今日分享至此✨”
                      完整代码与测试数据免费无套路在微信小程序“地学小助手”直接获取

                      最新文章

                      随机文章

                      基本 文件 流程 错误 SQL 调试
                      1. 请求信息 : 2026-08-22 01:39:26 HTTP/2.0 GET : https://f.mffb.com.cn/a/507129.html
                      2. 运行时间 : 1.286846s [ 吞吐率:0.78req/s ] 内存消耗:4,469.04kb 文件加载:140
                      3. 缓存信息 : 0 reads,0 writes
                      4. 会话信息 : SESSION_ID=728781d7fbcf146ef722fbd45e198df0
                      1. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/public/index.php ( 0.79 KB )
                      2. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/autoload.php ( 0.17 KB )
                      3. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/composer/autoload_real.php ( 2.49 KB )
                      4. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/composer/platform_check.php ( 0.90 KB )
                      5. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/composer/ClassLoader.php ( 14.03 KB )
                      6. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/composer/autoload_static.php ( 4.90 KB )
                      7. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/think-helper/src/helper.php ( 8.34 KB )
                      8. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/think-validate/src/helper.php ( 2.19 KB )
                      9. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/think-orm/src/helper.php ( 1.47 KB )
                      10. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/think-orm/stubs/load_stubs.php ( 0.16 KB )
                      11. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/framework/src/think/Exception.php ( 1.69 KB )
                      12. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/think-container/src/Facade.php ( 2.71 KB )
                      13. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/symfony/deprecation-contracts/function.php ( 0.99 KB )
                      14. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/symfony/polyfill-mbstring/bootstrap.php ( 8.26 KB )
                      15. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/symfony/polyfill-mbstring/bootstrap80.php ( 9.78 KB )
                      16. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/symfony/var-dumper/Resources/functions/dump.php ( 1.49 KB )
                      17. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/think-dumper/src/helper.php ( 0.18 KB )
                      18. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/symfony/var-dumper/VarDumper.php ( 4.30 KB )
                      19. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/framework/src/think/App.php ( 15.30 KB )
                      20. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/think-container/src/Container.php ( 15.76 KB )
                      21. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/psr/container/src/ContainerInterface.php ( 1.02 KB )
                      22. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/app/provider.php ( 0.19 KB )
                      23. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/framework/src/think/Http.php ( 6.04 KB )
                      24. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/think-helper/src/helper/Str.php ( 7.29 KB )
                      25. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/framework/src/think/Env.php ( 4.68 KB )
                      26. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/app/common.php ( 0.03 KB )
                      27. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/framework/src/helper.php ( 18.78 KB )
                      28. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/framework/src/think/Config.php ( 5.54 KB )
                      29. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/config/app.php ( 0.95 KB )
                      30. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/config/cache.php ( 0.78 KB )
                      31. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/config/console.php ( 0.23 KB )
                      32. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/config/cookie.php ( 0.56 KB )
                      33. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/config/database.php ( 2.48 KB )
                      34. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/framework/src/think/facade/Env.php ( 1.67 KB )
                      35. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/config/filesystem.php ( 0.61 KB )
                      36. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/config/lang.php ( 0.91 KB )
                      37. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/config/log.php ( 1.35 KB )
                      38. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/config/middleware.php ( 0.19 KB )
                      39. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/config/route.php ( 1.89 KB )
                      40. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/config/session.php ( 0.57 KB )
                      41. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/config/trace.php ( 0.34 KB )
                      42. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/config/view.php ( 0.82 KB )
                      43. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/app/event.php ( 0.25 KB )
                      44. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/framework/src/think/Event.php ( 7.67 KB )
                      45. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/app/service.php ( 0.13 KB )
                      46. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/app/AppService.php ( 0.26 KB )
                      47. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/framework/src/think/Service.php ( 1.64 KB )
                      48. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/framework/src/think/Lang.php ( 7.35 KB )
                      49. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/framework/src/lang/zh-cn.php ( 13.70 KB )
                      50. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/framework/src/think/initializer/Error.php ( 3.31 KB )
                      51. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/framework/src/think/initializer/RegisterService.php ( 1.33 KB )
                      52. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/services.php ( 0.14 KB )
                      53. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/framework/src/think/service/PaginatorService.php ( 1.52 KB )
                      54. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/framework/src/think/service/ValidateService.php ( 0.99 KB )
                      55. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/framework/src/think/service/ModelService.php ( 2.04 KB )
                      56. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/think-trace/src/Service.php ( 0.77 KB )
                      57. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/framework/src/think/Middleware.php ( 6.72 KB )
                      58. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/framework/src/think/initializer/BootService.php ( 0.77 KB )
                      59. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/think-orm/src/Paginator.php ( 11.86 KB )
                      60. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/think-validate/src/Validate.php ( 63.20 KB )
                      61. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/think-orm/src/Model.php ( 23.55 KB )
                      62. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/think-orm/src/model/concern/Attribute.php ( 21.05 KB )
                      63. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/think-orm/src/model/concern/AutoWriteData.php ( 4.21 KB )
                      64. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/think-orm/src/model/concern/Conversion.php ( 6.44 KB )
                      65. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/think-orm/src/model/concern/DbConnect.php ( 5.16 KB )
                      66. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/think-orm/src/model/concern/ModelEvent.php ( 2.33 KB )
                      67. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/think-orm/src/model/concern/RelationShip.php ( 28.29 KB )
                      68. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/think-helper/src/contract/Arrayable.php ( 0.09 KB )
                      69. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/think-helper/src/contract/Jsonable.php ( 0.13 KB )
                      70. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/think-orm/src/model/contract/Modelable.php ( 0.09 KB )
                      71. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/framework/src/think/Db.php ( 2.88 KB )
                      72. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/think-orm/src/DbManager.php ( 8.52 KB )
                      73. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/framework/src/think/Log.php ( 6.28 KB )
                      74. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/framework/src/think/Manager.php ( 3.92 KB )
                      75. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/psr/log/src/LoggerTrait.php ( 2.69 KB )
                      76. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/psr/log/src/LoggerInterface.php ( 2.71 KB )
                      77. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/framework/src/think/Cache.php ( 4.92 KB )
                      78. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/psr/simple-cache/src/CacheInterface.php ( 4.71 KB )
                      79. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/think-helper/src/helper/Arr.php ( 16.63 KB )
                      80. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/framework/src/think/cache/driver/File.php ( 7.84 KB )
                      81. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/framework/src/think/cache/Driver.php ( 9.03 KB )
                      82. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/framework/src/think/contract/CacheHandlerInterface.php ( 1.99 KB )
                      83. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/app/Request.php ( 0.09 KB )
                      84. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/framework/src/think/Request.php ( 55.78 KB )
                      85. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/app/middleware.php ( 0.25 KB )
                      86. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/framework/src/think/Pipeline.php ( 2.61 KB )
                      87. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/think-trace/src/TraceDebug.php ( 3.40 KB )
                      88. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/framework/src/think/middleware/SessionInit.php ( 1.94 KB )
                      89. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/framework/src/think/Session.php ( 1.80 KB )
                      90. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/framework/src/think/session/driver/File.php ( 6.27 KB )
                      91. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/framework/src/think/contract/SessionHandlerInterface.php ( 0.87 KB )
                      92. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/framework/src/think/session/Store.php ( 7.12 KB )
                      93. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/framework/src/think/Route.php ( 23.73 KB )
                      94. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/framework/src/think/route/RuleName.php ( 5.75 KB )
                      95. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/framework/src/think/route/Domain.php ( 2.53 KB )
                      96. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/framework/src/think/route/RuleGroup.php ( 22.43 KB )
                      97. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/framework/src/think/route/Rule.php ( 26.95 KB )
                      98. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/framework/src/think/route/RuleItem.php ( 9.78 KB )
                      99. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/route/app.php ( 1.72 KB )
                      100. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/framework/src/think/facade/Route.php ( 4.70 KB )
                      101. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/framework/src/think/route/dispatch/Controller.php ( 4.74 KB )
                      102. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/framework/src/think/route/Dispatch.php ( 10.44 KB )
                      103. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/app/controller/Index.php ( 4.81 KB )
                      104. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/app/BaseController.php ( 2.05 KB )
                      105. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/think-orm/src/facade/Db.php ( 0.93 KB )
                      106. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/think-orm/src/db/connector/Mysql.php ( 5.44 KB )
                      107. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/think-orm/src/db/PDOConnection.php ( 52.47 KB )
                      108. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/think-orm/src/db/Connection.php ( 8.39 KB )
                      109. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/think-orm/src/db/ConnectionInterface.php ( 4.57 KB )
                      110. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/think-orm/src/db/builder/Mysql.php ( 16.58 KB )
                      111. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/think-orm/src/db/Builder.php ( 24.06 KB )
                      112. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/think-orm/src/db/BaseBuilder.php ( 27.50 KB )
                      113. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/think-orm/src/db/Query.php ( 15.71 KB )
                      114. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/think-orm/src/db/BaseQuery.php ( 45.13 KB )
                      115. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/think-orm/src/db/concern/TimeFieldQuery.php ( 7.43 KB )
                      116. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/think-orm/src/db/concern/AggregateQuery.php ( 3.26 KB )
                      117. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/think-orm/src/db/concern/ModelRelationQuery.php ( 20.07 KB )
                      118. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/think-orm/src/db/concern/ParamsBind.php ( 3.66 KB )
                      119. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/think-orm/src/db/concern/ResultOperation.php ( 7.01 KB )
                      120. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/think-orm/src/db/concern/WhereQuery.php ( 19.37 KB )
                      121. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/think-orm/src/db/concern/JoinAndViewQuery.php ( 7.11 KB )
                      122. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/think-orm/src/db/concern/TableFieldInfo.php ( 2.63 KB )
                      123. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/think-orm/src/db/concern/Transaction.php ( 2.77 KB )
                      124. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/framework/src/think/log/driver/File.php ( 5.96 KB )
                      125. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/framework/src/think/contract/LogHandlerInterface.php ( 0.86 KB )
                      126. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/framework/src/think/log/Channel.php ( 3.89 KB )
                      127. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/framework/src/think/event/LogRecord.php ( 1.02 KB )
                      128. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/think-helper/src/Collection.php ( 16.47 KB )
                      129. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/framework/src/think/facade/View.php ( 1.70 KB )
                      130. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/framework/src/think/View.php ( 4.39 KB )
                      131. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/framework/src/think/Response.php ( 8.81 KB )
                      132. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/framework/src/think/response/View.php ( 3.29 KB )
                      133. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/framework/src/think/Cookie.php ( 6.06 KB )
                      134. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/think-view/src/Think.php ( 8.38 KB )
                      135. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/framework/src/think/contract/TemplateHandlerInterface.php ( 1.60 KB )
                      136. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/think-template/src/Template.php ( 46.61 KB )
                      137. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/think-template/src/template/driver/File.php ( 2.41 KB )
                      138. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/think-template/src/template/contract/DriverInterface.php ( 0.86 KB )
                      139. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/runtime/temp/067d451b9a0c665040f3f1bdd3293d68.php ( 11.98 KB )
                      140. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/think-trace/src/Html.php ( 4.42 KB )
                      1. CONNECT:[ UseTime:0.001159s ] mysql:host=127.0.0.1;port=3306;dbname=f_mffb;charset=utf8mb4
                      2. SHOW FULL COLUMNS FROM `fenlei` [ RunTime:0.001457s ]
                      3. SELECT * FROM `fenlei` WHERE `fid` = 0 [ RunTime:0.032985s ]
                      4. SELECT * FROM `fenlei` WHERE `fid` = 63 [ RunTime:0.046737s ]
                      5. SHOW FULL COLUMNS FROM `set` [ RunTime:0.000639s ]
                      6. SELECT * FROM `set` [ RunTime:0.007337s ]
                      7. SHOW FULL COLUMNS FROM `article` [ RunTime:0.000618s ]
                      8. SELECT * FROM `article` WHERE `id` = 507129 LIMIT 1 [ RunTime:0.009128s ]
                      9. UPDATE `article` SET `lasttime` = 1787333967 WHERE `id` = 507129 [ RunTime:0.057756s ]
                      10. SELECT * FROM `fenlei` WHERE `id` = 66 LIMIT 1 [ RunTime:0.011805s ]
                      11. SELECT * FROM `article` WHERE `id` < 507129 ORDER BY `id` DESC LIMIT 1 [ RunTime:0.001384s ]
                      12. SELECT * FROM `article` WHERE `id` > 507129 ORDER BY `id` ASC LIMIT 1 [ RunTime:0.011270s ]
                      13. SELECT * FROM `article` WHERE `id` < 507129 ORDER BY `id` DESC LIMIT 10 [ RunTime:0.297837s ]
                      14. SELECT * FROM `article` WHERE `id` < 507129 ORDER BY `id` DESC LIMIT 10,10 [ RunTime:0.542802s ]
                      15. SELECT * FROM `article` WHERE `id` < 507129 ORDER BY `id` DESC LIMIT 20,10 [ RunTime:0.093769s ]
                      1.290390s