The Wine Line-Up

Machine Learning in CodeMedium+10 XP+10

The Wine Line-Up

Run six classifiers side by side on the wine data, the same way the lesson did for breast cancer.

Write wine_line_up(seed).

  • 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).
  • Build these models, under these names:
    • "logistic": make_pipeline(StandardScaler(), LogisticRegression(max_iter=1000))
    • "knn": make_pipeline(StandardScaler(), KNeighborsClassifier(n_neighbors=5))
    • "bayes": GaussianNB()
    • "svm": make_pipeline(StandardScaler(), SVC(kernel="linear"))
    • "tree": DecisionTreeClassifier(max_depth=3, random_state=0)
    • "forest": RandomForestClassifier(n_estimators=100, random_state=0)
  • Fit each on the training rows and score it on the test rows.

Return a dict with the six names mapped to their test scores, rounded to 3 places, plus one more entry "best": the name with the highest rounded score. On a tie, pick the name that comes first in the list above.

Examples

seed = 0
returns {'logistic': 1.0, 'knn': 0.933, 'bayes': 0.956, 'svm': 0.978, 'tree': 0.822, 'forest': 1.0, 'best': 'logistic'}
seed = 1
returns {'logistic': 0.978, 'knn': 0.933, 'bayes': 1.0, 'svm': 0.956, 'tree': 0.933, 'forest': 1.0, 'best': 'bayes'}

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