You are viewing a free preview of this lesson.
Subscribe to unlock all 10 lessons in this course and every other course on LearningBro.
Machine learning (ML) is a branch of artificial intelligence that enables computers to learn from data and make decisions or predictions without being explicitly programmed for every scenario. Instead of writing rules by hand, you provide the machine with examples and let it discover the underlying patterns.
At its core, machine learning is about learning from data. A traditional programme follows explicit instructions written by a developer. A machine learning model, by contrast, is given data and a learning algorithm — the algorithm finds patterns in the data and encodes them into a model that can make predictions on new, unseen data.
| Traditional Programming | Machine Learning |
|---|---|
| Input: Data + Rules | Input: Data + Expected Output |
| Output: Results | Output: Rules (a model) |
| Developer writes the logic | Algorithm discovers the logic |
| Works well for well-defined problems | Works well for complex, pattern-rich problems |
Suppose you want to classify emails as spam or not-spam:
Machine learning is broadly divided into three categories:
The algorithm learns from labelled data — each training example has an input and a known correct output. The goal is to learn a mapping from inputs to outputs.
| Task | Description | Example |
|---|---|---|
| Classification | Predict a discrete category | Email spam detection, image recognition |
| Regression | Predict a continuous value | House price prediction, temperature forecasting |
The algorithm learns from unlabelled data — there are no correct answers provided. The goal is to discover hidden structure in the data.
| Task | Description | Example |
|---|---|---|
| Clustering | Group similar data points together | Customer segmentation, document grouping |
| Dimensionality Reduction | Reduce the number of features while preserving structure | Data visualisation, noise removal |
The algorithm learns by interacting with an environment — it takes actions, receives rewards or penalties, and learns to maximise cumulative reward over time.
| Concept | Description |
|---|---|
| Agent | The learner that takes actions |
| Environment | The world the agent interacts with |
| Reward | Feedback signal after each action |
| Policy | Strategy the agent learns to follow |
Examples: game-playing AI (AlphaGo), robotics, autonomous driving, recommendation systems.
| Term | Definition |
|---|---|
| Feature | An individual measurable property of the data (e.g., age, height, income) |
| Label / Target | The variable you want to predict (e.g., price, category) |
| Training Set | Data used to train the model |
| Test Set | Data held out to evaluate the model's performance on unseen data |
| Model | The mathematical representation learned from data |
| Hyperparameter | A setting configured before training (e.g., learning rate, number of trees) |
| Overfitting | Model memorises training data and performs poorly on new data |
| Underfitting | Model is too simple to capture the patterns in the data |
| Generalisation | The model's ability to perform well on new, unseen data |
Every machine learning project follows a similar workflow:
| Library | Purpose |
|---|---|
NumPy | Numerical computing and array operations |
Pandas | Data manipulation and analysis |
Matplotlib / Seaborn | Data visualisation |
Scikit-Learn | Classical machine learning algorithms, preprocessing, evaluation |
TensorFlow | Deep learning framework (Google) |
PyTorch | Deep learning framework (Meta) |
XGBoost / LightGBM | Gradient boosting libraries for tabular data |
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
# Load a built-in dataset
iris = load_iris()
X, y = iris.data, iris.target
# Split into training and test sets
X_train, X_test, y_train, y_test = train_test_split(
X, y, test_size=0.2, random_state=42
)
# Create and train a model
model = DecisionTreeClassifier(random_state=42)
model.fit(X_train, y_train)
# Make predictions and evaluate
predictions = model.predict(X_test)
print(f"Accuracy: {accuracy_score(y_test, predictions):.2f}")
Machine learning is not always the right tool. Consider ML when:
Avoid ML when:
Machine learning enables computers to learn from data rather than following explicit instructions. It is broadly divided into supervised learning (learning from labelled data), unsupervised learning (discovering hidden structure), and reinforcement learning (learning through interaction). The ML pipeline involves defining a problem, collecting and preparing data, training and evaluating a model, and deploying it to production. Python and its rich ecosystem — Scikit-Learn, TensorFlow, PyTorch — make machine learning accessible to beginners and experts alike.