Who Wins Each Split?

Machine Learning in CodeMedium+10 XP+10

Who Wins Each Split?

One train/test split decides nothing: change which rows are held back and the winner can change. Count how often each model wins on the wine data.

Write wins_per_split(seeds).

For each seed in seeds:

  • Load the data with load_wine(return_X_y=True, as_frame=True) and split it with train_test_split(X, y, test_size=0.25, random_state=seed, stratify=y).
  • Fit and test-score three models:
    • "logistic": make_pipeline(StandardScaler(), LogisticRegression(max_iter=1000))
    • "bayes": GaussianNB()
    • "tree": DecisionTreeClassifier(max_depth=3, random_state=0)
  • The winner of that split is the model with the highest test score rounded to 3 places. On a tie, the winner is the one that comes first in the list above.

Return a dict with all three names, each mapped to the number of splits it won (an int, which can be 0).

Examples

seeds = [0, 1]
returns {'logistic': 1, 'bayes': 1, 'tree': 0}
seeds = [2]
returns {'logistic': 1, 'bayes': 0, 'tree': 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