CS 460G Midterm Hub / Notebooks / Assignment 1 — Diabetes Linear Classification
Python notebook · CS460G-Assignment1.ipynb

Assignment 1 — Diabetes Linear Classification

The graded starter notebook: what each section asks for, and what it is marked on

assignmentQ5 material

This is the starter notebook, not a completed one — every task is a #To Do: cell. What matters for the exam is that you can explain the intended pipeline and the rubric behind it.

The rubric, verbatim from the notebook

> Graded under three major criteria: > - Functional code — completed code with every piece functional > - Correctness — correct code that gives accurate results unless otherwise stated > - Documentation — every cell well documented and easy to follow to reproduce the results

Plus two fixed 5-point sections: Use of Generative AI and Discussion with Others.

Section 1 — Dataset preparation (30 points)

The tasks, in order:

  1. Mount Google Drive
  2. pd.read_csv the diabetes CSV from a path on Drive
  3. Check the "keys" — i.e. columns and dtypes
  4. Display the full dataset and its shape
  5. Extract features and target
  6. Check their shapes
  7. Display the features
  8. Check the label distribution
  9. Write your findings on the label distribution (a markdown cell — this is the one people leave blank)
  10. Scatter plot of bmi vs HbA1c_level, coloured by label, properly annotated

What "check, analyse, visualise" means in practice. The notebook's own header says "Understand it: check, analyze, visualize". A head() alone is not that. The full inspection is:

df.shape
df.dtypes
df.isna().sum()
df.duplicated().sum()
df.describe().T

The graded deduction "check the keys only, not values" came from exactly this: a student ran df.keys() and stopped. Keys tell you the column names; they tell you nothing about range, dtype, missingness or duplicates.

The label-distribution finding you are expected to write. The dataset is 91,500 negative / 8,500 positive = 91.5% / 8.5%, a ratio of 10.76 : 1. State the consequence: a majority-class predictor scores 0.9166 accuracy while detecting nothing, so accuracy is not a usable metric here — F1, recall and ROC-AUC are.

Section 2 — Two features (30 points)

  1. Select any two features (the notebook suggests bmi and HbA1c_level)
  2. Verify shapes
  3. train_test_split
  4. Check the label distribution for both train and test
  5. Load and fit LogisticRegression
  6. Predict
  7. Decision boundary showing train and test points with class labels
  8. Confusion matrix
  9. F1 score computed from the confusion matrix
  10. ROC curve, properly annotated

Why bmi and HbA1c_level: these are the two strongest univariate predictors — HbA1c means 6.93 (positive) vs 5.40 (negative), BMI means 31.99 vs 26.89. Choosing them makes the 2-feature model as strong as it can be, which is the fair comparison against the 6-feature model.

The F1-from-confusion-matrix cell, done correctly

from sklearn.metrics import confusion_matrix
TN, FP, FN, TP = confusion_matrix(Y_test, Y_pred, labels=[0,1]).ravel()

precision = TP / (TP + FP)
recall    = TP / (TP + FN)
f1        = 2  precision  recall / (precision + recall)

# cross-check
from sklearn.metrics import f1_score
assert abs(f1 - f1_score(Y_test, Y_pred)) < 1e-9

The labels=[0,1] argument is not optional. It fixes the row/column order so .ravel() returns [TN, FP, FN, TP] deterministically. Without it the order follows whatever sorted order the labels happen to take.

The ROC cell, done correctly

y_prob = LR_model.predict_proba(X_test)[:, 1]      # P(class 1)
fpr, tpr, _ = roc_curve(Y_test, y_prob)
auc = roc_auc_score(Y_test, y_prob)
plt.plot(fpr, tpr, label=f'LogisticRegression (AUC = {auc:.3f})')
plt.plot([0,1],[0,1],'k--', label='Random')
plt.xlabel('False Positive Rate (1 - specificity)')
plt.ylabel('True Positive Rate (sensitivity)')
plt.legend()

Why [:,1]: predict_proba returns an (n, 2) array — column 0 is $P(\text{class }0)$, column 1 is $P(\text{class }1)$. Passing the whole array to roc_curve raises a shape error, and passing column 0 silently gives you the inverted curve with AUC $= 1-\text{AUC}$.

Section 3 — Six features (30 points)

Repeat everything except the scatter plot and the decision boundary (which cannot be drawn in 6-D). So: split → fit → predict → confusion matrix → F1 → ROC.

The comparison is the deliverable, not the numbers. The expected discussion:

Metric2 features6 featuresChange
Accuracy0.94390.9616+1.8 pts
Recall (class 1)0.36690.6422+27.5 pts
Precision (class 1)0.90320.8628−4.0 pts
F1 (class 1)0.52180.7363+21.5 pts
ROC-AUC0.88430.9627+7.8 pts

The sentence to write: accuracy understates the improvement by an order of magnitude because the majority class dominates it. What actually changed is recall — the 2-feature model only fires when it is very confident (precision 0.90, recall 0.37), missing 1,320 of the 2,085 positives; the 6-feature model trades 4 points of precision for 574 more true positives. For a screening task that is the correct trade, and it is invisible if you only report accuracy.

Section 4 — Use of Generative AI (5 points)

Three sub-questions: did you use GenAI (1), list every prompt (3), what percentage split of credit (1).

The honest answer scores better than a blank one. In the graded run, a thorough disclosure (prompt list plus a 75:25 human:AI split) was explicitly appreciated by the grader — the deduction was for overuse, not for disclosure. Leaving "I didn't seek any GenAI assistance" when you did use it is an academic-integrity risk, not a shortcut.

Section 5 — Discussion with Others (5 points)

"No, I did not have any discussion" scores the minimum. The grader's comment was "discussion is encouraged during the lab sessions". Name who you talked to and what about — a single sentence.

What this notebook teaches about the course's expectations

  1. Inspection is graded as its own step, before any modelling.
  2. The metric must match the problem — imbalance changes which metric is meaningful.
  3. The decision boundary must show train and test, not test only.
  4. Metrics must be cross-checked against scikit-learn, not hand-rolled once.
  5. Documentation is a third of the marks — a markdown paragraph per finding, not per cell.

If asked to explain this notebook in the exam, walk the six steps in order — prepare, inspect, split, fit, evaluate, compare — and then give the one finding that matters: the 2-feature model has high precision and low recall; the 6-feature model nearly doubles recall at a small precision cost; accuracy hides this because 91.5% of the data is one class.