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.
supervised_learning_example.py
unsupervised_learning_example.py
File: supervised_learning_example.py
This script demonstrates a basic supervised learning task using a Decision Tree Classifier.
- 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
- Python 3.x
- NumPy
- scikit-learn
python supervised_learning_example.py
File: unsupervised_learning_example.py
This script showcases an unsupervised learning task using K-means clustering.
- Generates synthetic 2D data
- Applies K-means clustering to group the data into 3 clusters
- Visualizes the clustered data and centroids using matplotlib
- Python 3.x
- NumPy
- scikit-learn
- matplotlib
python unsupervised_learning_example.py
- Clone this repository:
git clone https://github.com/yourusername/machine-learning-examples.git
- Install the required packages:
pip install numpy scikit-learn matplotlib
- Run the examples as described in the Usage sections above.
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.