Skillversitas

Types of Machine Learning

Machine Learning has several main categories based on how the model learns from data. Understanding these differences is important for choosing the right approach to solve a problem.

Supervised Learning

Supervised learning is a technique where the model learns from data that has already been labeled (labeled data). Every data point has an input and an expected output.

Classification

Classification is used to predict a category or label.
- Binary Classification: Spam vs Not Spam, Fraud vs Legit
- Multi-class Classification: Classifying flower species (Iris, Rose, Tulip)

Regression

Regression is used to predict a continuous value.
- Predicting house prices based on size and location
- Predicting tomorrow's temperature based on historical data

from sklearn.model_selection import train_test_split
from sklearn.linear_model import LinearRegression
from sklearn.datasets import make_regression

X, y = make_regression(n_samples=100, n_features=1, noise=10, random_state=42)
X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.2)

model = LinearRegression()
model.fit(X_train, y_train)
score = model.score(X_test, y_test)
print(f"R² Score: {score:.4f}")

Unsupervised Learning

Unsupervised learning works with data that has no labels. The goal is to find patterns or hidden structure in the data.

Clustering

Grouping data based on similarity.
- K-Means: Grouping customers based on shopping behavior
- Hierarchical Clustering: A hierarchy tree of data groups

Dimensionality Reduction

Reducing the number of features without losing important information.
- PCA (Principal Component Analysis)
- t-SNE for visualizing high-dimensional data

from sklearn.datasets import load_iris
from sklearn.cluster import KMeans

iris = load_iris()
X = iris.data

kmeans = KMeans(n_clusters=3, random_state=42, n_init=10)
kmeans.fit(X)
labels = kmeans.labels_
print(f"Labels found: {labels[:10]}")

Reinforcement Learning

Reinforcement learning involves an agent that learns to make decisions through interaction with an environment. The agent receives a reward or punishment based on its actions.

Examples of applications:
- AlphaGo: Defeating the world Go champion
- Robotics: A robot learning to walk
- Game AI: Game bots that learn to play
- Trading: Trading bots that optimize strategies

State → Action → Reward → New State → Repeat

Semi-Supervised Learning

This approach uses a combination of labeled and unlabeled data. It is useful when labeling data is expensive or time-consuming.

Self-Supervised Learning

The model creates labels from the data itself. Example: GPT and BERT, which are trained by predicting the next word in a sentence.

When to Use Each One?

Type Data Example Problem Algorithm
Supervised Labeled Classification, Regression SVM, Random Forest, Neural Network
Unsupervised Unlabeled Clustering, Dimensionality Reduction K-Means, PCA
Reinforcement Reward/Punishment Games, Robotics Q-Learning, DQN
Semi-supervised Partially labeled Text classification Label Propagation

Choosing the right type of ML depends on the data available and the kind of problem you want to solve.

In the next chapter, we will start with one of the most fundamental algorithms in supervised learning: Linear Regression.

Next: Linear Regression →