/xgb_bio

Primary LanguagePython

Machine Learning Examples: Supervised vs Unsupervised Learning

This repository contains simple examples of supervised and unsupervised learning using Python and scikit-learn. These examples are designed to illustrate the basic concepts and differences between these two fundamental approaches in machine learning.

Contents

  1. supervised_learning_example.py
  2. unsupervised_learning_example.py

Supervised Learning Example

File: supervised_learning_example.py

This script demonstrates a basic supervised learning task using a Decision Tree Classifier.

Features:

  • Adds synthetic data for a binary classification problem
  • Splits data into training and testing sets
  • Trains a Decision Tree Classifier
  • Makes predictions on the test set
  • Calculates and prints the accuracy of the model

Requirements:

  • Python 3.x
  • NumPy
  • scikit-learn

Usage:

python supervised_learning_example.py

Unsupervised Learning Example

File: unsupervised_learning_example.py

This script showcases an unsupervised learning task using K-means clustering.

Features:

  • Generates synthetic 2D data
  • Applies K-means clustering to group the data into 3 clusters
  • Visualizes the clustered data and centroids using matplotlib

Requirements:

  • Python 3.x
  • NumPy
  • scikit-learn
  • matplotlib

Usage:

python unsupervised_learning_example.py

Getting Started

  1. Clone this repository:
    git clone https://github.com/yourusername/machine-learning-examples.git
    
  2. Install the required packages:
    pip install numpy scikit-learn matplotlib
    
  3. Run the examples as described in the Usage sections above.

Learning Outcomes

By studying and running these examples, you will:

  • Understand the basic difference between supervised and unsupervised learning
  • See how to implement simple machine learning models using scikit-learn
  • Learn how to generate synthetic data for testing machine learning algorithms
  • Gain insights into data splitting, model training, and evaluation in supervised learning
  • Explore data clustering and visualization in unsupervised learning

Feel free to modify the code, experiment with different parameters, or use your own datasets to deepen your understanding of these machine learning concepts.