XgBoost as nuisance model in DML learners (categorical features)
Nobody has claimed this yet.
- Dominant language
- Jupyter Notebook
- Stars
- 4.8k
- Forks
- 827
- PR merge metrics
- No merged PRs in 30d
Description
Hi there,
I'm looking to use xgboost as my nuisance model in my DoubleML setup and use xgboost's own mechanism for encoding categorical features (rather than having to one hot encode them myself).
I can do this quite easily in xgboost using the scikit-learn interface:
from econml.dml import NonParamDML
import numpy as np
import scipy
import pandas as pd
import xgboost as xgb
np.random.seed(123)
#numeric feats
X_num = pd.DataFrame(np.random.normal(size=(1000, 2)))
#categorical feat
X_cat = pd.Series(np.random.randint(0,3,1000))
X_cat=X_cat.replace({0:'zero',1:'one',2:'two'}).astype('category')
X=pd.concat([X_num,X_cat],axis=1)
X.columns=['num_feat_1','num_feat_2','cat_feat_1']
T = pd.Series(np.random.normal(size=(1000)))
y = pd.Series(np.random.randint(0,2,1000))
training_params={
'objective': 'binary:logistic',
'booster': 'gbtree',
'eval_metric': 'logloss',
'enable_categorical':True,
'max_cat_to_onehot':2,
'learning_rate':0.1,
'max_depth': 6
}
clf = xgb.XGBClassifier(**training_params)
clf.fit(X,y)
clf.predict_proba(X)
However, using the DML classes results in an error. The param that allows us to use xgboost's encoding of categorical features is enable_categorical=True but it appears econml is not able to pass this information onto xgboost.
Is there a way to get around this? I have some high cardinality categorical features that I would rather not have to one hot encode, hence why I have used xgboost as my nuisance model.
est = NonParamDML(
model_y=xgb.XGBClassifier(**training_params),
model_t=xgb.XGBRegressor(),
model_final=xgb.XGBRegressor(),
discrete_treatment=False,
discrete_outcome=True,
allow_missing=True,
)
est.fit(y, T, X=X, W=None)
Contributor guide
No contributing guide indexed for this repository
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start by reproducing the supplied example at NonParamDML.fit with pandas categorical features and the XGBoost scikit-learn interface. Trace how model_y, model_t, and model_final are handled during fitting, then verify that the requested enable_categorical behavior works without one-hot encoding; the payload names no files or tests to run.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- machine-learning, python, scikit-learn
- Domain
- machine-learning
- Issue type
- Feature
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Needs clarification
- Newbie friendliness
- 25/100