3

In mlxtend library, there is An ensemble-learning meta-classifier for stacking called "StackingClassifier".

Here is an example of a StackingClassifier function call:

sclf = StackingClassifier(classifiers=[clf1, clf2, clf3], 
                          meta_classifier=lr)

What is meta_classifier here? What is it used for?

user3303020
  • 933
  • 2
  • 12
  • 26

3 Answers3

3

What is stacking ?

Stacking is an ensemble learning technique to combine multiple classification models via a meta-classifier. The individual classification models are trained based on the complete training set; then, the meta-classifier is fitted based on the outputs -- meta-features -- of the individual classification models in the ensemble.

Source : StackingClassifier-mlxtend

So meta_classifier parameter helps us to choose the classifier to fit the output of the individual models.

Example:

Assume that you have used 3 binary classification models say LogisticRegression, DT & KNN for stacking. Lets say 0, 0, 1 be the classes predicted by the models. Now we need a classifier which will do majority voting on the predicted values. And that classifier is the meta_classifier. And in this example it would would pick 0 as the predicted class.

You can extend this for prob values also.

Refer mlxtend-API for more info

Kalsi
  • 579
  • 5
  • 13
  • @[user3303020](https://stackoverflow.com/users/3303020/user3303020) did this answer solved the problem you had ? – Kalsi Sep 12 '18 at 04:13
3

meta-classifier is the one that takes in all the predicted values of your models. As in your example you have three classifiers clf1, clf2, clf3 let's say clf1 is naive bayes, clf2 is random-forest, clf3 is svm. Now for every data point x_i in your dataset your all three models will run h_1(x_i), h_2(x_i), h_3(x_i) where h_1,h_2,h_3 corresponds to the function of clf1, clf2, clf3. Now these three models will give three predicted y_i values and all these will run in parallel. Now with these predicted values a model is trained which is known as meta- classifier and that is logistic regression in your case.

So for a new query point (x_q) it will calculated as h^'(h_1(x_q),h_2(x_q),h_3(x_q)) where h^'(h dash) is function that computes y_q.

The advantage of meta-classifier or ensemble models is that suppose your clf1 gives an accuracy of 90%, clf2 gives an accuracy of 92%, clf3 gives an accuracy of 93%. So the end model will give an accuracy that will be greater than 93% which is trained using meta classifier. These stacking classifer are used extensively in kaggle completions.

Aditya
  • 950
  • 8
  • 37
  • is it similar to an ensemble of trees? How the new points will be plotted after using the three classifiers? I can't understand this : Now with these predicted values a model is trained ?? If a classifier predicts a label then how can we use it in meta classifier, plz explain, Thanks! – Nischay Namdev Jun 17 '20 at 06:42
0

meta_classifier is simply the classifier that makes a final prediction among all the predictions by using those predictions as features. So, it takes classes predicted by various classifiers and pick the final one as the result that you need.

Here is a nice and simple presentation of StackingClassifier:

StackingClassifier

M. Yasin
  • 66
  • 6