GeezerVisonThe World Wide Web, restored to 800 pixels of glory. |
| Home|About|Gaming cabinet|Archives|How it works|Starter sites |
GeezerVison is showing xgboost.readthedocs.io — Python Package Introduction — xgboost 3.4.2 documentation Python Package IntroductionThis document gives a basic walkthrough of the xgboost package for Python. The Python package is consisted of 3 different interfaces, including native interface, scikit-learn interface and dask interface. For introduction to dask interface please see Distributed XGBoost with Dask. List of other Helpful Links Contents Install XGBoostTo install XGBoost, follow instructions in Installation Guide. To verify your installation, run the following in Python: import xgboost as xgb Data InterfaceThe XGBoost Python module is able to load data from many different types of data format including both CPU and GPU data structures. For a comprehensive list of supported data types, please reference the Supported Python data structures. For a detailed description of text input formats, please visit Text Input Format of DMatrix. The input data is stored in a
Setting ParametersXGBoost can use either a list of pairs or a dictionary to set parameters. For instance:
TrainingTraining a model requires a parameter list and data set. num_round = 10 bst = xgb.train(param, dtrain, num_round, evallist) After training, the model can be saved into bst.save_model('model.ubj') The model and its feature map can also be dumped to a text file. # dump model bst.dump_model('dump.raw.txt') # dump model with feature map bst.dump_model('dump.raw.txt', 'featmap.txt') A saved model can be loaded as follows: bst = xgb.Booster({'nthread': 4}) # init model bst.load_model('model.ubj') # load model data Methods including update and boost from Early StoppingIf you have a validation set, you can use early stopping to find the optimal number of boosting rounds.
Early stopping requires at least one set in train(..., evals=evals, early_stopping_rounds=10) The model will train until the validation score stops improving. Validation error needs to decrease at least every If early stopping occurs, the model will have two additional fields: This works with both metrics to minimize (RMSE, log loss, etc.) and to maximize (MAP, NDCG, AUC). Note that if you specify more than one evaluation metric the last one in PredictionA model that has been trained or loaded can perform predictions on data sets. # 7 entities, each contains 10 features data = np.random.rand(7, 10) dtest = xgb.DMatrix(data) ypred = bst.predict(dtest) If early stopping is enabled during training, you can get predictions from the best iteration with ypred = bst.predict(dtest, iteration_range=(0, bst.best_iteration + 1)) PlottingYou can use plotting module to plot importance and output tree. To plot importance, use xgb.plot_importance(bst) To plot the output tree via xgb.plot_tree(bst, num_trees=2) When you use xgb.to_graphviz(bst, num_trees=2) Scikit-Learn interfaceXGBoost provides an easy to use scikit-learn interface for some pre-defined models including regression, classification and ranking. See Using the Scikit-Learn Estimator Interface for more info. # Use "hist" for training the model. reg = xgb.XGBRegressor(tree_method="hist", device="cuda") # Fit the model using predictor X and response y. reg.fit(X, y) # Save model into JSON format. reg.save_model("regressor.json") User can still access the underlying booster model when needed: booster: xgb.Booster = reg.get_booster() |
| You are visitor 01402503 — GeezerVison does not store the pages you look up. Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required. |