1. What Is Machine Learning?
Machine learning (ML) is an important branch of artificial intelligence (AI).
It studies how to enable computers to learn patterns from data and use the learned patterns to perform tasks such as prediction, classification, and decision-making, rather than relying entirely on fixed rules written by humans.
Traditional programming usually involves developers explicitly writing the processing logic:
- Input data.
- Execute predefined rules.
- Output the computed result.
Machine learning takes a different approach:
- Provide training data.
- Design models and learning algorithms.
- Automatically adjust model parameters through training.
- Enable the model to learn statistical patterns in the data.
- Use the trained model to process new data.
The core difference between the two is this: traditional programming mainly relies on humans writing rules, whereas machine learning learns rules from data and algorithms.
1.1 A Simple Example: Spam Detection
Suppose you need to develop a spam detection system.
Traditional programming might use manually defined rules:
- If the email subject contains "free to claim", mark it as spam.
- If the email body contains many advertising links, mark it as spam.
- If the sender is on a blacklist, mark it as spam.
This approach has obvious limitations:
- Rules must be maintained manually.
- New types of spam may bypass existing rules.
- Rules may conflict with one another.
- It is difficult to cover complex language expressions and behavioral patterns.
With machine learning, you can collect a large amount of labeled email data:
- Legitimate email.
- Spam email.
Through training, the model learns the relationship between email content, sender features, link features, and categories.
After training is complete, when a new email is input, the model can predict whether it is legitimate email or spam.
1.2 The Basic Process of Machine Learning
flowchart TB
A["Collect training data"] --> B["Data preprocessing"]
B --> C["Select model and algorithm"]
C --> D["Model training"]
D --> E["Learn model parameters"]
E --> F["Model evaluation"]
F --> G{"Does performance meet requirements?"}
G -->|"No"| H["Adjust model or training strategy"]
H --> D
G -->|"Yes"| I["Deploy model"]
I --> J["Input new data"]
J --> K["Model prediction"]
style A fill:#DCEFE5,stroke:#4F8B70,color:#24563F
style B fill:#F5F8F4,stroke:#B5CBBB,color:#40594A
style C fill:#EAF3EC,stroke:#83A995,color:#315D49
style D fill:#DCEFE5,stroke:#4F8B70,color:#24563F
style E fill:#EAF3EC,stroke:#83A995,color:#315D49
style F fill:#F5F8F4,stroke:#B5CBBB,color:#40594A
style G fill:#F7F4E8,stroke:#C7B77A,color:#675A2D
style H fill:#F5F8F4,stroke:#B5CBBB,color:#40594A
style I fill:#E5F0E9,stroke:#83A995,color:#315D49
style J fill:#F5F8F4,stroke:#B5CBBB,color:#40594A
style K fill:#E5F0E9,stroke:#83A995,color:#315D49
2. Core Components of Machine Learning
Machine learning is not a single algorithm but a technical system composed jointly of data, models, objective functions, and optimization algorithms.
2.1 Data
Data is the foundation of machine learning.
Models learn patterns from data, and data quality directly affects the model's training performance and generalization ability.
Common data types:
| Data type | Example |
|---|---|
| Numerical data | Age, price, temperature, sales |
| Categorical data | Gender, product category, region |
| Text data | Reviews, emails, news |
| Image data | Faces, product images, medical images |
| Audio data | Speech, music, environmental sounds |
| Time series | Stock prices, sensor data, traffic metrics |
In machine learning, raw data usually needs to be converted into feature representations that the model can process.
For example, when predicting house prices, you can use:
- House area.
- Number of rooms.
- Year built.
- Geographic location.
- Surrounding amenities.
This information can serve as the model's input features.
2.2 Features
Features are information used to describe the attributes of a sample.
Suppose there is a house price prediction task:
where:
- x_1: house area.
- x_2: number of rooms.
- x_3: year built.
- x_4: distance to the subway.
The model predicts house prices based on these features:
Where:
- X: input features.
- \theta: model parameters.
- \hat{y}: model prediction result.
Traditional machine learning usually requires a considerable amount of manual feature engineering, whereas deep learning can automatically learn more complex feature representations through multi-layer networks.
But this does not mean that deep learning requires no data processing or feature design at all.
2.3 Model
A model is a computational structure that expresses patterns in data mathematically.
For example, a linear regression model:
Where:
- x: input.
- w: weight.
- b: bias.
- \hat{y}: prediction result.
The model parameters determine how exactly the model processes the input data.
Different machine learning algorithms have different model structures and learning mechanisms.
Common models include:
- Linear regression.
- Logistic regression.
- Decision tree.
- Random forest.
- Support vector machine.
- K-Means.
- Neural network.
2.4 Loss Function
The loss function is used to measure the difference between the model's prediction and the true result.
For example, mean squared error is commonly used in regression tasks:
Where:
- N: number of samples.
- \hat{y}_i: model predicted value.
- y_i: true value.
A core goal of model training is to find suitable parameters that make the loss function as small as possible:
2.5 Optimization Algorithm
The optimization algorithm is responsible for adjusting the model parameters according to how the loss function changes.
Common algorithms:
- Gradient Descent.
- Stochastic Gradient Descent (SGD).
- Momentum.
- RMSProp.
- Adam.
Taking gradient descent as an example:
Where:
- \theta_t: current model parameters.
- \eta: learning rate.
- \nabla L(\theta_t): gradient of the loss function with respect to the parameters.
The optimization algorithm uses gradient information to gradually adjust the model parameters, so that the model's loss on the training data decreases.
3. How Does Machine Learning Work?
From a technical standpoint, the machine learning training process can be divided into several stages: data preparation, model construction, model training, model evaluation, and model inference.
3.1 Data Preparation
First, collect data related to the target task.
For example, to build a house price prediction model, you need to collect:
- House area.
- House location.
- Number of rooms.
- Age of the house.
- Historical transaction prices.
Raw data usually needs to be processed:
| Data Processing | Purpose |
|---|---|
| Data cleaning | Handle erroneous and duplicate data |
| Missing value handling | Fill in or delete missing records |
| Outlier handling | Identify obviously anomalous data |
| Feature encoding | Convert categorical information into numerical representations |
| Feature scaling | Adjust the numerical ranges of different features |
| Feature selection | Keep features relevant to the target task |
The goal of data preprocessing is to improve data quality so that the model can learn effectively.
3.2 Model Training
The core of model training is to use training data to adjust parameters.
Taking supervised learning as an example, training data usually contains inputs and corresponding target values:
The model computes a prediction result based on the input x_i:
Then compute the loss from the predicted values and the true values:
Parameters are continuously updated through an optimization algorithm.
3.3 Forward Propagation and Backpropagation
For neural networks, the training process usually consists of two core computational stages.
Forward Propagation
Data enters the network from the input layer, passes through multiple computational layers, and finally produces a prediction.
Backpropagation
Based on the loss function, the chain rule is used to compute the gradients of the parameters in each layer.
flowchart TB
A["Input training data"] --> B["Forward propagation"]
B --> C["Obtain model prediction"]
C --> D["Compute loss function"]
D --> E["Backpropagation"]
E --> F["Compute parameter gradients"]
F --> G["Optimizer updates parameters"]
G --> H{"Continue training?"}
H -->|"Yes"| B
H -->|"No"| I["Obtain the trained model"]
style A fill:#DCEFE5,stroke:#4F8B70,color:#24563F
style B fill:#EAF3EC,stroke:#83A995,color:#315D49
style C fill:#F5F8F4,stroke:#B5CBBB,color:#40594A
style D fill:#EAF3EC,stroke:#83A995,color:#315D49
style E fill:#DCEFE5,stroke:#4F8B70,color:#24563F
style F fill:#F5F8F4,stroke:#B5CBBB,color:#40594A
style G fill:#EAF3EC,stroke:#83A995,color:#315D49
style H fill:#F7F4E8,stroke:#C7B77A,color:#675A2D
style I fill:#E5F0E9,stroke:#83A995,color:#315D49
Note the following:
- Forward propagation is responsible for computing the prediction.
- Backpropagation is responsible for computing the gradients.
- The optimizer is responsible for updating the parameters.
These three concepts are interrelated, but they are not the same thing.
3.4 Model Evaluation
Once model training is complete, it is necessary to determine whether the model has good predictive capability on data it has not been trained on.
Data is typically split into:
| Dataset | Purpose |
|---|---|
| Training Set | Used for learning model parameters |
| Validation Set | Used for model selection and hyperparameter tuning |
| Test Set | Used for final performance evaluation |
Common evaluation metrics:
| Task Type | Evaluation Metrics |
|---|---|
| Classification | Accuracy, Precision, Recall, F1, AUC |
| Regression | MAE, MSE, RMSE, R² |
| Clustering | Silhouette Score, Davies-Bouldin Index |
| Ranking | NDCG, MAP, MRR |
Different tasks require the selection of appropriate metrics; model quality cannot be judged on accuracy alone.
3.5 Model Inference
Once model training is complete, it can be used to process new input data.
This stage is called inference.
For example:
- Input an email and predict whether it is spam.
- Input an image and identify the objects in it.
- Input user behavior and predict which products the user is likely to purchase.
- Input house features and predict the house price.
Differences between training and inference:
| Comparison Item | Training | Inference |
|---|---|---|
| Primary goal | Learn model parameters | Use already-trained parameters |
| Whether parameters are updated | Usually yes | Usually no |
| Whether loss backpropagation is needed | Required during training | Generally not required |
| Main computation | Forward propagation, backpropagation, parameter updates | Forward computation |
| Resource requirements | Usually higher | Depends on model size and deployment method |
IV. The Three Main Learning Paradigms of Machine Learning
Based on differences in training data and feedback signals, machine learning is generally divided into three major categories:
- Supervised Learning.
- Unsupervised Learning.
- Reinforcement Learning.
In addition, there are other important paradigms such as semi-supervised learning and self-supervised learning.
4.1 Supervised Learning
Supervised learning uses labeled data to train models.
Each training example usually contains:
Where:
- x_i: input features.
- y_i: the corresponding true label or target value.
The model learns the mapping relationship between inputs and targets:
Supervised learning mainly includes two types of tasks.
Classification
Predict which class a sample belongs to.
For example:
- Spam email detection.
- Image classification.
- Customer churn prediction.
- Fraudulent transaction detection.
Regression
Predict a continuous numerical value.
For example:
- House price prediction.
- Sales forecasting.
- Temperature prediction.
- Equipment lifetime prediction.
Common supervised learning algorithms:
- Linear regression.
- Logistic regression.
- Decision tree.
- Random forest.
- Support vector machine.
- K-nearest neighbors.
- XGBoost.
- Neural networks.
4.2 Unsupervised Learning
Unsupervised learning uses data without explicit target labels, allowing the model to discover structures, distributions, or latent relationships in the data.
Its core goal is not to directly predict known labels, but to uncover patterns in the data itself.
Common tasks include:
Clustering
Group similar data samples into the same cluster.
For example:
- User segmentation.
- Product categorization.
- Customer behavior analysis.
- Discovery of anomalous groups.
Dimensionality Reduction
Map high-dimensional data into a lower-dimensional space while preserving important information as much as possible.
For example:
- PCA (principal component analysis).
- t-SNE.
- UMAP.
Anomaly Detection
Identify data that is significantly different from most normal samples.
For example:
- Financial fraud detection.
- Network intrusion detection.
- Industrial equipment anomaly monitoring.
Common unsupervised learning algorithms:
- K-Means.
- DBSCAN.
- Hierarchical clustering.
- PCA.
- Gaussian mixture model (GMM).
- Autoencoder.
4.3 Reinforcement Learning
Reinforcement learning studies how an agent learns behavioral policies that can obtain long-term returns through interaction with an environment.
Core components:
| Concept | Meaning |
|---|---|
| Agent | The agent responsible for choosing actions |
| Environment | The environment the agent interacts with |
| State | Current state |
| Action | The action taken by the agent |
| Reward | Reward feedback from the environment |
| Policy | The policy that determines how actions are chosen |
| Return | Accumulated return over a period of time |
The basic process of reinforcement learning:
flowchart TB
A["Agent"] -->|"Take action"| B["Environment"]
B -->|"Return state"| A
B -->|"Return reward"| A
A --> C["Update policy"]
C --> A
style A fill:#DCEFE5,stroke:#4F8B70,color:#24563F
style B fill:#EAF3EC,stroke:#83A995,color:#315D49
style C fill:#F5F8F4,stroke:#B5CBBB,color:#40594A
Reinforcement learning typically aims to maximize the expected cumulative return:
Where:
- \pi: policy.
- r_t: reward obtained at time t.
- \gamma: discount factor.
- T: task end time or planning horizon.
Typical applications:
- Game agents.
- Robot control.
- Autonomous driving decision research.
- Resource scheduling.
- Large model alignment and policy optimization.
4.4 Semi-supervised Learning
Semi-supervised learning uses both a small amount of labeled data and a large amount of unlabeled data.
Its basic idea is:
- Use a small amount of labeled data to provide explicit supervisory signals.
- Use large amounts of unlabeled data to learn the data distribution and structure.
- Improve model performance through methods such as pseudo-labeling and consistency regularization.
It is suitable for scenarios where annotation costs are high and unlabeled data is abundant.
For example:
- Medical image classification.
- Industrial defect detection.
- Speech recognition.
- Image recognition.
4.5 Self-supervised Learning
Self-supervised learning constructs training objectives from the data itself and does not rely on manually annotated labels for each sample.
For example, in a language model:
- Input a piece of text.
- Use the preceding Tokens as context.
- Predict the next Token.
- Compute the training loss based on the true Token.
Typical language model objective:
Where:
- x_t: current Token.
- x_{<t}: context before the current Token.
- P_\theta: conditional probability given by the model.
Self-supervised learning has become an important technical approach for large-scale pretrained models.
4.6 Comparison of Different Learning Paradigms
| Learning Paradigm | Training Data | Core Objective | Typical Tasks |
|---|---|---|---|
| Supervised Learning | Labeled Data | Learn mapping from inputs to targets | Classification, Regression |
| Unsupervised Learning | Unlabeled Data | Discover data structures and patterns | Clustering, Dimensionality Reduction |
| Reinforcement Learning | Environment interaction feedback | Learn the policy that maximizes long-term return | Control, Decision-making |
| Semi-supervised Learning | Small amount labeled, large amount unlabeled | Use unlabeled data to improve learning | Image Classification |
| Self-supervised Learning | Construct supervisory signals from data | Learn general representations or predictive ability | Large Model Pretraining |
These paradigms are not completely mutually exclusive. Practical systems can combine multiple learning methods.
5. Mainstream Machine Learning Algorithms
Machine learning algorithms can be categorized in many ways. Based on model structure and learning mechanism, we can examine the following mainstream algorithm categories.
5.1 Linear Regression
Linear regression is used to predict continuous numerical values.
Basic model:
Matrix form:
A common loss function is mean squared error:
Characteristics:
- Simple model structure.
- Parameters have a certain degree of interpretability.
- High training and prediction efficiency.
- Suitable for tasks with approximately linear relationships.
Limitations:
- Limited expressive power for complex nonlinear relationships.
- May be sensitive to outliers.
- Relationships between features may require manual handling.
5.2 Logistic Regression
Logistic regression is mainly used for classification tasks.
Although its name contains “regression,” it is usually used as a classification model.
Binary logistic regression:
where the Sigmoid function is:
It maps the linear calculation result to a value between 0 and 1 as the predicted probability of the positive class.
Characteristics:
- Relatively simple model structure.
- Can output class probabilities.
- Good interpretability.
- Often used as a baseline model for classification tasks.
5.3 Decision Tree
Decision trees perform classification or regression through a series of condition checks.
For example:
- Is age greater than 30?
- Is income above a certain threshold?
- Is there a certain type of purchasing behavior?
Each check splits the data into different branches, ultimately reaching a leaf node to obtain the prediction result.
Common splitting criteria:
- Information gain.
- Information gain ratio.
- Gini index.
Characteristics:
- Intuitive structure.
- Easy to interpret.
- Can handle non-linear relationships.
- Generally insensitive to feature scaling.
Limitations:
- A single tree is prone to overfitting.
- It may be fairly sensitive to changes in the training data.
- Depth and pruning strategies need to be controlled reasonably.
5.4 Random Forest
Random Forest is an ensemble learning algorithm based on the idea of Bagging.
It trains multiple decision trees and combines their prediction results.
For classification tasks, voting is usually used; for regression tasks, averaging is usually used.
Core mechanism:
- Sample from the training data with replacement.
- Each tree uses a randomly selected subset of features for node splitting.
- Multiple trees are trained independently.
- Aggregate the prediction results of all trees.
Characteristics:
- Can handle relatively complex non-linear relationships.
- Usually more stable than a single decision tree.
- Can reduce the variance of a single tree.
- Can provide analytical information such as feature importance.
5.5 Support Vector Machine (SVM)
SVM is mainly used for classification, and can also be extended to regression.
Its core idea is to find a decision boundary that can separate the classes and to maximize the classification margin as much as possible.
Key concepts:
- Hyperplane.
- Support Vector.
- Margin.
- Kernel.
For the linearly separable case, the decision boundary can be expressed as:
SVM finds a suitable decision boundary by optimizing the margin.
With the use of kernel functions, it can also handle non-linear classification problems.
Characteristics:
- Performs well on small and medium-sized datasets.
- Can handle high-dimensional features.
- The kernel trick can extend its non-linear modeling capability.
Limitations:
- Training on large-scale data can be costly.
- The choice of kernel function and hyperparameters is relatively important.
- Relatively sensitive to feature scaling.
5.6 K-Means
K-Means is a classic unsupervised clustering algorithm.
It aims to partition the data into K clusters, so that each sample is as close as possible to the center of the cluster it belongs to.
Optimization objective:
Where:
- K: the number of clusters.
- C_k: the kth cluster.
- \mu_k: the center of the kth cluster.
Basic steps:
- Initialize K cluster centers.
- Assign each sample to the nearest center.
- Recalculate the centers based on the samples within each cluster.
- Repeat the assignment and update.
- Until the convergence condition is met.
Characteristics:
- Simple algorithm.
- Relatively high computational efficiency.
- Suitable for discovering data with a certain clustering structure.
Limitations:
- K needs to be specified in advance.
- Relatively sensitive to initial centers.
- Sensitive to outliers.
- May perform poorly on non-spherical clusters or clusters with large differences in density.
5.7 Gradient Boosting
Gradient boosting is a class of ensemble learning methods that reduces the prediction error of an existing model by progressively training new weak learners.
Its core idea is:
- Build an initial model.
- Compute the residuals or the negative gradient of the loss function of the current model.
- Train a new weak learner to fit this information.
- Add the new model to the existing model.
- Progressively improve the overall predictive capability.
Typical algorithms:
- GBDT.
- XGBoost.
- LightGBM.
- CatBoost.
Gradient boosting trees are widely used in structured data tasks, commonly in risk control, recommendation, marketing prediction, and business analysis.
5.8 Neural Network
A neural network consists of multiple interconnected computational units, building complex function mappings through linear transformations and non-linear activation functions.
A single layer's computation can be expressed as:
Where:
- W: weight matrix.
- b: bias vector.
- \sigma: activation function.
- a: output of this layer.
Through a multi-layer structure, the network can learn complex non-linear relationships.
Common network structures:
| Network type | Main applications |
|---|---|
| MLP | General structured data modeling |
| CNN | Image and vision tasks |
| RNN | Sequence modeling |
| LSTM | Long-sequence modeling |
| Transformer | Language, multimodal, and sequence tasks |
| GNN | Graph-structured data |
Deep learning is an important branch of machine learning, and neural networks are its core model architecture.
6. What Is the Difference Between Machine Learning and Deep Learning?
Machine learning and deep learning are not two completely parallel technical fields.
Deep learning is part of machine learning.
Where:
- AI: Artificial intelligence, the study of how to achieve intelligent behavior.
- ML: Machine learning, learning patterns from data.
- DL: Deep learning, learning complex representations through multi-layer neural networks.
6.1 Core differences
| Comparison dimension | Traditional machine learning | Deep learning |
|---|---|---|
| Model structure | Linear models, tree models, kernel methods, etc. | Multi-layer neural networks |
| Feature engineering | Usually relies on manual design | Can automatically learn multi-layer feature representations |
| Data requirements | Small- to medium-scale data can work for many tasks | Complex tasks usually require large amounts of data |
| Computational resources | Usually lower | Usually higher |
| Training cost | Relatively lower | Usually higher |
| Interpretability | Some models are easier to interpret | Complex networks are usually harder to interpret |
| Typical applications | Risk control, forecasting, structured data | Images, speech, language, multimodal data |