ML

Classification & Reinforcement Learning

A two-part machine learning project: supervised classification of network intrusions (KDD dataset) and reinforcement learning on a Gridworld environment, with several algorithms reimplemented from scratch.

  • Python
  • NumPy
  • Pandas
  • Matplotlib
  • Scikit-learn
Classification & Reinforcement Learning

Context

An academic project meant to demonstrate command of the main families of machine learning, from generative models to reinforcement learning. It combines a supervised part on real, heavily imbalanced data and a reinforcement part on a custom-built environment, under the constraint of implementing some algorithms without any dedicated library, to prove understanding of the underlying mechanisms rather than just their use.

Approach

Classification part: on the KDD network intrusion detection dataset (five classes: normal traffic, DoS, Probe, R2L and U2R), after preprocessing that combines scaling of numerical features and one-hot encoding of categorical ones, three families of methods are compared: a generative approach (Gaussian Naive Bayes), a discriminative approach (SVM) and an ensemble method (AdaBoost). The strong class imbalance is handled by choosing suitable metrics (F1, per-class recall and precision, confusion matrix) rather than accuracy alone, and hyperparameters are tuned through cross-validation. AdaBoost (the SAMME variant on decision stumps) is fully reimplemented by hand, then validated against scikit-learn's reference implementation.
Reinforcement part: on a stochastic 5x5 Gridworld (slippery moves, 80 percent in the intended direction and 10 percent skidding to each side, with a goal reward, a trap penalty and a step cost), two algorithms are written from scratch. With known transitions, dynamic programming (value iteration from the Bellman equations) yields the value function and the optimal policy. With unknown transitions, Q-learning learns through interaction with epsilon-greedy exploration. A sensitivity study on the discount factor, the learning rate and the exploration rate, together with a learning curve, accompanies the comparison of the two policies.

Results

Both from-scratch implementations are validated: the hand-written AdaBoost is checked against the scikit-learn reference, and the policy learned by Q-learning is compared with the one obtained through value iteration. The project shows an end-to-end grasp of a model's lifecycle (preprocessing, metric choice justified by the data, comparison of algorithm families, bias-variance reading) and of the foundations of reinforcement learning, beyond simply calling libraries.