|
1 | 1 | import xgboost |
2 | 2 | import numpy as np |
| 3 | +import os |
3 | 4 | from tests import utils |
4 | 5 | from m2cgen import assemblers, ast |
5 | 6 |
|
@@ -228,3 +229,42 @@ def test_multi_class_best_ntree_limit(): |
228 | 229 | ]) |
229 | 230 |
|
230 | 231 | assert utils.cmp_exprs(actual, expected) |
| 232 | + |
| 233 | + |
| 234 | +def test_regression_saved_without_feature_names(): |
| 235 | + base_score = 0.6 |
| 236 | + estimator = xgboost.XGBRegressor(n_estimators=2, random_state=1, |
| 237 | + max_depth=1, base_score=base_score) |
| 238 | + utils.train_model_regression(estimator) |
| 239 | + |
| 240 | + with utils.tmp_dir() as tmp_dirpath: |
| 241 | + filename = os.path.join(tmp_dirpath, "tmp.file") |
| 242 | + estimator.save_model(filename) |
| 243 | + estimator = xgboost.XGBRegressor(base_score=base_score) |
| 244 | + estimator.load_model(filename) |
| 245 | + |
| 246 | + assembler = assemblers.XGBoostModelAssembler(estimator) |
| 247 | + actual = assembler.assemble() |
| 248 | + |
| 249 | + expected = ast.SubroutineExpr( |
| 250 | + ast.BinNumExpr( |
| 251 | + ast.BinNumExpr( |
| 252 | + ast.NumVal(base_score), |
| 253 | + ast.IfExpr( |
| 254 | + ast.CompExpr( |
| 255 | + ast.FeatureRef(12), |
| 256 | + ast.NumVal(9.72500038), |
| 257 | + ast.CompOpType.GTE), |
| 258 | + ast.NumVal(1.67318344), |
| 259 | + ast.NumVal(2.92757893)), |
| 260 | + ast.BinNumOpType.ADD), |
| 261 | + ast.IfExpr( |
| 262 | + ast.CompExpr( |
| 263 | + ast.FeatureRef(5), |
| 264 | + ast.NumVal(6.94099998), |
| 265 | + ast.CompOpType.GTE), |
| 266 | + ast.NumVal(3.3400948), |
| 267 | + ast.NumVal(1.72118247)), |
| 268 | + ast.BinNumOpType.ADD)) |
| 269 | + |
| 270 | + assert utils.cmp_exprs(actual, expected) |
0 commit comments