how can i get the base learners's importance? #816
Unanswered
the-black1022
asked this question in
Q&A
Replies: 1 comment
-
This can be done by generating a dataset of the meta-classifier predictions and then accessing the internally fitted 1) Setup: Assume this is your meta-classifier:from sklearn import model_selection
from sklearn.linear_model import LogisticRegression
from sklearn.neighbors import KNeighborsClassifier
from sklearn.naive_bayes import GaussianNB
from sklearn.ensemble import RandomForestClassifier
from mlxtend.classifier import StackingCVClassifier
from sklearn import datasets
import numpy as np
import warnings
iris = datasets.load_iris()
X, y = iris.data[:, 1:3], iris.target
RANDOM_SEED = 42
clf1 = KNeighborsClassifier(n_neighbors=1)
clf2 = RandomForestClassifier(random_state=RANDOM_SEED)
clf3 = GaussianNB()
lr = LogisticRegression()
sclf = StackingCVClassifier(classifiers=[clf1, clf2, clf3],
meta_classifier=lr,
random_state=RANDOM_SEED) 2) Create meta-feature predictions:sclf.fit(X, y)
meta_X = sclf.predict_meta_features(X) 3) Get feature importanceYou can now use from mlxtend.evaluate import feature_importance_permutation
mean_importance_vals, all_importance_vals = feature_importance_permutation(
meta_X, y, sclf.meta_clf_.predict, metric='accuracy')
print(mean_importance_vals)
# prints: array([0.2 , 0.26666667, 0.20666667]) |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
i was useing the stacking framework to predict. here is my steps: in the first layer, i use the classifiers such as KNN, SVM, RF, in the second layer , i use LR as meta classifier, and my problems is, the first: how do I see the contribution of each base classifier's prediction result to the final result, the second: can I adjust the weight of the prediction result of the base classifier in the second layer classifier. thank you very much
Beta Was this translation helpful? Give feedback.
All reactions