Menu
CoddyTech

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.

Breast tissue samples as dots, mean concave points across and mean perimeter up: benign samples crowd the lower left, malignant ones spread up and to the right

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)
0

13 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)

Bars of the three wine classes: class_0 33%, class_1 40%, class_2 27%, with a dashed line at 40% marked always class_1: 40% right

Always answering class_1 is right 40% of the time: the baseline a real model must beat.

challenge icon

Challenge

Medium

Run 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:

  1. The size and the missing cells.
  2. The feature's min, max and median, from describe().
  3. Each class's share as a whole percent, in class order.
  4. 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 setosa

Iris 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
quiz iconTest yourself

This lesson includes a short quiz. Start the lesson to answer it and track your progress.

All lessons in Statistics for ML

Practice on your own: Online Python compiler