<jupyter_start><jupyter_text>**Stacking**<jupyter_code># Importing the meta learner and base learners
from sklearn.linear_model import LogisticRegression
from sklearn.neighbors import KNeighborsClassifier
from sklearn.ensemble import RandomForestClassifier

bl1 = KNeighborsClassifier(n_neighbors=5)
bl2 = RandomForestClassifier(random_state=123)
ml = LogisticRegression(random_state=123)
# Creating the stacking classifier
from mlxtend.classifier import StackingClassifier
stackclf = StackingClassifier(classifiers=[bl1, bl2], 
                          meta_classifier=ml)
# Fitting the model on the training set
model = stackclf.fit(X_train, y_train)

# Generating predictions on test set
pred = model.predict(X_test)
# Printing the classification report
from sklearn.metrics import classification_report
print(classification_report(y_test, pred))
# Printing the confusion matrix
from sklearn.metrics import confusion_matrix
print(confusion_matrix(y_test, pred))<jupyter_output>[[98  9]
 [14 75]]
{'fraction_non_alphanumeric': 0.07007007007007007, 'fraction_numerical': 0.018018018018018018, 'mean_word_length': 6.8125, 'pattern_counts': {'":': 0, '<': 4, '<?xml version=': 0, '>': 4, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '1', 'dir': 'jupyter-structured-clean-dedup', 'id': '26491', 'license': 'MIT', 'n_tokens_mistral': 322, 'n_tokens_neox': 303, 'n_words': 78, 'path': 'Chapter15/Exercise15.07/Exercise_15_07_Ensemble_learning_Stacking.ipynb', 'repo_name': 'khieunguyen/The-Data-Science-Workshop', 'size': '999'}