.. DO NOT EDIT. .. THIS FILE WAS AUTOMATICALLY GENERATED BY SPHINX-GALLERY. .. TO MAKE CHANGES, EDIT THE SOURCE PYTHON FILE: .. "python/examples/boost_from_prediction.py" .. LINE NUMBERS ARE GIVEN BELOW. .. only:: html .. note:: :class: sphx-glr-download-link-note :ref:`Go to the end ` to download the full example code. .. rst-class:: sphx-glr-example-title .. _sphx_glr_python_examples_boost_from_prediction.py: Demo for boosting from prediction ================================= .. GENERATED FROM PYTHON SOURCE LINES 5-36 .. code-block:: Python import os import xgboost as xgb CURRENT_DIR = os.path.dirname(__file__) dtrain = xgb.DMatrix( os.path.join(CURRENT_DIR, "../data/agaricus.txt.train?format=libsvm") ) dtest = xgb.DMatrix( os.path.join(CURRENT_DIR, "../data/agaricus.txt.test?format=libsvm") ) watchlist = [(dtest, "eval"), (dtrain, "train")] ### # advanced: start from a initial base prediction # print("start running example to start from a initial prediction") # specify parameters via map, definition are same as c++ version param = {"max_depth": 2, "eta": 1, "objective": "binary:logistic"} # train xgboost for 1 round bst = xgb.train(param, dtrain, 1, watchlist) # Note: we need the margin value instead of transformed prediction in # set_base_margin # do predict with output_margin=True, will always give you margin values # before logistic transformation ptrain = bst.predict(dtrain, output_margin=True) ptest = bst.predict(dtest, output_margin=True) dtrain.set_base_margin(ptrain) dtest.set_base_margin(ptest) print("this is result of running from initial prediction") bst = xgb.train(param, dtrain, 1, watchlist) .. _sphx_glr_download_python_examples_boost_from_prediction.py: .. only:: html .. container:: sphx-glr-footer sphx-glr-footer-example .. container:: sphx-glr-download sphx-glr-download-jupyter :download:`Download Jupyter notebook: boost_from_prediction.ipynb ` .. container:: sphx-glr-download sphx-glr-download-python :download:`Download Python source code: boost_from_prediction.py ` .. container:: sphx-glr-download sphx-glr-download-zip :download:`Download zipped: boost_from_prediction.zip ` .. only:: html .. rst-class:: sphx-glr-signature `Gallery generated by Sphinx-Gallery `_