AI Foundations ← pitcsolutions.com All lessons

Lesson 3 of 13 in Machine learning, about 15 minutes

Machine Learning Algorithms

A practical map of the most important algorithms: what each is good at, where it struggles, and when to reach for it.

By the end of this lesson you will be able to

  • recognise the main algorithms in each learning type
  • pick a sensible starting algorithm for a real problem
  • know which algorithms appear most often in ML interviews

There are hundreds of ML algorithms, but you don't need to memorise them all. Start with the pictures below: most algorithms are variations on a handful of simple ideas. Then use the tables as a reference you come back to.

Eight core algorithms in pictures

Eight small diagrams illustrating linear regression, logistic regression, decision tree, random forest, K-means, K-nearest neighbours, support vector machine and PCA Linear regression fit a straight line, predict a number Logistic regression S-curve gives a probability: yes / no Decision tree income > 5L? reject debt low? approve reject a chain of yes/no questions Random forest yesyesnoyes vote: yes many trees vote together K-Means clustering K centres pull points into groups K-nearest neighbours new point copies its nearest neighbours Support vector machine widest possible gap between classes PCA keep the direction with most spread
Top row: supervised algorithms. Bottom row: two unsupervised algorithms (K-Means, PCA) and two supervised ones (KNN, SVM).
How to read the tables below

Regression predicts a number (a price, a temperature). Classification predicts a category (spam or not spam). Both means the algorithm has versions for either. The stars show how often the algorithm comes up in interviews.

1. Supervised learning algorithms

AlgorithmProblem typeUsed forAdvantagesDisadvantagesBest used whenInterview
Linear RegressionRegressionPredict continuous valuesSimple, interpretable, fastAssumes a linear relationshipHouse prices, sales forecastingβ˜…β˜…β˜…β˜…β˜…
Multiple Linear RegressionRegressionSeveral input variablesEasy to understandSensitive to multicollinearitySalary predictionβ˜…β˜…β˜…β˜…
Polynomial RegressionRegressionCurved relationshipsFits curves wellEasily overfitsGrowth trendsβ˜…β˜…β˜…
Logistic RegressionClassificationBinary classificationFast, interpretableOnly a linear decision boundarySpam detection, disease predictionβ˜…β˜…β˜…β˜…β˜…
Decision TreeBothClassification and regressionEasy to explainOverfitsMedical diagnosisβ˜…β˜…β˜…β˜…β˜…
Random ForestBothEnsemble of treesHigh accuracy, less overfittingSlower, less interpretableBanking, fraud detectionβ˜…β˜…β˜…β˜…β˜…
Extra TreesBothMore randomised forestFaster, lower varianceHarder to interpretLarge datasetsβ˜…β˜…β˜…
Support Vector MachineClassificationHigh-dimensional dataWorks well with small datasetsSlow on large datasetsFace recognitionβ˜…β˜…β˜…β˜…
Support Vector RegressionRegressionContinuous predictionHandles non-linearityComputationally expensiveFinancial forecastingβ˜…β˜…β˜…
K-Nearest NeighboursBothClassification and regressionVery simpleSlow on large datasetsRecommendation systemsβ˜…β˜…β˜…β˜…
Naive BayesClassificationProbability-based classificationVery fastAssumes features are independentEmail spam filteringβ˜…β˜…β˜…β˜…
Gaussian Naive BayesClassificationContinuous featuresExtremely fastSometimes lower accuracyMedical diagnosisβ˜…β˜…β˜…
Bernoulli Naive BayesClassificationBinary (yes/no) featuresGood for textBinary inputs onlyDocument classificationβ˜…β˜…
Multinomial Naive BayesClassificationCount-based featuresExcellent for NLPAssumes independenceSentiment analysisβ˜…β˜…β˜…β˜…
Gradient BoostingBothEnsemble boostingHigh accuracySlow trainingCredit scoringβ˜…β˜…β˜…β˜…
AdaBoostClassificationBoosting weak learnersSimple boostingSensitive to noiseFraud detectionβ˜…β˜…β˜…
XGBoostBothGradient boostingExtremely accurateMany hyperparametersKaggle competitionsβ˜…β˜…β˜…β˜…β˜…
LightGBMBothGradient boostingVery fastCan overfit small datasetsLarge datasetsβ˜…β˜…β˜…β˜…
CatBoostBothCategorical featuresHandles categories automaticallySlower than LightGBMBusiness datasetsβ˜…β˜…β˜…β˜…
Neural Network (MLP)BothComplex patternsPowerfulNeeds more dataGeneral predictionβ˜…β˜…β˜…β˜…
Deep Neural NetworkBothLarge-scale predictionLearns complex relationshipsComputationally expensiveImages, speechβ˜…β˜…β˜…β˜…
Bagging vs boosting, in one line each

Random forest (bagging): ask 100 independent experts and take a vote. Gradient boosting / XGBoost (boosting): each new expert studies the mistakes of the previous ones and fixes them.

2. Unsupervised learning algorithms

AlgorithmPurposeAdvantagesDisadvantagesBest used forInterview
K-MeansClusteringFast, simpleYou must choose KCustomer segmentationβ˜…β˜…β˜…β˜…β˜…
Hierarchical ClusteringClusteringNo K needed at the startSlowGene analysisβ˜…β˜…β˜…β˜…
DBSCANDensity clusteringAny cluster shape, flags outliersSensitive to parametersAnomaly detectionβ˜…β˜…β˜…β˜…
OPTICSDensity clusteringHandles varying densitiesMore complexSpatial dataβ˜…β˜…β˜…
Mean ShiftClusteringNo K neededSlowImage segmentationβ˜…β˜…β˜…
Gaussian Mixture ModelProbabilistic clusteringSoft (probabilistic) clustersComputationally intensiveCustomer behaviourβ˜…β˜…β˜…
Spectral ClusteringGraph-based clusteringHandles complex shapesSlowImage processingβ˜…β˜…β˜…
Affinity PropagationClusteringNo K neededHigh memory useRecommendation systemsβ˜…β˜…
PCADimensionality reductionFast, reduces featuresLinear onlyData visualisationβ˜…β˜…β˜…β˜…β˜…
Kernel PCANon-linear reductionCaptures non-linear structureMore expensiveImage recognitionβ˜…β˜…β˜…
t-SNEVisualisationExcellent 2-D pictures of dataSlow, doesn't scaleData explorationβ˜…β˜…β˜…β˜…
UMAPVisualisationFaster than t-SNESensitive to parametersLarge datasetsβ˜…β˜…β˜…
ICAFeature extractionSeparates mixed signalsSensitive to noiseSignal processingβ˜…β˜…β˜…
AutoencoderFeature learningLearns compressed representationsNeeds neural networksAnomaly detectionβ˜…β˜…β˜…β˜…
AprioriAssociation rulesEasy to understandSlow on large dataMarket basket analysisβ˜…β˜…β˜…β˜…
FP-GrowthAssociation rulesFaster than AprioriMore complexRetail analyticsβ˜…β˜…β˜…β˜…

3. Semi-supervised learning algorithms

AlgorithmIdeaAdvantagesDisadvantagesBest used for
Self-TrainingThe model labels unlabelled data itselfSimpleEarly errors can spreadImage classification
Label PropagationSpreads labels through a similarity graphWorks with very few labelsDepends on graph qualitySocial networks
Label SpreadingA more robust label propagationBetter robustnessComputationally expensiveDocument classification
Co-TrainingTwo models teach each otherImproves accuracyNeeds two independent feature setsWeb page classification
Semi-Supervised SVMSVM that also uses unlabelled dataHigh accuracySlow trainingMedical imaging
Pseudo-LabellingConfident predictions become labelsEasy to implementCan reinforce mistakesDeep learning pipelines
Mean TeacherA teacher model guides a student modelStrong performanceComplex trainingImage recognition
FixMatchPseudo-labelling + data augmentationExcellent resultsDepends on augmentationComputer vision

4. Reinforcement learning algorithms

AlgorithmTypeAdvantagesDisadvantagesBest used for
Q-LearningValue-basedSimpleDoesn't scale to big problemsGames
Deep Q-Network (DQN)Deep RLHandles huge state spacesNeeds a lot of computeAtari games
SARSAOn-policyStable learningSlower to convergeRobotics
Monte CarloModel-freeSimple conceptSlow learningEpisodic tasks
Temporal DifferenceModel-freeEfficientCan be unstableSequential decisions
Policy GradientPolicy-basedContinuous actionsHigh varianceRobotics
REINFORCEPolicy-basedEasy to implementSlow convergenceSimple RL tasks
Actor-CriticHybridStable and efficientMore complexAutonomous driving
PPOPolicy optimisationStable, very widely usedNeeds hyperparameter tuningRobotics, games, LLM fine-tuning
TRPOPolicy optimisationStrong theoretical guaranteesComputationally expensiveResearch
A3CAsynchronous RLFaster trainingComplex implementationGame AI
DDPGContinuous controlHandles continuous actionsSensitive to hyperparametersIndustrial robots
TD3Improved DDPGBetter stabilityMore complexRobotics
SAC (Soft Actor-Critic)Off-policySample-efficientComputationally intensiveAutonomous systems

5. Deep learning algorithms

These are covered in depth in the Deep Learning, Computer Vision, NLP, Transformer, GAN and VAE lessons later in the course.

AlgorithmUsed inBest forAdvantagesDisadvantages
Artificial Neural NetworkGeneral MLTabular dataFlexibleNeeds more data
CNNComputer visionImage classificationExcellent for imagesHigh compute cost
RNNSequence dataText, speechCaptures order in timeVanishing gradients
LSTMNLP, time seriesLong sequencesRemembers long-term contextSlower training
GRUNLPFaster than LSTMSimpler architectureSlightly less expressive
TransformerNLP and moreLanguage understandingParallel processingResource-intensive
Encoder-DecoderTranslationMachine translationFlexibleTraining complexity
BERTNLPText understandingContext-awareLarge model
GPTGenerative AIText generationExcellent language generationExpensive to train
GANImage generationSynthetic dataVery realistic outputsDifficult to train
VAEData generationImage synthesisStable trainingBlurry outputs
Diffusion modelsGenerative AIImage generationHigh-quality imagesSlow generation

Which algorithm should I use?

A good starting point for common problems. In practice, you try two or three and compare them on held-out data.

If your problem is…Start with
Predicting house pricesLinear Regression, Random Forest Regressor, XGBoost
Predicting customer churnLogistic Regression, Random Forest, XGBoost
Detecting spam emailsNaive Bayes, Logistic Regression
Classifying imagesCNN, Vision Transformer
Translating languagesTransformer, Encoder-Decoder
Building a chatbotTransformer, GPT-style LLM
Recommending productsKNN, Matrix Factorisation, Neural Collaborative Filtering
Segmenting customersK-Means, DBSCAN, Hierarchical Clustering
Detecting fraudIsolation Forest, One-Class SVM, Random Forest, XGBoost
Reducing the number of featuresPCA, UMAP, t-SNE
Analysing shopping basketsApriori, FP-Growth
Forecasting stock pricesLSTM, GRU, Transformer (with caution: financial forecasting is inherently hard)
Controlling robots or game agentsPPO, DQN, Actor-Critic, SAC
A professional tip

For tabular data (rows and columns, like a spreadsheet), gradient-boosted trees such as XGBoost, LightGBM and CatBoost still beat deep learning most of the time. Deep learning shines on unstructured data: images, text, audio and video.

The interview shortlist

If you are preparing for ML interviews, master these first. Together they cover most concepts expected at entry and intermediate level:

Classical ML

Linear Regression, Logistic Regression, Decision Tree, Random Forest, SVM, KNN, Naive Bayes, Gradient Boosting, XGBoost

Unsupervised

K-Means, DBSCAN, PCA

Deep learning

ANN, CNN, RNN, LSTM and GRU, the Transformer

Reinforcement

Q-Learning, Deep Q-Networks (DQN)

Key takeaways

  • Most algorithms are variations of a few ideas: fit a line, ask yes/no questions, vote, find nearest neighbours, find groups.
  • Start simple (linear/logistic regression, a tree), then try ensembles like Random Forest and XGBoost.
  • Tabular data β†’ boosted trees; images, text and audio β†’ deep learning.

Check your understanding

1. You need to predict whether a patient has a disease (yes or no) and explain the result to doctors. A good first choice is…

It's a supervised classification problem where interpretability matters. K-Means and PCA are unsupervised.

2. What is the main weakness of K-Means?

K-Means asks you for K up front. DBSCAN and hierarchical clustering avoid this.

3. How does a Random Forest reduce overfitting compared with a single Decision Tree?

Individual trees overfit in different ways; averaging many of them cancels much of that out.