◢◤ ARKANE_
SYS_TIME UTC+0
Work with me
/W04

实验Lab: Which feature tells you most?

week 4
Dataset
UCI Mushroom (8,124 rows, CC BY 4.0)
Time
2 hours

Capstone Due this week: Capstone proposal: problem statement, dataset, and success criteria.

This week you'll be able to

  • Compute entropy, cross-entropy, and KL divergence for small discrete distributions.
  • Explain why log loss is cross-entropy, and why it punishes confident wrong answers.
  • Compute the information gain of a split.

Goal

Compute entropy, information gain, and cross-entropy by hand, then check them with library code. Find the single feature that best separates edible from poisonous mushrooms.

Data

Descriptions of 23 species of gilled mushroom. Every column is categorical. The target is poisonous (e edible, p poisonous).

import pandas as pd

mush = pd.read_csv("https://archive.ics.uci.edu/static/public/73/data.csv")
mush["poisonous"].value_counts()

stalk-root has 2,480 missing values. Treat missing as its own category this week.

Safety note. This is a teaching dataset. Never use a model to decide whether a real mushroom is safe to eat.

Tasks

  1. Compute the entropy of the target in bits (Procedure 5.1). It should be close to 1. Why?
  2. For each feature, compute the conditional entropy of the target given that feature, then the information gain. Write the function yourself with pandas.
  3. Rank the features by information gain. Compare your ranking with mutual_info_classif (Procedure 5.4). Mutual information is in nats by default, so convert before comparing.
  4. Look at the top feature. Show its crosstab with the target. Explain why its gain is so high.
  5. Fit a logistic regression on the top feature alone, one-hot encoded. Compute its log loss on a test split by hand (Procedure 5.2), then with sklearn.metrics.log_loss.
  6. Compute the KL divergence between the class distribution in the training split and the test split (Procedure 5.3). What would a large value warn you about?

Deliverable

A notebook with the ranked information-gain table, the crosstab, and a short paragraph on tasks 4 and 6.

Done when

  • Your information gain and the library's mutual information give the same ranking.
  • Your hand-computed log loss matches scikit-learn's.
  • You can say in one sentence why one feature nearly solves the problem.

Capstone

Your capstone proposal is due this week. See the capstone brief.

online /teaching/semester-1/labs/4 Newcastle, UK v0.1.0 // rss