**E-COMMERCE PRODUCT PURCHASE MODEL USING GBM**

**Gradient Boosting Machine has been helping businesses to productivity and reduce business costs through the implementation of Business of technology. To Spot patterns, convenient investigation of the business is significant, to appropriate dissect and to comprehend is to fabricate what is well-suited for boosting the business or to construct what has demonstrated to be fruitful could be a distinct advantage for any business.**

**INTRODUCTION TO GBM**

Ezapp Solution built the holistic Gradient Boosting Machine System to increase productivity and reduce business costs on various Digital Channels and product Sales to various countries. The Gradient Boosting system is a demonstrated valuable system for both assistance suppliers and clients. The system has the ability to predict the correct kind of product for the specific client. Based on the client's profile, the system could recognize if a specific client would lean toward a specific product. Gradient Boosting helps change the business priorities of retailers.

Gradient boostingis a machine learning technique for regression and classification issues, which creates a prediction models, regularly decision trees.

**STRENGTHS OF THE GRADIENT BOOSTING MACHINE**

Since Gradient Boosting Machine are determined by improving a goal work, fundamentally GBM can utilized to tackle practically all target work that we can work out. This includinig things like positioning and poisson regression.

**WHY DO WE NEED A GRADIENT BOOSTING MACHINE ?**

Gradient boosting is a kind of machine learning boosting. It depends on the instinct that the most ideal next model, when joined with previous models, minimizes the general prediction error, If a small change in the prediction for a case causes no change in error, at that point next objective result of the case is zero.

Gradient boosting is a greedy algorithm and can over fit a preparation dataset rapidly. It can profit by regularization strategies that punish different pieces of the calculation and by and large improve the algorithm by reducing over fitting.

**HOW DOES GRADIENT BOOSTING WORK?**

**Gradient boosting will involve these three elements.**

**A loss function that has to be optimized**

**A weak learner who will make predictions**

**An additive model that helps to add weak learners to minimize the loss function**

**IDENTIFYING PROBLEM RESOURCES**

**Loss Function**

The loss function that is utilized will depend upon the sort of issue that is being settled. It should to be differentiable. Nonetheless, there are numerous standard loss functions that are supported and you are allowed to characterize your own. Like for instance gradient boosting regression could utilize a squares error and classification could utilize the logarithmic loss. The reason behind why the gradient boosting framework is utilized is that another calculation shouldn't be inferred for each loss work that might need to get utilized. All things considered, the framework is conventional enough that can be utilized by any differentiable loss work.

**WEAK LEARNER**

The Decision tree is utilized as a weak learner in the gradient boosting. The regression tree is utilized that yields the real value for the parts and the yields of these can be added together. This permits the resulting model yields to get added and also correct the residuals that are there in the prediction. The tree gets made in a covetous way by picking the split focuses that are the best which depends on the immaculateness score to minimize losses.

**ADDITIVE MODEL**

The trees get added individually and the current trees in the model don't change. The procedure of gradient descent minimizes the loss when the trees are added. The gradient descent is utilized to limit the rowers sets. This remembers the coefficient for the regression condition or the load in a neural network. After the error or loss gets determined the loads get refreshed to limit any error.

**Solution**

Once you have identified the problem. It is time to put the solution using python code.Now that we are familiar with the gradient boosting algorithm, let’s look at how we can fit GBM models in Python

**The scikit-learn Python machine learning library provides an implementation of Gradient Boosting Machine for machine learning.**

**IMPORT SOME REQUIRED LIBRARY**

**GETTING THE DATA**

Before we start implementing the model, we need to get the data. I have uploaded a sample data.You can download the data on your local if you want to try on your own machine.

**Given below are a few rows of our sample data, the dataset is from a Sale Product purchaseGiven below are a few rows of our sample data, the dataset is from a Sale Product purchase.**

We drop those rows that have Nan in the product purchase Dataset because that is our most important measure.

**TRAINING THE GRADIENT BOOSTING MACHINE MODEL**

Now, We are starting with read our dataset, and then explore the top 2 rows of the dataset by using head(). Run the describe, corr, .info() method on your DataFrame to get useful information about the data.Separate the target variable and rest of the variables using .iloc to subset the data. Now, you will create the train and test set for cross-validation of the results using the train_test_split function from sklearn's model_selection module with test_size size equal to 30% of the data. Also, to maintain reproducibility of the results.The next step is to instantiate an gradientboostingclassifier** **object by calling the gradientboostingclassifier() class from the gradientboostingclassifier library with the hyper-parameters passed as arguments. Fit the classifier to the training set and make predictions on the test set using the familiar .fit() and .predict() methods.

**EVALUATING THE MODEL**

Let us evaluate the model. Before evaluating the model it is always a good idea to visualize what we created. So I have plotted the priceis.sale against its prediction as shown in the figure below. This gives us the better understanding of how well the model is fitting into the data. And as seen clearly from the diagram below, it looks like we have a good fit. We are using the pyplot library to create the below plot. As you can see in below code I have first set the figsize. After that using the title function we need to set the title of the plot. Then we need to pass the feature and label to the scatter function. And finally use the plot function to pass the feature , its corresponding prediction and the color to be used.

**ADVANTAGES OF GRADIENT BOOSTING MACHINE **

1. Often provides predictive accuracy that cannot be performed by linear or logistic models.

2. Lots of flexibility can optimize on different loss functions and provides several hyper parameter tuning options that make the function fit very flexible.

3. No data pre-processing required- often works great with categorical and numerical values as is.

**Final Thoughts**

**In this blog we learned what is Gradient Boosting Machine, what are the advantages of using it. We also discussed various hyperparameter used in Gradient Boosting Machine. After that we loaded sample data and trained a model with the data. With the trained model we tried to visualize and quantify how good the model is fitting into the data which is more than 99%**