<jupyter_start><jupyter_text>1.Import data<jupyter_code>data = pd.read_csv('../data/data_cleaned.csv')

X, y = data.drop('Survived', axis=1), data.pop('Survived')

X_train, X_test, y_train, y_test = train_test_split(X,y, test_size=0.3, stratify=y)<jupyter_output><empty_output><jupyter_text>2. Creade models<jupyter_code>DT = DecisionTreeClassifier()
KNN = KNeighborsClassifier()
LR = LogisticRegression(solver='lbfgs', max_iter=1000)<jupyter_output><empty_output><jupyter_text>3. Evaluate each model<jupyter_code>DT.fit(X_train, y_train)
KNN.fit(X_train, y_train)
LR.fit(X_train, y_train)

DT.score(X_test, y_test), KNN.score(X_test, y_test) , LR.score(X_test, y_test)<jupyter_output><empty_output><jupyter_text>3. Train models and create new datasets using their predictions  3.1 First approach: feeding the entire dataset<jupyter_code>def model_predictions_holdout(model, X_train, y_train, X_holdout, X_test):
    #train the model
    model.fit(X_train, y_train)
    
    model_name = model.__class__.__name__
    model_name = "".join(c for c in model_name if c.isupper()) 

    #storing predictions for train and test
    pred_train=model.predict(X_holdout)
    pred_train = pd.DataFrame(pred_train, index = X_holdout.index, columns=[model_name])
    pred_test=model.predict(X_test)
    pred_test = pd.DataFrame(pred_test, index = X_test.index, columns=[model_name])

    return pred_train, pred_test<jupyter_output><empty_output><jupyter_text>a) Train models<jupyter_code>DT = DecisionTreeClassifier()
KNN = KNeighborsClassifier()
LR = LogisticRegression(solver='liblinear', max_iter=1000)

X_train, X_holdout, y_train, y_holdout = train_test_split(X_train, y_train, test_size=0.3)


M1_train, M1_test = model_predictions_holdout(DT, X_train, y_train, X_holdout, X_test)
M2_train, M2_test = model_predictions_holdout(KNN, X_train, y_train, X_holdout, X_test)
M3_train, M3_test = model_predictions_holdout(LR, X_train, y_train, X_holdout, X_test)<jupyter_output><empty_output><jupyter_text>b) Create the base models predictions dataset<jupyter_code>X_train_meta = pd.concat([X_holdout, M1_train, M2_train, M3_train],axis=1)
X_test_meta = pd.concat([X_test, M1_test, M2_test, M3_test],axis=1)<jupyter_output><empty_output><jupyter_text>c) Make predictions<jupyter_code># Stacker Model
meta_model = RidgeClassifier()
meta_model.fit(X_train_meta, y_holdout)
meta_model.score(X_test_meta,y_test)<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.11670103092783506, 'fraction_numerical': 0.013608247422680412, 'mean_word_length': 8.052238805970148, 'pattern_counts': {'":': 0, '<': 29, '<?xml version=': 0, '>': 29, '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': '7', 'dir': 'jupyter-structured-clean-dedup', 'id': '229789', 'license': 'MIT', 'n_tokens_mistral': 979, 'n_tokens_neox': 953, 'n_words': 154, 'path': 'blending/blending.ipynb', 'repo_name': 'maikereis/ensembling_techniques', 'size': '2425'}