.Net wrapper for XGBoost based on the Python API. The main goal of the project is to provide a similar experience to the Python API, but in C#.
Currently supports XGBoostClassifier
and XGBoostRegressor
.
// Create and fit a classifier.
using var classifier = new XGBClassifier(maxDepth: 3, learningRate: 0.1f, nEstimators: 100);
classifier.Fit(dataTrain, labelsTrain);
// make predictions.
var predictions = classifier.Predict(dataTest);
var probabilities = classifier.PredictProbability(dataTest);
// Save and load the classifier.
var modelFileName = "classifier.json";
classifier.SaveModelToFile(modelFileName)
var loadedClassifier = XGBClassifier.LoadFromFile(modelFileName);
// Create and fit a regressor.
using var regressor = new XGBRegressor(maxDepth: 3, learningRate: 0.1f, nEstimators: 100);
regressor.Fit(dataTrain, labelsTrain);
// make predictions.
var predictions = regressor.Predict(dataTest);
// Save and load the regressor.
var modelFileName = "regressor.json";
regressor.SaveModelToFile(modelFileName)
var loadedRegressor = XGBRegressor.LoadFromFile(modelFileName);
- Get the latest version of the managed packages from nuget.org.
- https://www.nuget.org/packages/XGBoostSharp. Note that this requires a reference to one of the native packages (see below).
- https://www.nuget.org/packages/XGBoostSharp-cpu: This comes with native packages for cpu for win-x64, linux-x64, and osx-x64.
- If using the XGBoostSharp package the native packages can be installed separately from nuget.org.