I want to build a classification algorithm that will predict multiple values for a set of features. For instance, lets say I have a customer demographic data like Income, age, sex, city and I want to predict 5 top products they will buy: like if a customer is male, has income less than 30k, lives in Tier1 city and has age 20-35 years--then the output is: 1. Mobile 2. Car 3. Furniture i.e., there are three outputs which means they would most probably buy Mobile, Car and Furniture with decreasing value of probability. Which algorithm will be best suited for this problem?

  • $\begingroup$ This is either multiclass, and you're interested in retrieving probabilities, or multilabel. What would your training data look like? $\endgroup$
    – Ben Reiniger
    Feb 28, 2020 at 13:10

1 Answer 1


Your problem can be considered as multiclass classification problem. So, you have a dataset of features X and the predictor y. Where X contain Income, age, sex,etc. and y is an item that one customer will buy with higher probability.

To achieve your goal and predict the probability of a customer you can use any classifier from scikit-learn Library (if you use python) and call the method predict_proba after you fit the classifier, as shown in the following example:

from sklearn.datasets import make_classification
from sklearn.ensemble import RandomForestClassifier

# Make a random multiclass classification problem
X, y = make_classification(n_samples=1000,

# Fit any classifier
rfc = RandomForestClassifier(n_jobs=-1,max_features= 'sqrt' ,n_estimators=50, oob_score = True) 

# Prediction for one example
one_example = X[10,:].reshape(1,-1)
outcome     = rfc.predict_proba(one_example)

The outcome of this problem with 5 classes is

array([[0.76, 0.12, 0.02, 0.06, 0.04]])

Which represent the probability of each class for this example (or customer in your case)


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.