The Lazy Model Next Door

Machine Learning in CodeEasy+10 XP+10

The Lazy Model Next Door

A bank wants to know if its fraud model is any better than doing nothing. You will build both and score them side by side.

Task: write lazy_versus_trained(rare_share, seed).

  1. Make the data with make_classification(n_samples=2000, n_features=10, n_informative=4, weights=[1 - rare_share, rare_share], class_sep=1.8, flip_y=0.01, random_state=seed). Class 1 is fraud, and rare_share is roughly the share of rows that are fraud.
  2. Split it with train_test_split(X, y, test_size=0.25, random_state=0, stratify=y).
  3. Fit a DummyClassifier(strategy="most_frequent") on the training rows. This is the lazy model.
  4. Fit make_pipeline(StandardScaler(), LogisticRegression(max_iter=1000)) on the training rows. This is the trained model.

Return a list of three numbers, each rounded to 3 decimal places:

  • the lazy model's accuracy on the test rows,
  • the trained model's accuracy on the test rows,
  • the trained model's recall on the test rows: the share of real frauds (class 1) that it flagged.

Look at the first test. The two accuracies are close, but the recall tells a very different story.

Examples

rare_share = 0.05
seed = 0
returns [0.946, 0.956, 0.185]
rare_share = 0.5
seed = 0
returns [0.5, 0.736, 0.76]

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