<jupyter_start><jupyter_text>Selecting model using TPOT<jupyter_code>from tpot import TPOTClassifier

tpot = TPOTClassifier(generations=5,population_size=20,verbosity=2,
scoring='roc_auc',random_state=42,disable_update_check=True,config_dict='TPOT light')

tpot.fit(X_train, y_train)
# AUC score for tpot model
tpot_auc_score = roc_auc_score(y_test, tpot.predict_proba(X_test)[:, 1])
print(f'\nAUC score: {tpot_auc_score:.4f}')
# Print best pipeline steps
print('\nBest pipeline steps:', end='\n')
for idx, (name, transform) in enumerate(tpot.fitted_pipeline_.steps, start=1):
    # Print idx and transform
    print(f'{idx}. {transform}')
# X_train's variance, rounding the output to 3 decimal places
X_train.var().round(3)
# Copy X_train and X_test into X_train_normed and X_test_normed
X_train_normed,X_test_normed = X_train.copy(), X_test.copy()

# Specify which column to normalize
col_to_normalize = 'Monetary (c.c. blood)'

# Log normalization
for df_ in [X_train_normed, X_test_normed]:
    # Add log normalized column
    df_['monetary_log'] = np.log(df_[col_to_normalize])
    # Drop the original column
    df_.drop(columns=col_to_normalize, inplace=True)

# Check the variance for X_train_normed.
X_train_normed.var().round(3)<jupyter_output><empty_output><jupyter_text>logistic regression:<jupyter_code>logreg =LogisticRegression(solver='liblinear',random_state=42)
logreg.fit(X_train_normed, y_train)
logreg_auc_score = roc_auc_score(y_test, logreg.predict_proba(X_test_normed)[:, 1])
print((logreg_auc_score))
from sklearn.ensemble import RandomForestClassifier

rfc= RandomForestClassifier(n_estimators=700).fit(X_train_normed,y_train)
predictionforest = rfc.predict(X_test)
rfc.score(X_train_normed, y_train)
rfc_score = roc_auc_score(y_test, rfc.predict_proba(X_test_normed)[:, 1])
print((rfc_score))
from operator import itemgetter

# Sort models based on their AUC score from highest to lowest
sorted([('tpot', tpot_auc_score), ('logreg', logreg_auc_score),('rfc', rfc_score)],key=itemgetter(1),
    reverse=True)<jupyter_output><empty_output>
StarcoderdataJupyterStructuredCleanDedup