From 0ddb1d7149f256c804d1fd4029aafc0ab544148d Mon Sep 17 00:00:00 2001 From: shenzhengntu <142518889+shenzhengntu@users.noreply.github.com> Date: Wed, 22 Jul 2026 17:25:20 +0800 Subject: [PATCH] classification xgboost train bug MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit \set ON_ERROR_STOP true \timing on -- 清理旧数据 DROP EXTENSION IF EXISTS pgml CASCADE; DROP SCHEMA IF EXISTS pgml CASCADE; CREATE EXTENSION pgml; -- 加载数据集 SELECT pgml.load_dataset('breast_cancer'); -- 加载数据集 SELECT pgml.load_dataset('breast_cancer'); -- ============================================= -- 分类算法 Python vs Rust 对比测试 -- 指标: f1, 差异阈值: < 0.05 (random_forest < 0.1) -- ============================================= -- === linear 分类 === SELECT * FROM pgml.train('Rust Classification Compare', 'classification', 'pgml.breast_cancer', 'malignant', algorithm => 'linear', runtime => 'python'); SELECT * FROM pgml.train('Rust Classification Compare', algorithm => 'linear', runtime => 'rust'); -- === xgboost 分类 === SELECT * FROM pgml.train('Rust Classification Compare', algorithm => 'xgboost', runtime => 'python', hyperparams => '{"n_estimators": 10}'); SELECT * FROM pgml.train('Rust Classification Compare', algorithm => 'xgboost', runtime => 'rust', hyperparams => '{"n_estimators": 10}'); -- xgboost rust "roc_auc" always 0.5----- INFO: Metrics: {"roc_auc": 0.5, "log_loss": 10.55341, "f1": 0.50526315, "precision": 0.33802816, "recall": 1.0, "accuracy": 0.33802816, "mcc": NaN, "fit_time": 0.006182069, "score_time": 0.000807744} INFO: Comparing to deployed model f1: Some(0.9292929172515868) WARNING: New model's f1 is not better than current model. New: 0.5052631497383118, Current 0.9292929172515868 WARNING: Not deploying newly trained model. project | task | algorithm | deployed -----------------------------+----------------+-----------+---------- Rust Classification Compare | classification | xgboost | f the reason is not update bst train --- src/booster.rs | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/booster.rs b/src/booster.rs index a965b6d..19504d3 100644 --- a/src/booster.rs +++ b/src/booster.rs @@ -148,8 +148,9 @@ impl Booster { dmats }; - let bst = Booster::new_with_cached_dmats(¶ms.booster_params, &cached_dmats)?; + let mut bst = Booster::new_with_cached_dmats(¶ms.booster_params, &cached_dmats)?; for i in 0..params.boost_rounds as i32 { + bst.update(params.dtrain, i)?; if let Some(eval_sets) = params.evaluation_sets { let mut dmat_eval_results = bst.eval_set(eval_sets, i)?;