Skip to content

mdabros/XGBoostSharp

Repository files navigation

Build Status License

XGBoostSharp

.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.

XGBoostClassifier

// 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);

XGBoostRegressor

// 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);

Installation

  1. Get the latest version of the managed packages from nuget.org.
  2. If using the XGBoostSharp package the native packages can be installed separately from nuget.org.