DRO on Tree-Ensemble ModelsΒΆ

[2]:
import xgboost as xgb
import numpy as np
from sklearn.model_selection import train_test_split
from sklearn.datasets import make_classification
from dro.src.tree_model.xgb import KLDRO_XGB, CVaRDRO_XGB
from dro.src.tree_model.lgbm import KLDRO_LGBM, CVaRDRO_LGBM
[3]:
X, y = make_classification(
        n_samples=1000,
        n_features=5,
        n_informative=3,
        n_redundant=1,
        n_classes=2,
        random_state=42
    )

X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=.2)
# create model instance
model = KLDRO_XGB(eps=0.001)
config = {"max_depth":2, "learning_rate":1, "num_boost_round":4}
model.update(config)
model.fit(X_train, y_train)
predict = model.predict(X_test)
print((predict==y_test).mean())
0.945
[4]:
X, y = make_classification(
        n_samples=1000,
        n_features=5,
        n_informative=3,
        n_redundant=1,
        n_classes=2,
        random_state=42
    )

X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=.2)
# create model instance
model = CVaRDRO_XGB(eps=0.1)
config = {"max_depth":2, "learning_rate":1, "num_boost_round":4}
model.update(config)
model.fit(X_train, y_train)
predict = model.predict(X_test)
print((predict==y_test).mean())
0.935
[5]:
X, y = make_classification(
        n_samples=1000,
        n_features=5,
        n_informative=3,
        n_redundant=1,
        n_classes=2,
        random_state=42
    )

X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=.2)
# create model instance
model = CVaRDRO_LGBM(eps=0.1)
config = {"max_depth":2, "learning_rate":1, "num_boost_round":4}
model.update(config)
model.fit(X_train, y_train)
predict = model.predict(X_test)
print((predict==y_test).mean())
[LightGBM] [Info] Using self-defined objective function
0.95
[6]:
X, y = make_classification(
        n_samples=1000,
        n_features=5,
        n_informative=3,
        n_redundant=1,
        n_classes=2,
        random_state=42
    )

X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=.2)
# create model instance
model = KLDRO_LGBM(eps=0.1)
config = {"max_depth":2, "learning_rate":1, "num_boost_round":4}
model.update(config)
model.fit(X_train, y_train)
predict = model.predict(X_test)
print((predict==y_test).mean())
[LightGBM] [Info] Using self-defined objective function
0.94