<jupyter_start><jupyter_text>A Classifier Model Performance EvaluationThe material for evaluting a classifier here are applied to all classifiersWe focused our concentration to Logistic RegressionRead this to undestand what is Logistic Regression: https://www.datacamp.com/community/tutorials/understanding-logistic-regression-python  Activity: Obtain confusion matrix, accuracy, precision, recall for pima Diabetes datasetSteps:1- Load the dataset: `pd.read_csv('diabetes.csv')`2- Use these features: `feature_cols = ['Pregnancies', 'Insulin', 'BMI', 'Age']`3- split the data to train and test: `X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.25, random_state=0)`4- Instantiate logistic regressiuon model5- Obtain the statistics of `y_test`6- Obtain the confuction matrixhttps://www.ritchieng.com/machine-learning-evaluate-classification-model/  Basic terminologyTrue Positives (TP): we correctly predicted that they do have diabetes: 15True Negatives (TN): we correctly predicted that they don't have diabetes: 118False Positives (FP): we incorrectly predicted that they do have diabetes (a "Type I error"): 12False Negatives (FN): we incorrectly predicted that they don't have diabetes (a "Type II error"): 47  What is accuracy, recall and precision?Accuracy: overall, how often is the classifier correct? -> $accuracy = \frac {TP + TN}{TP+TN+FP+FN}$Classification error: overall, how ofthen is the classifier incorrect? -> $error = 1- accuracy = \frac {FP + FN}{TP + TN + FP + FN}$Recall: when the actual value is positive, how ofthen is the prediction correct? -> $recall = \frac {TP}{TP + FN}$Precision: When a positive value is predicted, how often is the prediction correct? -> $precision = \frac {TP}{TP + FP}$Specificity: When the actual value is negative, how often is the prediction correct? -> $Specificity = \frac {TN}{TN + FP}$<jupyter_code>import pandas as pd
from sklearn.model_selection import train_test_split

pima = pd.read_csv('diabetes.csv')
print(pima.columns)
print(pima.head())

feature_cols = ['Pregnancies', 'Insulin', 'BMI', 'Age']

X = pima[feature_cols]
# print(X)
# y is a vector, hence we use dot to access 'label'
y = pima['Outcome']

# split X and y into training and testing sets
X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.25, random_state=0)

y_test.value_counts()<jupyter_output>Index(['Pregnancies', 'Glucose', 'BloodPressure', 'SkinThickness', 'Insulin',
       'BMI', 'DiabetesPedigreeFunction', 'Age', 'Outcome'],
      dtype='object')
   Pregnancies  Glucose  BloodPressure  SkinThickness  Insulin   BMI  \
0            6      148             72             35        0  33.6   
1            1       85             66             29        0  26.6   
2            8      183             64              0        0  23.3   
3            1       89             66             23       94  28.1   
4            0      137             40             35      168  43.1   

   DiabetesPedigreeFunction  Age  Outcome  
0                     0.627   50        1  
1                     0.351   31        0  
2                     0.672   32        1  
3                     0.167   21        0  
4                     2.288   33        1
{'fraction_non_alphanumeric': 0.09217877094972067, 'fraction_numerical': 0.04003724394785847, 'mean_word_length': 2.6834285714285713, 'pattern_counts': {'":': 0, '<': 4, '<?xml version=': 0, '>': 9, 'https://': 2, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 10, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '1', 'dir': 'jupyter-structured-clean-dedup', 'id': '14094', 'license': 'MIT', 'n_tokens_mistral': 1044, 'n_tokens_neox': 929, 'n_words': 340, 'path': 'site/public/courses/DS-2.1/Notebooks/.ipynb_checkpoints/model_evaluation_slide-checkpoint.ipynb', 'repo_name': 'KitsuneNoctus/makeschool', 'size': '3222'}