# How can machine learning algorithms solve this particular problem?

Let's think of a case of an e-commerce website which lists products for sale. Now a person can come on a particular product page and decide to add it to the shopping cart or not. If we look at it as a classification problem then, specifications of the product can be its features(e.g. for a cell phone, camera resolution, screen size, price, warranty period) and for a particular product page view by a customer either he clicked on add to cart button or not can be the success criteria(classification label).

An observation is that for the same set of features, X for a product page view, very few customers click on add to cart button (y = 1). That means for the same X, there will be many Y=0 and very few Y=1.

My peer says that machine learning algorithms like XGBoost will be able to classify this. While I am not convinced of the fact that how will the algorithm be able to predict that for an X, Y will be 1 when in reality itself it has a very slight chance of being 1 as many customers will not add it to cart.

I know it will give me a probability score of y being 1 but that will be too low to make use of.

• I didn't understand the end goal of this. What exactly are expecting at the end of classification? probability of a product going into a cart? – Kiritee Gak Jul 3 '18 at 9:10
• Yes, exactly. What will be the probability that a product will be added to cart, given a set of features? – rohit Jul 3 '18 at 9:14

## 2 Answers

I know it will give me a probability score of y being 1 but that will be too low to make use of.

Given the description you have of input data, which as you explain it is just the specs of a product (and implicitly that you are classifying for a user who has reached the product page somehow), then that's the best you can do. You simply don't have the data about the motivations and history of the user that would enable you to refine further than the mean probability of purchase given the product stats.

If you can access data about the visitor, features such as what other pages they have visited, previous purchases, whether they have clicked through from a particular advert or search result etc, then you may be able to refine the value further. However, even with that kind of backing data, you would still be quite far from predicting a clear "will buy" vs "won't buy" - instead you may be able to refine a generic p=0.01 to a personalised range p=0.0001 to p=0.05 depending on the user details.

These kind of shifts in probabilities can still be used successfully in advertising and sales pipelines. The difference between a 0.01 and 0.05 probability when deciding what to advertise for example is a factor of 5 efficiency improvement on use of advertising sections of a web site. The trick is finding the right way to make use of the information.

In general, you won't be able to make a reliable prediction that a user will buy a product like a mobile phone on a website. Too many hidden variables. So don't try to design systems that rely on a direct yes/no prediction.

• Thanks for the answer. Even I think that modelling it this way is not useful as there are many signals that are not captured e.g. even the day of the week is a signal for sale as weekends have more sales compared to weekdays. And many more signal like these. – rohit Jul 3 '18 at 12:36

It looks an interesting project. If I am not wrong, you would like to predict whether a particular user add a specific product into his/her cart (target = 1) or not (target = 0). It's an awesome idea to use Data Science concepts for this project.

From my point of view, first of all, you should skim through your data to manually analyse it and try to gather as much hidden data as you can. The more analysis you will do (on e-commerce), the more data you will get. Well, I am not an expert in e-commerce world, but lets say for example the type of day (festival or working day) or the particular user history might be useful for this system.

After doing this, you should try to fill up missing data (if you have some data missing) instead of just ignoring those data. Then, you should plot some graph of your data to find how all features are correlated with each other. This might help you to analyse what are the important features. For example, by seeing at the graph, it might be possible that you could see that the sale of the particular product is increasing with the popularity of that product. matplotlib and seaborn are the best libraries to do this.

The next and the most important step is to apply the Machine Learning model for the prediction of the target data (yes / no).

It is obvious that you will have majority of data with No (y = 0). So, you have imbalanced dataset in your training data. As suggested by your peers, XGBoost will be the best to classify imbalanced data. Now, you should do a minor modification on your data before fitting the model. You can adjust the weights of the target data by putting more weight on (y = 1) class.

  weights = np.zeros(len(y_train))
weights[y_train == 0] = 5
weights[y_train == 1] = 10


I think that you can also try cross-validation (5-fold) only on your training data. It's also good use F1-Macro score to find accuracy and to evaluate the model.

You should definitely try this thing. It might be possible that you can get more benefits than your expectation at last. You can also use this data to make the product recommendation system on your e-commerce site later on.