XGBoost
Deploy a model built with the XGBoost framework.
XGBoost is a gradient boosting framework. Baseten supports deploying XGBoost models out of the box.
Baseten officially supports
xgboost
version 1.6.1 or higher. Especially if you're using an online notebook environment like Google Colab or a bundle of packages like Anaconda, ensure that the version you are using is supported. If it's not, use the --upgrade
flag and pip will install the most recent version.Deploying a XGBoost model is as simple as:
import baseten
baseten_model = baseten.deploy(
xgboost_model,
model_name='My XGBoost model',
)
If you have already saved your model, just load it back into memory, test it to ensure it works, and deploy as in the above.
This code sample deploys a XGBoost model.
import baseten
import xgboost as xgb
from sklearn.datasets import make_classification
from sklearn.model_selection import train_test_split
def create_data():
X, y = make_classification(n_samples=100,
n_informative=2,
n_classes=2,
n_features=6)
X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.25)
train = xgb.DMatrix(X_train, y_train)
test = xgb.DMatrix(X_test, y_test)
return train, test
train, test = create_data()
params = {
"learning_rate": 0.01,
"max_depth": 3
}
# training, we set the early stopping rounds parameter
model = xgb.train(params,
train, evals=[(train, "train"), (test, "validation")],
num_boost_round=100, early_stopping_rounds=20)
baseten.login("*** INSERT API KEY ***") # https://docs.baseten.co/settings/api-keys
baseten_model = baseten.deploy(
model,
model_name='lgb model',
)
Last modified 5mo ago