def _get_nb_classes(self, nb_classes: int | None) -> int | None:
        """
        Return the number of output classes.

        :return: Number of classes in the data.
        """
        from xgboost import Booster, XGBClassifier

        try:
            if isinstance(self._model, Booster):
                return int(len(self._model.get_dump(dump_format="json")) / self._model.n_estimators)  # type: ignore
            if isinstance(self._model, XGBClassifier):
                return self._model.n_classes_
        except AttributeError:
            # Attribute n_classes_ not found, will return default nb_classes value
            pass

        if nb_classes is not None:
            return nb_classes
        return None

        Return the number of output classes.

        :return: Number of classes in the data.
        
art/estimators/classification/xgboost.py