How to visualise XGBoost tree in Python?
MACHINE LEARNING RECIPES

How to visualise XGBoost tree in Python?

How to visualise XGBoost tree in Python?

This recipe helps you visualise XGBoost tree in Python

0
In [ ]:
## How to visualise XGBoost tree in Python
## DataSet: skleran.datasets.load_breast_cancer()
def Snippet_186():
    print()
    print(format('Hoe to visualise XGBoost tree in Python','*^82'))
    import warnings
    warnings.filterwarnings("ignore")

    # load libraries
    from sklearn import datasets
    from sklearn import metrics
    from xgboost import XGBClassifier, plot_tree
    from sklearn.model_selection import train_test_split
    import matplotlib.pyplot as plt

    plt.style.use('ggplot')

    # load the iris datasets
    dataset = datasets.load_wine()
    X = dataset.data; y = dataset.target
    X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.25)

    # fit a ensemble.AdaBoostClassifier() model to the data
    model = XGBClassifier()
    model.fit(X_train, y_train)
    print(); print(model)
    # make predictions
    expected_y  = y_test
    predicted_y = model.predict(X_test)
    # summarize the fit of the model
    print(); print('XGBClassifier: ')
    print(); print(metrics.classification_report(expected_y, predicted_y,
                   target_names=dataset.target_names))
    print(); print(metrics.confusion_matrix(expected_y, predicted_y))

    plot_tree(model); plt.show()
    plot_tree(model, num_trees=4); plt.show()
    plot_tree(model, num_trees=0, rankdir='LR'); plt.show()
Snippet_186()

Relevant Projects

Machine Learning or Predictive Models in IoT - Energy Prediction Use Case
In this machine learning and IoT project, we are going to test out the experimental data using various predictive models and train the models and break the energy usage.

Human Activity Recognition Using Smartphones Data Set
In this deep learning project, you will build a classification system where to precisely identify human fitness activities.

Predict Employee Computer Access Needs in Python
Data Science Project in Python- Given his or her job role, predict employee access needs using amazon employee database.

Choosing the right Time Series Forecasting Methods
There are different time series forecasting methods to forecast stock price, demand etc. In this machine learning project, you will learn to determine which forecasting method to be used when and how to apply with time series forecasting example.

Data Science Project-TalkingData AdTracking Fraud Detection
Machine Learning Project in R-Detect fraudulent click traffic for mobile app ads using R data science programming language.

PySpark Tutorial - Learn to use Apache Spark with Python
PySpark Project-Get a handle on using Python with Spark through this hands-on data processing spark python tutorial.

Data Science Project-All State Insurance Claims Severity Prediction
Data science project in R to develop automated methods for predicting the cost and severity of insurance claims.

Loan Eligibility Prediction using Gradient Boosting Classifier
This data science in python project predicts if a loan should be given to an applicant or not. We predict if the customer is eligible for loan based on several factors like credit score and past history.

Predict Churn for a Telecom company using Logistic Regression
Machine Learning Project in R- Predict the customer churn of telecom sector and find out the key drivers that lead to churn. Learn how the logistic regression model using R can be used to identify the customer churn in telecom dataset.

Walmart Sales Forecasting Data Science Project
Data Science Project in R-Predict the sales for each department using historical markdown data from the Walmart dataset containing data of 45 Walmart stores.