#!/usr/bin/python3.6 """ An SSCCE for our NaN issue in XGBoost. This is with regard to Grokstream issue RM-454, the test_train transient error. This script fails every time, and completes quickly. The matter could easily be an input problem rather than an XGBoost bug. """ import sys import xgboost.sklearn import xgboost.core import numpy def main(): """Replicate.""" classifier = xgboost.sklearn.XGBClassifier() classifier.load_model('xgboost-sklearn-model-file') booster = classifier.get_booster() booster.dump_model(sys.stdout, dump_format='text') test_dmatrix = xgboost.core.DMatrix('test-dmatrix') class_probs = booster.predict(test_dmatrix, ntree_limit=0, validate_features=True) print(class_probs) if all(numpy.isfinite(class_probs)): print('Good, all values are finite.') else: raise SystemExit('Uh oh, one or more values are not finite.') main()