Skip to content

Repository files navigation

Machine Learning Lab 5 — Clustering

Lab assignment for the Machine Learning course at Universidad Carlos III de Madrid. Unsupervised learning techniques applied to state and action space data from a control environment (pendulum-like system with x/y position and angular velocity).

UC3M · Robotics Engineering · 2024


Exercises

Exercise 1 — K-Means Clustering (exercise11.py, exercise12.py, exercise13.py)

K-Means applied to both state space (x, y, angular velocity) and action space data. Parameters tuned via elbow method and silhouette analysis.

Space Best k Silhouette Score
State 8 0.387
Action 4 0.447

Exercise 2 — Hierarchical Clustering (exercise21.py, exercise22.py, exercise23.py)

Agglomerative clustering with ward, complete and average linkage methods. Best parameters selected via silhouette score.

Space Linkage Best k Silhouette Score
State average 3 0.332
Action ward 5 0.423

Exercise 3 — PCA (exercise31.py, exercise32.py)

Dimensionality reduction on the state space. With 3 components, explained variance is distributed as PC1: 38.6% / PC2: 34.0% / PC3: 27.4% — all 3 are needed to reach 95%. 2D vs 3D comparison shows the spiral structure is preserved after reduction.


Data

File Description
states_data.csv State space: x position, y position, angular velocity
actions_data.csv Action space: control input values

Requirements

pip install numpy pandas matplotlib scikit-learn scipy seaborn

Usage

Each script is self-contained. Run any exercise independently:

python exercise11.py   # K-Means on state space
python exercise12.py   # K-Means on action space
python exercise13.py   # Cluster visualization
python exercise21.py   # Hierarchical clustering on state space
python exercise22.py   # Hierarchical clustering on action space
python exercise23.py   # Dendrogram visualization
python exercise31.py   # PCA variance analysis
python exercise32.py   # PCA 2D/3D comparison

Make sure states_data.csv and actions_data.csv are in the same directory as the scripts.


Authors

Jorge Serrano Navas · Lucas Kohley Aguilar
UC3M · 2024

About

lab5 de Aprendizaje Automático

Resources

Stars

0 stars

Watchers

1 watching

Forks

Releases

Packages

Contributors

Languages