How it works...

This recipe shows how easy it is to use different classifiers, as long as we want to use the default settings. In the first step, we imported the classifiers from their respective libraries.

In Steps 2 to 5, we created a special pipeline for each classifier. We combined the already established ColumnTransformer preprocessor with the corresponding classifier. Then, we fitted each pipeline to the training data and showed the performance evaluation report.

Classifiers such as XGBoost and LightGBM offer their own approaches to training models. First, you need to convert the pandas DataFrame to an acceptable data format (xgb.DMatrix, in the case of XGBoost, and lightgbm.Dataset for LightGBM), then use the train and cv functions to actually train the models. However, as scikit-learn is the leading library for training machine learning models in Python, both libraries provide scikit-learn-compatible APIs, which we used in this recipe. Using the native approaches can yield extra benefits, in terms of using features such as automatic handling of categorical variables by LightGBM, or using early stopping (stopping the training of the model when the validation score ceases to improve meaningfully), for both XGBoost and LightGBM.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
18.116.37.62