Every Feature at Once
Part of the Statistics for ML section of Coddy's Machine Learning journey. Lesson 57 of 64.
Thirty features need thirty histograms. They read faster as one grid of small charts, like these four iris features:
A loop fills the grid, chart i with feature i:
names = iris.feature_names
fig, axs = plt.subplots(2, 2)
for i in range(4):
ax = axs.flat[i]
ax.hist(iris.frame[names[i]], bins=15)
ax.set_title(names[i])
fig.tight_layout()
plt.show()plt.subplots(2, 2) makes a table of charts, and axs.flat lines them up row by row:
fig.tight_layout() keeps the titles apart. Now read: both petal histograms split in two. A gap like that often means a class sits apart, so keep that feature.
Challenge
MediumSee the tissue data whole. The input picks a group, mean, error or worst, and the starter puts its first six feature names in names.
- Make a grid of 2 rows and 3 columns.
- In chart
i, draw a histogram of featureiwith 20 bins, titled with its name. - Tidy the layout, then show it.
Like this grid of six wine features:
Your program prints nothing: Coddy describes each chart.
Try it yourself
import matplotlib.pyplot as plt
from sklearn.datasets import load_breast_cancer
group = input()
cancer = load_breast_cancer(as_frame=True)
df = cancer.frame
# The first six feature names of the group: mean, error or worst
start = {"mean": 0, "error": 10, "worst": 20}[group]
names = cancer.feature_names[start:start + 6]
# Write your code below
This lesson includes a short quiz. Start the lesson to answer it and track your progress.
All lessons in Statistics for ML
1Center and Spread
Mean and MedianPercentiles and QuartilesVariance and StdSample or Population?The Most Common ValueRecap: Delivery Times4Samples and Populations
Population and SampleSample Means VaryThe Sampling DistributionBigger Samples, Less NoiseRecap: Polling a Town2Distributions
Density HistogramsShapes of DataThe Normal CurveThe 68-95-99.7 RuleZ-ScoresRecap: Battery Life8Comparing Groups
Box Plots by GroupDifference in MeansCould It Be Chance?P-ValuesThe t-TestRecap: A/B Test11Exploring a Dataset
A First LookEvery Feature at OnceFeatures Against the LabelTwo Best FeaturesRecap: Diabetes Data3Probability by Simulation
Probability as FrequencyThe Law of Large NumbersSums of DiceExpected ValueConditional ProbabilityRecap: Dice Stall Odds6Relationships
Reading Scatter PlotsCorrelationCorrelation MatrixCorrelation HeatmapsCorrelation Is Not CauseRecap: Ice Cream and SunPractice on your own: Online Python compiler