<jupyter_start><jupyter_text>Logistic Regression<jupyter_code>train=pd.read_csv('data/train.csv')
valid=pd.read_csv('data/valid.csv')

df=pd.concat([train, valid])
df.describe()
cols=['car_value_as_new',
'car_year',
'pol_holder_age',
'pol_holder_licence_length',
'car_top_speed',
'postcode_rating',
'credit_rating',
'criminal_convictions']
X=df[cols]
y=df['large_collision']
X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.3, random_state=0)

logreg = LogisticRegression()
logreg.fit(X_train, y_train)
y_pred=logreg.predict(X_test)
y_pred_prob=logreg.predict_proba(X_test)
y_pred_prob=[p[1] for p in y_pred_prob]
print('Accuracy Score:', accuracy_score(y_test, y_pred))
print('Precision Score:', precision_score(y_test, y_pred, average=None))
print('Recall Score:', recall_score(y_test, y_pred, average=None))
print('F1 Score:', f1_score(y_test, y_pred, average=None))
print('AUROC:', roc_auc_score(y_test, y_pred_prob))
print('MCC:', matthews_corrcoef(y_test, y_pred), '\n')
def model_performance_metrics(train_pred, ):
    ''' function to return the model performance metrics '''

    print(f"{model_name} Training Performance Metrics:\n")
    tn, fp, fn, tp = confusion_matrix(train_pred, y_train).ravel()
    print('True Negatives:', tn, 'False Positives:', fp, 'False Negatives:', fn, 'True Positives:', tp)
    print('Accuracy Score:', accuracy_score(y_train, train_pred))
    print('Precision Score:', precision_score(y_train, train_pred, average=None))
    print('Recall Score:', recall_score(y_train, train_pred, average=None))
    print('F1 Score:', f1_score(y_train, train_pred, average=None))
    print('AUROC:', roc_auc_score(y_train, train_prob))
    print('MCC:', matthews_corrcoef(y_train, train_pred), '\n')<jupyter_output><empty_output><jupyter_text>XGBoost<jupyter_code># split data into X and y
X = train[cols]
Y = train['large_collision']
# fit model no training data
model = XGBClassifier()
model.fit(X_train, y_train)
# make predictions for test data
y_test=valid['large_collision']
y_pred = model.predict(valid[cols])
y_pred_prob = model.predict_proba(valid[cols])
y_pred_prob=[p[1] for p in y_pred_prob]
# evaluate predictions
print('Accuracy Score:', accuracy_score(y_test, y_pred))
print('Precision Score:', precision_score(y_test, y_pred, average=None))
print('Recall Score:', recall_score(y_test, y_pred, average=None))
print('F1 Score:', f1_score(y_test, y_pred, average=None))
print('AUROC:', roc_auc_score(y_test, y_pred_prob))
print('MCC:', matthews_corrcoef(y_test, y_pred), '\n')<jupyter_output>Accuracy Score: 0.81036
Precision Score: [0.81468434 0.66643812]
Recall Score: [0.98784737 0.09751693]
F1 Score: [0.89294827 0.17013828]
AUROC: 0.7162941136787359
MCC: 0.20265903449097106
{'fraction_non_alphanumeric': 0.15005476451259583, 'fraction_numerical': 0.03906535231836437, 'mean_word_length': 8.647887323943662, 'pattern_counts': {'":': 0, '<': 8, '<?xml version=': 0, '>': 8, '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': '2', 'dir': 'jupyter-structured-clean-dedup', 'id': '453073', 'license': 'CNRI-Python', 'n_tokens_mistral': 1141, 'n_tokens_neox': 1064, 'n_words': 198, 'path': 'ML_Model_Demo.ipynb', 'repo_name': 'benturner993/ml_dataset_creation', 'size': '2739'}