<jupyter_start><jupyter_text>Stacking* Ensemble model that combines predictions from multiple models to create a better prediction* Very popular on Kaggle and other online competitions<jupyter_code>data = pd.read_csv('german_credit.csv')
X = data.loc[:, data.columns != 'Creditability']
y = data["Creditability"]
X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.3)
sc = StandardScaler()
sc.fit(X_train)
# Apply the scaler to the X training data
X_train_std = sc.transform(X_train)

# Apply the SAME scaler to the X test data
X_test_std = sc.transform(X_test)
models = [
    GradientBoostingClassifier(random_state=0,
                           n_estimators=100, max_depth=3),
        
    RandomForestClassifier(random_state=0, n_jobs=-1, 
                           n_estimators=100, max_depth=3),
        
    MLPClassifier(hidden_layer_sizes=(22, 22, 22),max_iter=1000)
]
S_train, S_test = stacking(models,                   
                           X_train_std, y_train, X_test_std,   
                           regression=False, 
     
                           mode='oof_pred_bag', 
       
                           needs_proba=False,
         
                           save_dir=None, 
            
                           metric=accuracy_score, 
    
                           n_folds=4, 
                 
                           stratified=True,
            
                           shuffle=True,  
            
                           random_state=0,    
         
                           verbose=2)
model = MLPClassifier(hidden_layer_sizes=(22, 22, 22),max_iter=1000)
    
model = model.fit(S_train, y_train)
y_pred = model.predict(S_test)
print('Final prediction score: [%.8f]' % accuracy_score(y_test, y_pred))<jupyter_output>Final prediction score: [0.75333333]
{'fraction_non_alphanumeric': 0.08511806699615596, 'fraction_numerical': 0.025260845689181768, 'mean_word_length': 1.790199081163859, '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': '585116', 'license': 'MIT', 'n_tokens_mistral': 590, 'n_tokens_neox': 546, 'n_words': 105, 'path': 'Section 8/8.4.ipynb', 'repo_name': 'PacktPublishing/Scikit-learn-Recipes', 'size': '1821'}