You are the analyst at Summit Gear Co. Last week you predicted how long each account takes to pay. This week the credit team asks a different question about the same 2,200 accounts: which ones are likely to default, so a credit analyst can review them before the next order ships on terms? A review costs about $400 of analyst time. A default the team does not see coming costs about $2,000 after recoveries. An AI tool can write the fitting code. You choose the predictors, check that each fit ran, and recommend a cutoff to the credit team with what it costs.
Then choose File > Save a copy in Drive and work in your copy. The copy that opens from the link does not save your work. If your U of U Google account cannot open Colab, a personal Google account can.
Before you start
- Time. Plan on about 3 hours: about an hour for Exercise 1, and somewhat less for each of the other two. Most of the time goes to the three helpers and the four written cells, not to the fits.
- Practice first, if you like. The logistic regression trainer walks through odds, the sigmoid, odds ratios and one account's probability, which is Exercise 1. The cutoffs and cost trainer covers the confusion matrix, what each mistake costs and the ROC curve, which is Exercises 2 and 3. Neither is graded.
- What "write it yourself" means. The three helpers (
sigmoid,confusion_counts,total_cost) are yours to type. You can ask the tutor to explain an idea or an error first. - The helpers are graded on inputs you have not seen. For
sigmoidthese are ordinary scores, the size a fitted model produces, somath.expworks without special handling. - In Canvas, Lab 11 is a short quiz with one file upload and four short closing questions, which are not graded.
The data
- summit_gear_customers.csv: the same 2,200 accounts as Week 10, one row each. The notebook reads it from this link for you.
- The data dictionary: every column, its unit and its timing.
The target is defaulted: 1 if the account's receivable was written off as uncollectible during the period (the 12 months that follow its start), 0 if it was not written off in the period (this lab says "did not default"). Every predictor is measured as of the start of the period, so the review list can be made then. About 20% of the accounts defaulted. That share is the base rate. Calling every account "will not default" is the flag-nobody benchmark: it is right about 80% of the time and catches no one, and every model this week is compared with it.
You choose the predictors. Your list must include prior_late_count and discount_rate, and may add any of the other eight Week 10 candidates and segment. days_to_pay, industry, customer_id, tenure_months, region and defaulted stay out, and the notebook says why if you try one.
The three steps
- 1Specify and fit
Choose your predictors, have the AI fit the logistic regression, read two odds ratios, and turn one account's columns into a probability.
All 2,200 accounts - 2From a probability to a call
Refit on the training rows, flag test accounts at a 0.5 cutoff, and count the four kinds of call.
Fit on 1,760, judge on 440 - 3Choose a cutoff
Find the cheapest cutoff on the training rows, score it once on the test rows, compare train and test AUC, and decide.
Choose on 1,760, score on 440
The three exercises
Exercise 1: Specify and fit 34 points
- Set
PREDICTORS. Start from the two required columns and add only the ones you can defend. - Write the model definition.
- Have the AI write the
statsmodelsLogitofdefaultedon your list, on all 2,200 rows. Check that it ran on 2,200 rows, converged, and used your predictors. Exercise 1 uses every row because its job is to read the model; Exercise 2 refits on the training rows so the model can be judged on rows it has not seen. - Write
sigmoidyourself. It turns a score (the log-odds) into a probability, and the notebook uses it to turn account C-01182's columns into a probability. - An odds ratio is e raised to the coefficient: it multiplies the odds of default, not the probability. A dollar column's odds ratio prints as 1.0000, so read it per $1,000 from the unrounded coefficient, for example
np.exp(1000 * logit_full.params["avg_balance"]).
Written: Model definition. Five lines, one each.
- Target: the column, and what 1 and 0 mean
- Predictors and units: each predictor you chose, and its unit
- Why each belongs: one reason per predictor
- Look-ahead check: would you have each value at the start of the period, when the review list is made?
- Benchmark to beat: the flag-nobody benchmark, and how often it is right
Graded on (12 points): All five lines filled. The target says what 1 and 0 mean. Each predictor has its unit and a business reason, not "it was significant". The look-ahead check says why each value is known at the start of the period. The benchmark names the flag-nobody accuracy.
Written: Your interpretation. Three to five sentences.
- Read two odds ratios in credit terms, holding the other predictors fixed. One of them must be
prior_late_count. - Give the probability your model assigns to account C-01182, and say what it means for the credit team.
Graded on (12 points): Two odds ratios, one of them prior_late_count, read as multipliers on the odds with the other predictors held fixed, and matching your output. The probability for C-01182 from your output, read for the credit team.
Exercise 2: From a probability to a call 32 points
- Run the fixed split as given.
- Have the AI refit your model on the training rows and predict a probability for every training row and every test row. The test columns are built the same way as the training columns and reindexed to them, so the two line up.
- Write
confusion_countsyourself. A cutoff turns a probability into a call: flag the account when its probability is at or above the cutoff. Each call lands in one of the four cells below. - At 0.5 the notebook reports accuracy, the flag-nobody accuracy on the same rows, precision and recall.
| flagged | not flagged | |
|---|---|---|
| defaulted | true positive: caughtThe review catches it in time.costs the $400 review | false negative: missedThe loss goes through.costs $2,000 |
| did not default | false positive: a review that was not neededAnalyst time on a good account.costs the $400 review | true negative: clearedNo review, no loss.costs nothing |
Precision is the share of flagged accounts that defaulted (the left column). Recall is the share of defaults the model flagged (the top row).
Written: Your interpretation. Two or three sentences.
- Compare your model's accuracy at 0.5 with the flag-nobody accuracy on the same test rows, with both numbers.
- Say why the two are so close.
- Say what precision and recall show that accuracy does not.
Graded on (14 points): Accuracy at 0.5 and the flag-nobody accuracy on the same test rows, with both numbers. Why they are close. What precision and recall show, each defined correctly.
Exercise 3: Choose a cutoff 34 points
- Write
total_costyourself: every flagged account costs a $400 review, and every missed default costs $2,000. The break-even probability is where a review and no review are expected to cost the same: p × $2,000 = $400, so p = 0.20. - The notebook scores every cutoff from 0.05 to 0.95 on the 1,760 training rows with your two helpers and takes the cheapest. If two cutoffs tie, it takes the lower one, and either is accepted.
- It then scores that one cutoff on the 440 test rows, beside the test cost at 0.5 and of reviewing nobody. Choosing the cutoff on the test rows and reporting its cost on those same rows would make the cost look better than the model is likely to do on new accounts, because the choice already saw those outcomes.
- Write your own prompt for this one, and have the AI compute the AUC on the training rows and on the test rows. Name the function, the two probability arrays, the two target columns, and the two names the Final check reads,
train_aucandtest_auc. AUC runs from 0 to 1: it is the chance the model gives a randomly chosen defaulter a higher probability than a randomly chosen account that did not default (ties count half), so 0.5 is a coin flip.
Written: Your decision. One paragraph to the credit manager, about 150 to 250 words.
- The cutoff you would hand the credit team, and why.
- How it compares with the 0.20 break-even ($400 / $2,000), and why the two can differ.
- What it costs on the test rows against 0.5 and against reviewing nobody.
- What the train and test AUC comparison says. With 88 defaults in the test rows, a gap of several hundredths can come from the draw alone.
- One thing this table cannot see.
Graded on (16 points): The cutoff from your training-row sweep. How it compares with the 0.20 break-even and why the two can differ. Its test cost against 0.5 and against reviewing nobody, from your output. A hedged reading of the train and test AUC. One thing the table cannot see.
Ask the tutor
The tutor reads this box and the exercise. It can explain a statsmodels call, an odds ratio or an error. It will not write your three helpers or your written answers for you.
What the tutor sees, and a prompt to copy into another AI tool
The preview shows the full prompt, including earlier turns of the conversation. Nothing on this page submits to Canvas.
What to submit
In Canvas, Lab 11 is a short quiz with one file upload and four short closing questions. The file is your notebook, run top to bottom. In Colab choose File > Download > Download .ipynb, rename it <uID>_lab_11.ipynb with your uID in place of <uID>, upload it to Lab 11, answer the closing questions, and submit the quiz.
Three checks before you submit
- Runtime > Restart session and run all. Every cell shows its output, and the Final check reads your latest work.
- The Final check prints
RESULTSwith nonullin it, and every row is green. - Your four written cells have your words in them, not the placeholder line.
Lab 11 check: 11 of 12 done
| ✓ | PREDICTORS: a list that follows the rule | done |
| ✓ | logit_full: 2,200 rows, converged, your PREDICTORS | done |
| ✓ | sigmoid: fixed example | done |
| ✓ | train and test: 1,760 and 440 rows, 88 defaults in test | done |
| ✓ | logit_train: 1,760 rows, converged, the same terms | done |
| ✓ | train_prob and test_prob: 1,760 and 440 probabilities | done |
| ✓ | confusion_counts: fixed example | done |
| ✓ | accuracy, precision and recall at 0.5 | done |
| ✓ | total_cost: fixed example | done |
| ✓ | cutoff chosen on the 1,760 training rows | done |
| ✓ | that cutoff scored once on the 440 test rows | done |
| ✗ | AUC: training rows and test rows | not yet, see Exercise 3 |
RESULTS = {"predictors": [your list], "n_train": 1760, "n_test": 440, "test_defaults": 88, "base_rate": 0.1991, "or_prior_late": x.xxxx, "acc_050": 0.xxxx, "naive_acc": 0.xxxx, "precision_050": 0.xxxx, "recall_050": 0.xxxx, "cutoff_train": 0.xx, "cost_train_at_cutoff": xxxxxx, "cost_test_at_cutoff": xxxxxx, "cost_050": xxxxxx, "cost_nobody": xxxxxx, "train_auc": null, "test_auc": null}
Still to do: AUC: training rows and test rows (Exercise 3)
null and one row is red, so this notebook is not ready to submit. A red row names the exercise to go back to.How it is graded
Lab 11 is worth 100 points, all of them for the notebook. The four closing questions are not graded.
| Exercise | Numbers in RESULTS | Your helper, on inputs you have not seen | Your writing | Total |
|---|---|---|---|---|
| 1. Specify and fit | a legal list, the fit, the prior_late_count odds ratio: 4 | sigmoid: 6 | model definition 12, interpretation 12 | 34 |
| 2. From a probability to a call | the split, the refit, accuracy, precision, recall: 8 | confusion_counts: 10 | interpretation 14 | 32 |
| 3. Choose a cutoff | the training-row cutoff, the three test costs, both AUCs: 8 | total_cost: 10 | decision 16 | 34 |
| Total | 100 |
A script reads the RESULTS your Final check prints. Because you chose your own predictors, it refits your list from the data and checks your numbers against that fit, so there is no single answer everyone has to match. If two cutoffs tie for the cheapest on the training rows, either one is accepted. The script also runs your three helpers on inputs you have not seen.
The four written cells are 54 of the 100 points. Each is read against the line under "Graded on" in its exercise above, and any number you quote is checked against your own output. An AI tool may write the fitting code. The points go to the predictors you chose, the checks you ran and the four written cells.
You may resubmit. Each new attempt starts empty, so upload the notebook again and answer the closing questions again. The latest attempt is kept, so a resubmission after the deadline replaces your on-time attempt and is marked late.