Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/357.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/scala/16.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
xgboost-python模型与c++;模型_Python_C++_Xgboost - Fatal编程技术网

xgboost-python模型与c++;模型

xgboost-python模型与c++;模型,python,c++,xgboost,Python,C++,Xgboost,考虑以下xgboost fit函数的python实现: import xgboost as xgb booster = xgb.XGBRegressor( base_score = 50, max_depth = 8, n_estimators=200, learning_rate=0.05, nthread=-1, subsample=1, colsample_bytree=1, min_child

考虑以下xgboost fit函数的python实现:

import xgboost as xgb
booster = xgb.XGBRegressor(
                base_score = 50, max_depth = 8, n_estimators=200,
                learning_rate=0.05, nthread=-1, subsample=1,
                colsample_bytree=1, min_child_weight = 1, scale_pos_weight = 1,
                seed=0, silent = False)
booster.fit(xValues, yValues, eval_metric="rmse")
我必须把它转换成C++(由于各种各样的原因)。我正在使用c_api创建矩阵和学习者函数以进行培训:

XGDMatrixCreateFromMat(&xValues[0], rowCount, colCount, 0, &dMatrix);
XGDMatrixSetFloatInfo(dMatrix, "label", &yValues[0], rowCount);

learner = xgboost::Learner::Create(dMatrix);
learner->Configure(learnerConfig); //same config params as above
learner->InitModel();

for(int i = 0; i < 200; ++i)
    learner->UpdateOneIter(i, xValues);

auto fo(dmlc::Stream::Create("save.model", "w"));
learner->Save(fo.get());
XGDMatrixCreateFromMat(&xValues[0],rowCount,colCount,0,&dMatrix);
XGDMatrixSetFloatInfo(dMatrix,“label”&Y值[0],行计数);
learner=xgboost::learner::Create(dMatrix);
学习者->配置(learnerConfig)//与上述配置参数相同
学习者->初始化模型();
对于(int i=0;i<200;++i)
学习者->更新者(i,xvalue);
自动fo(dmlc::Stream::Create(“save.model”、“w”);
学习者->保存(fo.get());

从技术上讲,这应该给出类似于Python和C++的模型。然而,当我对这两个模型使用完全相同的预测函数时,我从这两个模型得到的预测是非常不同的

我做错了什么

编辑:

我改写C++函数,使用CyAPI贯穿:

BoosterHandle h_booster;
XGBoosterCreate(dmats, 1, &h_booster);

for(auto cfg : m_learnerConfig)
  XGBoosterSetParam(h_booster, cfg.first.c_str(), cfg.second.c_str());

for(size_t iter = 0; iter < nNumTrees; ++iter)
  XGBoosterUpdateOneIter(h_booster, iter, matrices[0]);

XGBoosterSaveModel(h_booster, filename);
增压器手柄h_增压器;
XGBoosterCreate(dmats、1和h_增压器);
用于(自动cfg:m_learnerConfig)
XGBoosterSetParam(h_booster,cfg.first.c_str(),cfg.second.c_str());
对于(尺寸=0;iter
生成的模型中没有任何更改。C++模型往往比Python模型给出更高的预测值。然而,这并不一致

只是确认:比较一下,我使用C++中的相同预测代码/逻辑,使用两个保存的模型文件。 这里有一个不同的例子。


你找到问题了吗,我正面临同样的问题,但是C++给了更低的值,用相同的参数,也许在Python中,一些PARAMS默认值被刷新了!