Code Along
/module-3
Loading, setting up: create a .R file in /module-3 and run this code
Model building with training data
Model evaluating with testing data
Loading, setting up: create a .py file in /module-3 and run this code
Train-test split the dataset
Specify the model formula and fit it to the training dataset
Make predictions on test dataset
Calculate model metrics
from sklearn.metrics import accuracy_score, recall_score, confusion_matrix, cohen_kappa_score
# Metrics we'se seen:
accuracy = accuracy_score(y_actual, y_preds)
# New metrics
precision = precision_score(y_actual, y_preds, pos_label=1)
kappa = cohen_kappa_score(y_actual, y_preds)
# We'll learn more about the confusion matrix in the case study
true_negative, false_positive, false_negative, true_positive = confusion_matrix(y_actual, y_preds).ravel()
sensitivity = true_positive / (true_positive + false_negative) # or the sklearn.metrics recall_score function
specificity = true_negative / (true_negative + false_positive)
negative_predictive_value = true_negative / (true_negative + false_negative)