Distributions
Data Distributions and Visualization
Before building any model, you must understand your data visually. The distribution of features tells you which preprocessing is needed, what problems to expect, and whether the data can support a given task.
Why Distribution Matters
The same algorithm applied to the same task can fail or succeed depending on the data distribution. A linear classifier works perfectly on linearly separable data but cannot learn XOR. Normalization is critical for gradient-based learning but irrelevant for decision trees.
The Salmon vs Seabass Problem
A classic introductory dataset: classify fish on a conveyor belt as "salmon" or "seabass" based on two sensors — size (cm) and brightness (0–10).
One-dimensional view: each feature individually. Note that neither size alone nor brightness alone perfectly separates the species.
Two-dimensional view: combining both features allows a linear decision boundary to separate most samples.
Lesson
More features = richer feature space = more separation potential. But adding irrelevant features can hurt. Feature selection matters.
The Iris Dataset
UCI Machine Learning Repository: introduced by Ronald A. Fisher in 1936, this 150-sample dataset of three Iris species is a cornerstone ML benchmark.
| Feature | Unit | Range |
|---|---|---|
| Sepal length | cm | 4.3–7.9 |
| Sepal width | cm | 2.0–4.4 |
| Petal length | cm | 1.0–6.9 |
| Petal width | cm | 0.1–2.5 |
import pandas as pd
from sklearn.datasets import load_iris
# Carregar o conjunto de dados Iris
iris = load_iris()
# Transforma em DataFrame
df = pd.DataFrame(
data=iris.data,
columns=['sepal_l', 'sepal_w', 'petal_l', 'petal_w']
)
df['class'] = iris.target_names[iris.target]
# Imprime os dados
print(df)
Output:
sepal_l sepal_w petal_l petal_w class
0 5.1 3.5 1.4 0.2 setosa
1 4.9 3.0 1.4 0.2 setosa
2 4.7 3.2 1.3 0.2 setosa
3 4.6 3.1 1.5 0.2 setosa
4 5.0 3.6 1.4 0.2 setosa
.. ... ... ... ... ...
145 6.7 3.0 5.2 2.3 virginica
146 6.3 2.5 5.0 1.9 virginica
147 6.5 3.0 5.2 2.0 virginica
148 6.2 3.4 5.4 2.3 virginica
149 5.9 3.0 5.1 1.8 virginica
[150 rows x 5 columns]
Pairplot of the Iris dataset. Note: petal length vs. petal width clearly separates all three species. Sepal length vs. sepal width shows overlap — not all feature pairs are equally discriminative.
Common Distribution Shapes
