Machine Learning · Topic 1 of 2
Machine Learning Algorithms, Types and Process
Learn what machine learning is, supervised, unsupervised, semi-supervised and reinforcement learning, the ML process, overfitting and precision and recall.
- 5 min
- Includes a diagram
- Supervised uses labels (classification and regression); unsupervised has no labels (clustering, dimensionality reduction).
- Semi-supervised mixes a few labels with many unlabeled samples; reinforcement learning learns from rewards.
- Process: collect, cleanse, select features, train, evaluate, deploy.
What it is
Machine learning (ML) lets a computer improve at a task by learning from data instead of following hand-written rules. Tom Mitchell's definition: a program learns from experience E for task T and performance measure P if its performance on T, measured by P, improves with E.
A machine learning algorithm takes training data and produces a model, a function that maps new inputs to predictions.
How it works
Rule-based versus machine learning
| Approach | How the logic is made | Good for |
|---|---|---|
| Rule-based | Humans write explicit if-then rules | Simple, stable logic that people can state |
| Machine learning | The algorithm finds the rules from labeled or unlabeled data | Complex patterns, such as image or speech recognition, that are hard to write as rules |
Use ML when the rules are too complex to write by hand, change over time, or must adapt to large amounts of data.
Types of machine learning
| Type | Training data | Typical tasks | Examples |
|---|---|---|---|
| Supervised learning | Labeled (input and correct output) | Classification (discrete label), regression (continuous value) | Spam filtering, house price prediction |
| Unsupervised learning | Unlabeled | Clustering, dimensionality reduction, association | Customer segmentation with k-means, PCA |
| Semi-supervised learning | A few labeled plus many unlabeled samples | Classification when labeling is costly | Labeling a large image set from a small labeled seed |
| Reinforcement learning | No labels; rewards from an environment | Learning a policy of actions | Game playing, robot control |
In reinforcement learning an agent observes a state, takes an action, and receives a reward. It learns a policy that maximizes total long-term reward.
Classification versus regression
Classification predicts a category, such as "cat" or "dog". Regression predicts a number, such as tomorrow's temperature. Both are supervised.
The machine learning process
| Step | What happens |
|---|---|
| 1. Data collection | Gather raw data from databases, logs, sensors or the web |
| 2. Data cleansing | Fix missing values, remove duplicates, correct errors and outliers |
| 3. Feature extraction and selection | Turn raw data into useful features; keep relevant ones, drop redundant ones |
| 4. Model training | Fit the algorithm to the training set |
| 5. Model evaluation | Measure performance on the validation and test sets |
| 6. Deployment and integration | Put the model into service and monitor it |
Data preparation usually takes most of the time in a real project. Poor data gives a poor model, whatever the algorithm.
Feature selection methods: filter methods score features by statistics such as correlation before training; wrapper methods test feature subsets by training the model; embedded methods select features during training, such as L1 regularization driving weights to zero.
Data sets

| Set | Role |
|---|---|
| Training set | Fits the model parameters |
| Validation set | Tunes hyperparameters and picks the best model |
| Test set | Final unbiased estimate of performance; used once at the end |
Generalization, overfitting and underfitting
Generalization is how well the model performs on new data. The gap between training error and test error shows how well it generalizes.
| Problem | Training error | Test error | Cause | Fixes |
|---|---|---|---|---|
| Underfitting | High | High | Model too simple (high bias) | More features, more complex model |
| Overfitting | Low | High | Model too complex or too little data (high variance) | More data, regularization, simpler model, early stopping |
Bias is error from wrong assumptions; variance is error from sensitivity to the particular training set. Raising model complexity lowers bias but raises variance, so the goal is a balance.
Evaluation metrics
For classification, the confusion matrix counts true positives (TP), false positives (FP), false negatives (FN) and true negatives (TN).
| Metric | Formula | Meaning |
|---|---|---|
| Accuracy | (TP + TN) / all | Share of all predictions that are right |
| Precision | TP / (TP + FP) | Of predicted positives, how many are real |
| Recall | TP / (TP + FN) | Of real positives, how many were found |
| F1 score | 2 x P x R / (P + R) | Harmonic mean of precision and recall |
For regression, common metrics are MSE (mean squared error), MAE (mean absolute error) and R squared.
A worked example
A fraud model is tested on 100 transactions: TP = 40, FP = 10, FN = 20, TN = 30. Accuracy = (40 + 30) / 100 = 0.70.
Precision = 40 / (40 + 10) = 0.80 and recall = 40 / (40 + 20) = 0.667. F1 = 2 x 0.80 x 0.667 / (0.80 + 0.667) = 1.067 / 1.467 = 0.727.
Recall is low, so the model misses a third of fraud cases. For fraud, recall usually matters more than precision.
How the exam asks about this
- "Which type of learning groups customers with no labels into segments?" → Unsupervised learning (clustering).
- "A model has low training error and high test error. What is the problem?" → Overfitting.
- "Which data set should be used only once, for the final performance estimate?" → The test set.
What to remember for the exam
- Supervised uses labels (classification and regression); unsupervised has no labels (clustering, dimensionality reduction).
- Semi-supervised mixes a few labels with many unlabeled samples; reinforcement learning learns from rewards.
- Process: collect, cleanse, select features, train, evaluate, deploy.
- Underfitting means high bias; overfitting means high variance.
- Precision = TP / (TP + FP), recall = TP / (TP + FN), F1 is their harmonic mean.
Do not tune hyperparameters on the test set. Use the validation set or cross-validation; otherwise the test score is no longer an unbiased estimate.
Common mistakes
Calling regression unsupervised. Regression needs a known target value for each training sample, so it is supervised learning.
Confusing precision and recall. Precision divides by predicted positives (TP + FP). Recall divides by actual positives (TP + FN).
Treating high accuracy as a good model. On imbalanced data, a model that always says "not fraud" can score high accuracy while finding no fraud at all.
Check yourself
What separates semi-supervised learning from supervised learning?
Semi-supervised learning trains on a small set of labeled samples plus many unlabeled ones. Supervised learning uses labeled samples only.
What is the validation set used for?
It is used to tune hyperparameters and choose between models, keeping the test set for the final unbiased check.
A model has TP = 30, FP = 30, FN = 10. What is its precision?
Precision = 30 / (30 + 30) = 0.5, so half of its positive predictions are correct.
Topic 1 of 2 in Machine Learning
Test yourself on Machine Learning
The full Huawei HCIA-AI H13-311 question bank has 600 questions, with timed practice exams and an explanation for every answer.
This study guide is independent and is not affiliated with, endorsed by, or sponsored by Huawei. Vendor names, certification names and exam codes are trademarks of their respective owners and are used for identification only.