A Stricter Yes

Machine Learning in CodeMedium+10 XP+10

A Stricter Yes

A small lender has past loans. Each row is [income, debt] in thousands, and each label is 1 if the loan was repaid and 0 if not. The lender only wants to say yes when the model is sure enough.

Write approve_at_threshold(rows, repaid, new_rows, threshold).

  • Fit make_pipeline(StandardScaler(), LogisticRegression(max_iter=1000)) on rows and repaid.
  • For each row in new_rows, get the model's probability of class 1 (repaid) with predict_proba.
  • Approve (1) when that probability is greater than or equal to threshold. Otherwise refuse (0).

Return a list of 1s and 0s, one per new row, in order.

Examples

rows = [[20, 15], [25, 18], [30, 10], [35, 22], [40, 8], [45, 12], [50, 5], [55, 20], [60, 4], [65, 9], [70, 3], [28, 25], [33, 6], [48, 16], [58, 14], [38, 17]]
repaid = [0, 0, 1, 0, 1, 1, 1, 0, 1, 1, 1, 0, 1, 0, 1, 0]
new_rows = [[42, 10], [30, 14], [62, 7], [45, 15], [52, 12], [26, 9], [36, 12]]
threshold = 0.5
returns [1, 0, 1, 0, 1, 1, 1]
rows = [[20, 15], [25, 18], [30, 10], [35, 22], [40, 8], [45, 12], [50, 5], [55, 20], [60, 4], [65, 9], [70, 3], [28, 25], [33, 6], [48, 16], [58, 14], [38, 17]]
repaid = [0, 0, 1, 0, 1, 1, 1, 0, 1, 1, 1, 0, 1, 0, 1, 0]
new_rows = [[42, 10], [30, 14], [62, 7], [45, 15], [52, 12], [26, 9], [36, 12]]
threshold = 0.7
returns [1, 0, 1, 0, 1, 0, 0]

Hints

Solve it to unlock the solution

Once your code passes every test, a reference solution shows up here so you can compare it with yours.

solution.py
CtrlEnterto run