0
$\begingroup$

Given that I have data containing images of oranges, apples and pineapples and I want to classify depending on a set of features.

Expected that I have completed the model and ready for prediction.

My questions are:

How can I output each score for every category the model predicted like this one?

Image 1:
     60% apple, 20% orange, 1% pineapple
     It implies that the image is an apple.


Image 2:
     40% apple, 60% orange, 10% pineapple
     It implies that the image is an orange.

Is there any libraries I can use with?

Does it depend on the model I am using? If yes, what are these models that implement this evaluation?

$\endgroup$
1
$\begingroup$

Based on the description of your question, it seems that you want the probability of outcome of each class (in multiclass-classification).

I would suggest you to use XGBoost to get output based on your requirement. By setting the value of objective parameter to multi:softprob, you can get probability of prediction of each and every class. If you set the value of objective parameter to multi:softmax, then you will only get the class with maximum probability among other classes.

Here, I am writing a example for your reference and to explain this description in a better way. You can get output by printing y_test_preds.

import xgboost as xgb

xgb_class = xgb.XGBClassifier(**params)
bst = xgb.train(params, dtrain, num_rounds)
y_test_preds = bst.predict(dtest)

By the following way, you can set the parameters for XGBoost. I would strongly suggest you to modify these parameters (except objective) based on your data and requirements.

params = {
     'objective' : 'multi:softprob',
     'max_depth' : 6,
     'silent' : 1,
     'eta' : 0.4,
     'num_class' : 3,
     'n_estimators' : 500,
     'learning_rate' : 0.1,
     'num_rounds' : 15
}

Note: In XGBoost, you have to use DMatrix instead of DataFrame. You can also get the DMatrix from DataFrame by this way.

dtrain = xgb.DMatrix(X_train.values, label = y_train.values)
dtest = xgb.DMatrix(X_test.values, label = y_test.values)

If you are new to XGBoost, then I would recommend you to go through this link once. https://xgboost.readthedocs.io/en/latest/get_started.html

| improve this answer | |
$\endgroup$
  • $\begingroup$ I will try to implement this method. Thanks for answering. $\endgroup$ – Jemar Villareal Aug 9 '18 at 10:28

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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