When I follow the instructions in the Python API documentation on how to save the XGBoost model and features, I get the following error:
raise XGBoostError(py_str(_LIB.XGBGetLastError()))
xgboost.core.XGBoostError: [08:28:42] /Users/runner/miniforge3/conda-bld/xgboost-split_1712072580858/work/dmlc-core/src/io/local_filesys.cc:209: Check failed: allow_null: LocalFileSystem::Open “featmap.txt”: No such file or directory
Hereby a small example of what I am doing and how to obtain the error:
import pandas as pd
import numpy as np
from sklearn.model_selection import KFold
import xgboost
X = pd.DataFrame(data=np.random.randint(1, 5, size=[100, 15]))
y = X.pop(4)
cross_val_folds = KFold(n_splits=5, shuffle=True, random_state=42)
train, test = cross_val_folds.split(X=X).__next__()
# set xgboost pars
param = {"max_depth": 2, "eta": 1, "objective": "multi:softprob"}
param["nthread"] = 4
param["eval_metric"] = "auc"
param["num_class"] = 4
num_round = 10
X_train, X_test = X.iloc[train], X.iloc[test]
y_train, y_test = y.iloc[train], y.iloc[test]
# xgboost needs labels [0,...,nclass)
y_train = y_train - 1
y_test = y_test - 1
# do XGBoost
# load data in DMatrix format
dtrain = xgboost.DMatrix(X_train, label=y_train)
dtest = xgboost.DMatrix(X_test, label=y_test)
# train xgboost
# evallist = [(dtrain, "train"), (dtest, "eval")]
bst = xgboost.train(param, dtrain, num_round)
# dump model
bst.dump_model("dump.raw.txt")
# dump model with feature map
bst.dump_model("dump.raw.txt", "featmap.txt")
Has anyone else come across this problem? How can I save the model and features/featuremap such that after running I can interpret what the XGBoost model learned?
Thank you in advance for any help and suggestions!