XGBoost in R Programming
XGBoost is a fast and efficient algorithm and used by winners of many machine learning competitions. XG Boost works only with the numeric variables. It is a part of the boosting technique in which the selection of the sample is done more intelligently to classify observations. There are interfaces of XGBoost in C++, R, Python, Julia, Java, and Scala. The core functions in XGBoost are implemented in C++, thus it is easy to share models among different interfaces. Based on the statistics from the CRAN mirror, the package has been downloaded for more than 81, 000 times. XgBoost modeling consists of two techniques: Bagging and Boosting.
- Bagging: It is an approach where you can take random samples of data, build learning algorithms and take simple means to find bagging probabilities.
- Boosting: It is an approach where selection of approach is made more intelligently i.e more an more weight is given to classify observations.
Parameters in XGBoost
- eta: It shrinks the feature weights to make the boosting process more conservative. The range is from 0 to 1. It is also knowm as learning rate or Shrinking factor. Low eta value signifies the model is more robust to overfitting.
- gamma: The larger the value of gamma, more conservative the algorithm will be. It’s range is from 0 to infinity.
- max_depth: The maximum depth of a tree can be specified using
- Subsample: It is the proportion of rows that the model will randomly select to grow trees.
- colsample_bytree: It is the ratio of variables randomly chosen to build each tree in the model.
Big Mart dataset consists of 1559 products across 10 stores in different cities. Certain attributes of each product and store have been defined. It consists of 12 features i.e Item_Identifier( is a unique product ID assigned to every distinct item), Item_Weight(includes the weight of the product), Item_Fat_Content(describes whether the product is low fat or not), Item_Visibility(mentions the percentage of the total display area of all products in a store allocated to the particular product), Item_Type(describes the food category to which the item belongs), Item_MRP(Maximum Retail Price (list price) of the product), Outlet_Identifier(unique store ID assigned. It consists of an alphanumeric string of length 6), Outlet_Establishment_Year(mentions the year in which store was established), Outlet_Size(tells the size of the store in terms of ground area covered), Outlet_Location_Type(tells about the size of the city in which the store is located), Outlet_Type(tells whether the outlet is just a grocery store or some sort of supermarket) and Item_Outlet_Sales( sales of the product in the particular store).
Performing XGBoost on Dataset
Using XGBoost algorithm on the dataset which includes 12 features with 1559 products across 10 stores in different cities.
- Training of Xgboost model:
The xgboost model is trained calculating the train-rmse score and test-rmse score and finding its lowest value in many rounds.
- Model xgb_model:
The XgBoost models consist of 21 features with the objective of regression linear, eta is 0.01, gamma is 1, max_depth is 6, subsample is 0.8, colsample_bytree = 0.5 and silent is 1.
- Variable Importance plot:
The Item_MRP is the most important variable followed by Item_Visibility and Outlet_Location_Type_num.
So, Xgboost finds its applications in many sectors of industries and used with full capacity.