Introduction:
Machine learning problems are grouped into categories based on the type of data being used and the structure of the output expected.
There are several categories in Machine Learning
- Supervised Learning: The model learns from labeled training data to predict specific targets
- Unsupervised Learning: The model analyzes unlabeled data to discover hidden patterns and structures.
- Reinforcement Learning: An agent learns to make decisions by interacting with an environment to maximize a cumulative reward.
Supervised Learning vs Unsupervised Learning
The two most fundamental categories are supervised learning and unsupervised learning. Understanding the difference determines which algorithms and evaluation methods you should use when building and evaluating your model.
Supervised learning:
- The model learns the relationships between inputs and outputs so it can predict labels for new, unseen data. Every training subset includes both the input features (X) and the correct output (y = label).
Real-world application:
Credit risk scoring and medical diagnosis from labeled scans.
Think of it like studying with an answer key: you look at each question, check the answer, and learn from the pattern.
Types of Supervised Learning Models:
Classification - predicting a category or class: Is an email spam or not spam?
Regression - predicting a continuous number: What will the price of a house be?
Example: Classification with Scikit-learn:
from sklearn.datasets import load_iris
from sklearn.model_selection import train_test_split
from sklearn.tree import DecisionTreeClassifier
from sklearn.metrics import accuracy_score```
{% endraw %}
data_iris = load_iris()
X, y = data_iris.data, data_iris.target # y = known species labels
X_train, X_test, y_train, y_test = train_test_split(
X, y, test_size=0.2, random_state=42)
model = DecisionTreeClassifier(random_state=42)
model.fit(X_train, y_train) # learns from labeled examples
predictions = model.predict(X_test)
print("Accuracy:", accuracy_score(y_test, predictions))
{% raw %}
Here, y (the flower species) is known during training; this is what makes it supervised.
Supervised Algorithms include:
- Linear Regression, Logistic Regression
- Decision Trees, Random Forests
- Support Vector Machines (SVM)
- k-Nearest Neighbors (k-NN)
- Neural Networks (RNN'S and CNN'S)
Some of the Model Evaluation Metrics include:
Classification: accuracy, precision, recall, F1-score.
Regression: Mean Absolute error(MAE), mean squared error (MSE), R² score.
Unsupervised Machine Learning:
In unsupervised learning, the data has no labels. The model’s job is to find hidden structure, patterns, or groupings in the data on its own, without being told the “correct” answer.
Real-world application:
Market segmentation, fraud detection (finding unusual patterns without predefined “fraud” labels).
Think of it like being handed a pile of unsorted photos and asked to group similar ones together — no one tells you the categories in advance.
Types of Unsupervised Learning:
Clustering: grouping of similar data points that have similar characteristics, e.g grouping customers by purchasing behavior.
Dimensionality Reduction — simplifying data while preserving important patterns, e.g compressing hundreds of features into two for visualization.
Unsupervised Algorithms:
- _K-Means Clustering: _ Groups data into a set number of clusters by assigning each observed data point to the nearest cluster centroid (the best n_clusters is estimated using methods such as the silhouette score or elbow method).
Example: Clustering with Scikit-learn:
from sklearn.datasets import load_iris
from sklearn.cluster import KMeans
data = load_iris()
X = data.data # note: we ignore datatarget here
kmeans = KMeans(n_clusters=3, random_state=42, n_init=10)
kmeans.fit(X)
print("Cluster assignments:", kmeans.labels_[:10])
Notice that we never gave the model the true species labels. It grouped the flowers purely based on similarities in their measurements.
- Hierarchical Clustering: Organizes data into nested clusters arranged in levels, represented as a tree-like dendrogram.
DBSCAN:
Groups closely packed data points into clusters based on density while identifying isolated points as noise or outliers.Principal Component Analysis (PCA): Reduces the number of features in a dataset by transforming them into a smaller set of components that retain most of the important variation in the data.
Summary
The main difference between supervised and unsupervised learning is that, when dealing with Labelled data( Data where the predicted value already exists in the data) and you want to train a model to predict an outcome using labelled data, you use supervised learning.
If you want the data to give you answers and to find hidden structures and relationships in data, then you use unsupervised learning algorithms.
Many real-world systems combine both machine learning algorithms, for example, using unsupervised clustering and dimensionality reduction to explore data before building a supervised model.

Top comments (0)