Files
learning_science/iris_flowers/README.md
T
2026-05-11 07:37:50 +01:00

58 lines
3.5 KiB
Markdown

# Iris Flowers Learning Space
## Goal
This repository serves as a personal learning sandbox for exploring data science concepts, machine learning algorithms, and Python data tools using the classic Iris dataset. The primary objective is to move beyond simple "hello world" examples and dive into the thought processes behind data analysis.
## Exploration & Findings
We started by visualizing the dataset to understand the underlying structure of the data. Using `visualize.py`, we generated several key plots to inform our modeling strategy.
### 1. Feature Distributions (Histograms)
**Observation**: The histograms show that different species have distinct distributions for certain features. notably, **Petal Length** shows a clear bimodal distribution, hinting that one species is significantly smaller than the others, while the other two are closer in size.
### 2. Feature Correlations (Heatmap)
**Observation**: There is a very strong positive correlation between **Petal Length** and **Petal Width** (correlation coefficient > 0.9).
**Data Science Perspective**:
- **Multicollinearity**: This indicates that these two features carry very similar information. In statistical models like Linear Regression, this can make coefficient estimates unstable.
- **Dimensionality Reduction**: This strong correlation suggests that techniques like **PCA (Principal Component Analysis)** would be highly effective here. We could likely compress these two features into a single principal component without losing significant information.
### 3. Pairwise Relationships (Pairplot)
**Observation**:
- **Iris-setosa** is linearly separable from the other two species. It forms a tight, distinct cluster, especially when looking at petal dimensions.
- **Iris-versicolor** and **Iris-virginica** show some overlap, particularly in sepal dimensions, but are reasonably distinguishable using petal dimensions.
**Data Science Perspective**:
- **Model Selection**: Since one class is easily separable and the others have some overlap, even simple linear classifiers (like Logistic Regression or Linear SVM) should achieve high accuracy (likely > 95%).
- **Complexity**: To perfectly separate Versicolor and Virginica, a model might need a non-linear decision boundary (like a Kernel SVM or Decision Tree), but the risk of overfitting to the small overlap area should be considered.
## Regression Analysis
We investigated the relationship between **Petal Length** and **Petal Width** using regression models.
### Linear Regression
We fitted a simple linear model ($y = mx + c$).
- **Result**: The model achieved an $R^2$ score of **0.9283**, confirming the strong linear relationship observed in the correlation heatmap.
- **Interpretation**: Petal width increases proportionally with petal length.
### Polynomial Regression
We tested if a "curvy" line would fit better by introducing polynomial terms (degrees 2 and 3).
- **Degree 2 (Quadratic)**: $R^2 = 0.9283$. No improvement over the linear model.
- **Degree 3 (Cubic)**: $R^2 = 0.9376$. A slight improvement, capturing some non-linearity at the extreme values of the data.
- **Conclusion**: While the cubic model is technically better, the added complexity yields only marginal gains. For most practical purposes, the simple linear model is sufficient and more interpretable.
## Usage
To reproduce the visualizations and see these patterns for yourself:
```bash
uv run python visualize.py
```
To run the regression models:
```bash
uv run python linear_regression.py
uv run python polynomial_regression.py
```
This will generate the plots in the `plots/` directory.