A First Look
Part of the Statistics for ML section of Coddy's Machine Learning journey. Lesson 56 of 64.
Every model starts with someone looking closely at its data. This chapter ends with a picture like this: two measurements that split tumors by class.
Start with four checks: size, gaps, ranges and classes. On the wines:
wine = load_wine(as_frame=True)
df = wine.frame
print(df.shape)
print(df.isna().sum().sum())This prints:
(178, 14)
013 features plus target, and .sum().sum() found no gaps anywhere. df.describe() gives each feature's range.
Last, the classes. normalize=True turns counts into shares:
shares = df["target"].value_counts(normalize=True)Always answering class_1 is right 40% of the time: the baseline a real model must beat.
Challenge
MediumRun the first look on load_breast_cancer, before any model learns from it. The starter loads it into df and reads a feature's name. Print:
- The size and the missing cells.
- The feature's min, max and median, from
describe(). - Each class's share as a whole percent, in class order.
- The baseline: the biggest share and its class.
For the iris flowers and the input petal length (cm), it prints:
Size: 150 samples, 4 features
Missing cells: 0
petal length (cm): 1.0 to 6.9, median 4.35
setosa: 33%
versicolor: 33%
virginica: 33%
Baseline: 33% by always answering setosaIris is perfectly balanced. Is the tissue data?
Try it yourself
from sklearn.datasets import load_breast_cancer
feature = input()
cancer = load_breast_cancer(as_frame=True)
df = cancer.frame
# 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