Skip to main content

Classical Machine Learning Algorithms

This note is the second part of my machine learning foundation map. It focuses on classical machine learning algorithms and model evaluation.

The goal is not to memorize algorithm names, but to understand why each model exists, what type of problem it solves, how it works, when it is useful, and where its boundaries are.

1. Overview: Several Basic Ways of Thinking in Classical Machine Learning

This stage can be summarized into several modeling perspectives: probability, distance, boundary, rule structure, ensemble learning, and compression.

Modeling perspectiveRepresentative algorithmsFirst-principles idea
ProbabilityNaive BayesUse existing evidence to estimate class probabilities under uncertainty.
DistanceKNN / K-meansSimilar samples should be closer; classification uses neighbors and clustering uses centers.
BoundarySVMFind a classification boundary with the largest safe margin.
Rule structureDecision TreeBreak complex decisions into a sequence of if-else rules.
EnsembleRandom Forest / Boosting / XGBoost / LightGBM / CatBoostLet multiple weak or unstable models cooperate to reduce variance or bias.
CompressionPCAFind directions that preserve the most information in high-dimensional data.

These algorithms are not isolated terms. Each is an answer to a different kind of modeling problem.

2. Core Algorithm Modules

2.1 Naive Bayes: Efficient Probabilistic Classification Through a Simple Assumption

DimensionExplanation
First-principles viewAfter observing a set of features, estimate which class the sample most likely belongs to.
Core mechanismUse Bayes' theorem to calculate posterior probability, while assuming conditional independence of features given the class.
Input / OutputInput: a set of features. Output: class probabilities or final class label.
StrengthsFast training, fast inference, works with small datasets, and is useful as a quick baseline for text and probability-based classification.
LimitationsThe conditional independence assumption is strong; if features are highly correlated, probability estimates can be distorted.

Naive Bayes does not mean the real world is simple. It uses a simplified assumption to obtain an efficient and interpretable classifier.

2.2 KNN: Labeled Neighbor Voting

DimensionExplanation
First-principles viewSimilar samples should be close in feature space, so a new sample can be judged by nearby samples.
Core mechanismCompute the distance between a new sample and training samples, select the nearest K neighbors, and classify through voting or weighted voting.
Input / OutputInput: labeled training samples and new sample features. Output: class label or numerical prediction.
StrengthsAlmost no training is required. It is intuitive, easy to implement, and suitable for small, low-dimensional datasets where distance is meaningful.
LimitationsPrediction can be slow. It is sensitive to K, noise, outliers, feature scaling, and high dimensionality.

A key limitation is the curse of dimensionality. In high-dimensional space, distances between samples become less stable, and the difference between nearest and farthest points may become less meaningful. Since KNN relies heavily on distance, it can fail easily in high-dimensional data.

2.3 SVM: Finding the Maximum-Margin Decision Boundary

DimensionExplanation
First-principles viewA classification boundary should not only separate samples, but also stay as far as possible from both classes.
Core mechanismSVM finds the maximum-margin hyperplane. The boundary is determined by the closest key samples, called support vectors. Kernel functions allow SVM to handle nonlinear patterns without explicitly expanding high-dimensional features.
Input / OutputInput: feature vectors and labels. Output: classification boundary and predicted class.
StrengthsEffective for small to medium datasets, high-dimensional features, and relatively clear margins.
LimitationsTraining can be expensive for large datasets. Kernel and parameter choices strongly affect performance. Interpretability can be limited.

The core of SVM is not merely finding a line. It is finding the most stable boundary with the largest safety margin.

2.4 Decision Tree: Turning Decisions into Rule Paths

DimensionExplanation
First-principles viewA complex decision can be decomposed into a series of local questions.
Core mechanismSplit data by features so that samples in each leaf become as pure as possible. The final model is equivalent to a series of if-else rules.
Input / OutputInput: sample features. Output: class label or regression value.
StrengthsHighly interpretable, easy to visualize, suitable for tabular data, and able to capture nonlinear relationships.
LimitationsDeep trees can memorize noise in the training data and overfit. Constraints such as maximum depth, minimum samples, and pruning are often needed.

Decision trees are powerful because they are clear. Their weakness is also clarity: they may turn random noise into rules.

2.5 Random Forest: Bagging and Collective Judgment

DimensionExplanation
First-principles viewA single decision tree can be unstable, but multiple diverse trees can make more reliable decisions together.
Core mechanismTrain many decision trees through random sampling of data and random selection of features, then aggregate predictions by voting or averaging. This is the idea of Bagging.
Input / OutputInput: structured features and labels. Output: ensemble classification or regression result.
StrengthsMore stable than a single tree, more resistant to overfitting, suitable for tabular data, and able to provide feature importance.
LimitationsLess interpretable than a single tree. The model is larger and may not be ideal for high-dimensional sparse text data.

Random Forest is a parallel ensemble of independent trees. Its diversity helps reduce the instability of a single decision tree.

2.6 Boosting / XGBoost: Sequential Error Correction and Residual Approximation

DimensionExplanation
First-principles viewOne weak model may not solve a complex problem, but many weak models can correct one another step by step.
Core mechanismBoosting trains models sequentially, with each round focusing on correcting previous errors. GBDT fits residuals, while XGBoost uses first-order and second-order gradient information for more refined optimization.
Input / OutputInput: structured data and labels. Output: a strong predictor formed by combining multiple weak learners.
StrengthsStrong performance on tabular data, competitions, and industrial modeling; capable of capturing complex nonlinear patterns.
LimitationsMore parameters, more complex training, and still prone to overfitting if not controlled properly.

If Bagging is parallel voting, Boosting is sequential correction.

2.7 LightGBM: Engineering Optimization for Large-Scale GBDT

DimensionExplanation
First-principles viewOn large-scale data, a model must not only be accurate but also efficient to train.
Core mechanismLightGBM uses histogram binning to compress continuous features into discrete bins, then searches split points at the bin level. It also uses optimizations such as GOSS and EFB.
Input / OutputInput: large-scale structured data. Output: gradient boosting tree model.
StrengthsFast training, low memory usage, and strong performance on large tabular datasets.
LimitationsHistogram discretization may lose a small amount of precision; inappropriate parameters can still cause overfitting.

LightGBM trades a small amount of precision for significant gains in training speed and memory efficiency.

Additional note: binning, EFB, and GOSS

Histogram binning compresses continuous values into discrete intervals. EFB bundles mutually exclusive sparse features to reduce dimensionality. GOSS keeps large-gradient samples and samples from small-gradient samples to improve training efficiency. These are all engineering optimizations, but they work at different levels.

2.8 CatBoost: Categorical Features and Ordered Boosting

DimensionExplanation
First-principles viewReal tabular data often contains many categorical features. Handling them stably while avoiding leakage is important for generalization.
Core mechanismCatBoost is a strong GBDT-family model designed for categorical features. Ordered Boosting helps reduce target leakage and prediction shift.
Input / OutputInput: structured tabular data, especially with categorical features. Output: classification or regression result.
StrengthsStrong categorical feature handling, stable default performance, lower tuning burden, and good generalization.
LimitationsThe training mechanism is more complex. On some extremely large tasks, training speed and resource usage must be considered.

CatBoost is not only about reducing overfitting. It provides a more stable GBDT solution for categorical features and training bias.

2.9 K-means: Center-Based Clustering Without Labels

DimensionExplanation
First-principles viewEven without labels, samples can be organized into groups based on similarity.
Core mechanismPreset K cluster centers, assign each sample to the nearest center, and repeatedly update center positions until stable.
Input / OutputInput: unlabeled feature vectors. Output: cluster labels and cluster centers.
StrengthsSimple, efficient, suitable for user segmentation, data exploration, image compression, and initial clustering.
LimitationsK must be specified in advance. It is sensitive to initial centers and outliers, and performs poorly on crescent-shaped, non-spherical, or uneven-density clusters.

K-means lets unlabeled data organize itself around K centers.

2.10 PCA: Finding the View That Preserves the Most Information

DimensionExplanation
First-principles viewIn high-dimensional data, not every direction is equally important. The most informative directions usually have the largest variance.
Core mechanismPCA finds directions with maximum variance as principal components, then uses a small number of components to replace the original high-dimensional features.
Input / OutputInput: high-dimensional feature matrix. Output: lower-dimensional feature representation.
StrengthsUseful for dimensionality reduction, visualization, denoising, and feature compression.
LimitationsPrincipal components may be hard to interpret. PCA only captures linear structure and inevitably loses some information.

PCA is like choosing a good viewing angle: it uses fewer dimensions to preserve the most variation.

3. Key Distinction: KNN vs K-means

KNN and K-means have similar names, but they solve different tasks.

DimensionKNNK-meansOne-sentence distinction
Learning typeSupervised learningUnsupervised learningKNN uses labels; K-means does not.
Meaning of KNumber of neighborsNumber of clustersOne looks at neighbors; the other defines groups.
Core taskPredict the class of a new sampleAutomatically group dataOne predicts, the other discovers structure.
Core mechanismNeighbor votingCenter iterationOne relies on nearby samples; the other relies on centers.

KNN is a supervised classification or regression method. K-means is an unsupervised clustering method.

4. Model Evaluation and Generalization

A model should not be judged only by whether it "works well." It must be evaluated by where it performs well, where it fails, and whether it can generalize to new data.

ConceptFirst-principles explanation
AccuracyOverall correctness; suitable for balanced classes.
PrecisionAmong samples predicted as positive, how many are truly positive. Useful when false positives are costly.
RecallAmong true positive samples, how many are recovered. Useful when false negatives are costly.
F1-scoreA balance between Precision and Recall.
ROC-AUCMeasures the model's ability to rank positive and negative samples.
MAE / RMSERegression error metrics. RMSE is more sensitive to large errors.
OverfittingGood training performance but poor performance on new data; usually high variance.
UnderfittingPoor performance on both training and testing data; usually high bias.
Bias-Variance TradeoffSimple models may have high bias; complex models may have high variance. The goal is to find a balance.

Evaluation metrics transform intuition into comparable evidence. The purpose of evaluation is not only to report a score, but to understand error types, generalization ability, and task cost.

5. Compressed Summary

This stage can be summarized as follows:

  • Naive Bayes uses conditional independence to turn complex evidence into probability contributions.
  • KNN is labeled neighbor voting, suitable for small, low-dimensional data where distance is meaningful.
  • SVM searches for the maximum-margin hyperplane, with support vectors determining the boundary.
  • Decision Tree explains decisions through rule paths, but deep trees can overfit.
  • Random Forest is Bagging: many trees are trained in parallel to reduce instability.
  • Boosting is sequential error correction: later models correct earlier mistakes.
  • XGBoost improves gradient boosting through engineering optimization and second-order information.
  • LightGBM uses histogram binning, GOSS, and EFB to accelerate large-scale training.
  • CatBoost is strong in categorical feature handling and Ordered Boosting.
  • K-means is center-based unsupervised clustering.
  • PCA is dimensionality reduction through maximum-variance directions.
  • Model evaluation is not just about reporting a number; it is about explaining errors, generalization, and task-specific tradeoffs.

6. What I Learned

The most important lesson from this stage is that classical machine learning is not outdated. It provides foundational model thinking: probability, distance, boundary, rules, ensembles, compression, and evaluation.

These ideas remain important even when moving toward deep learning and AI for Science. Many scientific modeling tasks still require careful problem formulation, feature representation, baseline models, evaluation metrics, and generalization awareness.

7. Current Limitations

This note is still conceptual and does not yet include hands-on implementation for every algorithm. Some algorithms, such as XGBoost, LightGBM, and CatBoost, require deeper study of objective functions, regularization, parameter tuning, and real datasets.

8. Next Learning Steps

My next step is to connect these classical machine learning foundations to scientific modeling. This includes:

  • Understanding how AI enters scientific discovery workflows.
  • Studying world models and system dynamics.
  • Learning scientific agents and research automation.
  • Exploring protein structure prediction, molecular docking, molecular graphs, molecular dynamics, and materials discovery.
  • Building small reproducible experiments that connect concepts with code and documented outputs.