Machine learning uses data to build a model that can make predictions or decisions. A paradigm describes the type of learning signal available to the model.

Three Learning Paradigms

ParadigmLearning signalWhat the model learnsExample
Supervised learningInputs with known target valuesA mapping from inputs to targetsClassify a review as positive or negative
Unsupervised learningInputs without target labelsStructure or groups in the inputsGroup documents by similarity
Reinforcement learningRewards from actions in an environmentA policy for selecting actions over timeSelect actions that complete a robot task

Identify the learning signal

A supervised model receives the target during training. A clustering model receives the features. A reinforcement learning agent receives rewards from its actions.

Supervised Learning

Two common task types:

  • Classification predicts a category, such as positive or negative
  • Regression predicts a numerical value, such as a delivery time

The main components:

  • Features describe each input using numbers
  • Targets give the correct output for each training example
  • Model parameters are values learned during training
  • Loss measures prediction error and guides parameter updates
  • Evaluation metrics measure model performance on separate data

A low training loss shows that the model fits its training examples. Performance on new examples shows how well it generalises.

Text and Tabular Data

In a feature table, each row represents one example. Each column represents one feature. A review can become a row of word counts or TF-IDF values. The classifier then receives the same type of numerical input used for other tabular problems.

Logistic Regression and random forests are general machine learning models. The text representation makes them useful for NLP.

What Deep Learning Changes

Traditional NLP often uses features selected by a person, such as word counts, n-grams, or POS tags. Deep learning can learn useful representations and the prediction model together.

Dense representations can contain information about meaning. Sequence models can also use word order and context. Large-scale pretraining learns reusable representations from text.

Deep learning describes a model approach. The learning signal still determines whether a task uses supervised, unsupervised, or reinforcement learning.

Where reinforcement learning differs

An agent repeatedly observes a state, selects an action, and receives a reward and a new state. Learning then changes its policy to improve future rewards. The code examples below use fixed datasets.


Code

1. Prepare a small feature table

Each row represents a review. The columns count positive and negative words.

from sklearn.linear_model import LogisticRegression
from sklearn.cluster import KMeans
 
X = [
    [3, 0],
    [4, 0],
    [5, 0],
    [0, 3],
    [0, 4],
    [0, 5],
]
y = [1, 1, 1, 0, 0, 0]

The data structures:

  • X contains six rows and two features per row
  • y contains six target labels, where 1 means positive
  • X[0] and y[0] belong to the same review

2. Fit a supervised classifier

classifier = LogisticRegression()
classifier.fit(X, y)
print(classifier.predict([[2, 0], [0, 2]]))
[1 0]

fit(X, y) learns from both the features and the correct labels. predict(...) receives two new rows and returns one class per row. The extra brackets preserve the row-and-column structure.

3. Fit an unsupervised clustering model

clustering = KMeans(n_clusters=2, n_init=10, random_state=42)
groups = clustering.fit_predict(X)
 
print(groups[:3])
print(groups[3:])
print(groups[0] != groups[3])

The first three rows form one group. The last three rows form another group. The last line prints True.

fit_predict(X) receives the features and returns a cluster number for each row. Cluster numbers identify groups. Their meaning comes from inspection of the grouped data. The model receives no y labels in this operation. See the KMeans API.