Binary Classification
Binary Classification is a type of classification where a machine learning model chooses between exactly two possible classes.
Binary Classification means choosing between two possible classes.
The model learns patterns from training examples and then predicts which of the two classes a new input belongs to.
What Does "Binary" Mean?
The word binary means there are exactly two possible choices.
The model must choose one of these two classes when it receives new data.
Simple Example — Pass or Fail
Suppose we want to predict whether a student will pass an exam based on how many hours they studied.
The model learns from these examples.
How Does Binary Classification Work?
The model first learns from training examples where the correct class is already known.
The important part is that the model has only two possible classes to choose from.
Example — Spam or Not Spam
Email spam detection is another common Binary Classification problem.
The model can look at information such as:
Binary Classification Can Use 0 and 1
Machine learning models often represent two classes using numerical labels such as 0 and 1.
Fail
Pass
The numbers are simply labels representing the categories.
Another problem could use the same idea differently:
Not Spam
Spam
Another Example — Fraud Detection
A bank may want to determine whether a transaction is fraudulent.
Because there are exactly two possible outcomes, this is another Binary Classification problem.
Binary vs Multi-Class Classification
The difference is simply the number of possible classes.
Example: Spam / Not Spam
Example: Cat / Dog / Horse
Simple Python Example
Here is a simple example using scikit-learn. The student result is represented using two labels: 0 and 1.
from sklearn.linear_model import LogisticRegression
X = [[1], [2], [3], [5], [6], [8]]
y = [0, 0, 0, 1, 1, 1]
model = LogisticRegression()
model.fit(X, y)
prediction = model.predict([[6]])
print(prediction)
In this example:
When the model predicts 1, we interpret that class as Pass.
Binary Classification means choosing between exactly two classes.
The model learns from labeled training examples and then predicts one of two possible categories for new data.