CertNote/ Commute Study Notes
Roadmap
KOEN
CLF-C02 · FoundationalCloud Practitioner - Foundational
DVA-C02 · AssociateDeveloper - Associate
SAA-C03 · AssociateSolutions Architect - Associate
SOA-C02 · AssociateCloudOps Engineer - Associate
SAP-C02 · ProfessionalSolutions Architect - Professional
DOP-C02 · ProfessionalDevOps Engineer - Professional
Linux Master 2 · 2급KAIT Linux Master - Level 2
SCS-C03 · SpecialtySecurity - Specialty
Linux Master 1 · 1급KAIT Linux Master - Level 1
MLA-C01 · AssociateMachine Learning Engineer - Associate
AIF-C01 · FoundationalAI Practitioner - Foundational
DEA-C01 · AssociateData Engineer - Associate
MLS-C01 · SpecialtyMachine Learning - Specialty
  • Week 1
    • 1.The ML Lifecycle (from a Specialty Perspective)
    • 2.Data Storage for ML: S3, EFS, FSx for Lustre, and Data Formats
    • 3.Data Ingestion: Kinesis, Glue, Batch vs. Streaming
    • 4.Data Labeling: SageMaker Ground Truth, Active Learning, Label Quality
    • 5.Week 1 Comprehensive Review: ML Overview & Data Engineering 1
  • Week 2
  • Week 3
  • Week 4
  • Week 5
  • Week 6
    • 1.Algorithm Selection: Mapping by Problem Type
    • 2.SageMaker Builtin 1: XGBoost, Linear Learner, K-Means, KNN
    • 3.SageMaker Builtin 2: Text, Images, Time Series, Recommendations
    • 4.Unsupervised Learning and Anomaly Detection: RCF, PCA, IP Insights, Topic Models (LDA/NTM)
    • 5.Week 6 Comprehensive Review: Algorithm Selection and SageMaker Builtin Algorithms
  • Week 7
  • Week 8
  • Week 9
  • Week 10
  • Week 11
  • Week 12
SQLD · 개발자SQL Developer (SQLD)

© CertNote · 주간랩스

  • About
  • Changelog
  • Contact
  • Terms
  • Privacy
← MLS-C01/Week 6/Day 4

Based on the MLS-C01 exam guide·Report an error

MLS-C01· AssociateWeek 6 · Day 4~31 min read

Day 4 - Unsupervised Learning and Anomaly Detection: RCF, PCA, IP Insights, Topic Models (LDA/NTM)

📌 Key Takeaways

  • All four builtins today work with structure, anomalies, dimensions, and topics without labels. The signals in a question are "there are no labels / rare events / too many dimensions / discover topics."
  • RCF is for anomaly detection on general numeric data, and IP Insights is dedicated to "entity-IP" relationship anomalies. Do not mix the two.
  • For real-time stream anomaly detection, think of the RANDOM_CUT_FOREST function in Kinesis Data Analytics.
  • PCA compresses many correlated features while preserving variance. For very large dimensions, use algorithm_mode=randomized.
  • LDA in SageMaker is a topic model (Latent Dirichlet Allocation) and shares only a name with Linear Discriminant Analysis, the dimensionality reduction technique. Choose NTM for large scale/GPU, and LDA for simplicity/interpretability.

Unsupervised Builtins at a Glance

AlgorithmTaskSignal wordsInputOutput
Random Cut ForestAnomaly detection (general numeric)"rare events / spikes / real-time"CSV, RecordIO-protobufPer-record anomaly score
IP InsightsAnomaly detection (entity-IP)"abnormal login / account IP"(entity, IP) CSVLikelihood that the entity would use that IP
PCADimensionality reduction"too many features / compress / visualize"RecordIO-protobuf, CSVPrincipal component coordinates
LDATopic model (probabilistic)"discover topics / small scale / interpretability"BoWPer-document topic distribution, per-topic word distribution
NTMTopic model (neural network)"discover topics / large scale / GPU"BoWPer-document topic distribution, per-topic word distribution
              [There are no labels]
                     │
   ┌──────────┬──────┴───────┬──────────────┐
"Find rare   "Too many       "Find topics   "Group similar
 events"      features"       in documents"   things together"
   │             │              │              │
What data?     PCA          Document scale?   K-Means
   │        (regular /          │            (Day 2)
   ├─ General numeric randomized) ├─ Large/GPU → NTM
   │  → RCF                   └─ Small/interpretable → LDA
   │  (if real-time, Kinesis
   │   Data Analytics RCF)
   └─ (entity, IP) pairs
      → IP Insights

Random Cut Forest (RCF) — Anomaly Detection

It builds trees by cutting the data at random and assigns a high anomaly score to points that are easily isolated (rare).

  • Use: Anomaly detection (unsupervised). Time series spikes, rare patterns
  • Input: CSV, RecordIO-protobuf
  • Output: Per-record anomaly score (higher means more anomalous)
  • Streaming: Kinesis Data Analytics has a built-in RANDOM_CUT_FOREST function, which enables real-time anomaly detection
Key hyperparameters:
  num_trees              number of trees (more means more stable)
  num_samples_per_tree   samples per tree
  feature_dim            feature dimension

The intuition behind RCF is that "anomalies get isolated faster than normal points." Normal points sit in dense regions and need many cuts to be separated, but a rare point is isolated with just a few random cuts. This isolation depth becomes the score. It needs no labels and reacts even to new kinds of anomalies, so it represents the "there are almost no labels / the anomalies keep changing" problem mentioned on Day 1. If the requirement is real-time, think of the RCF SQL function in Kinesis Data Analytics.

[Normal point]  Dense region → many cuts needed to separate → deep isolation depth → low score
   ● ●●●
   ●●●●●   ──┬── ──┬── ──┬── ──┬──  (needs 4 cuts to separate)
   ●●●

[Anomalous point]  Sparse region → isolated in a few cuts → shallow isolation depth → high score
                ○     ──┬──               (separated in 1 cut)

Anomaly Detection: Supervised vs Unsupervised Decision Table

ConditionSupervised classificationUnsupervised anomaly detection (RCF)
Are there enough anomaly labels?Required (thousands or more)Not needed
Is the anomaly pattern fixed?Advantageous when fixedCopes even when it keeps changing
New types of anomaliesMissed because never learnedCaught when it deviates from normal
Question clue"Past fraud cases are sufficiently labeled""Almost no labels / the tactics keep changing"
Metricprecision/recall/PR-AUCAnomaly score threshold and operational alert volume

⚠️ Trap: For an anomaly detection problem, choosing "train it as a normal/anomaly binary classification" is correct only if the question gives grounds that enough anomaly labels exist. Choosing supervised classification without such grounds is wrong.

PCA — Dimensionality Reduction

It compresses many highly correlated features into a small number of principal components that preserve as much variance as possible.

  • Use: Dimensionality reduction (unsupervised). Visualization, lightening the input to downstream models, mitigating multicollinearity
  • Input: RecordIO-protobuf, CSV
  • Modes: regular (medium dimensions), randomized (very large dimensions, approximate, fast)
Key hyperparameters:
  num_components     number of principal components to keep
  algorithm_mode     regular | randomized
  subtract_mean      remove the mean (centering)
  • It is scale-sensitive, so you usually scale and center first.
  • PCA is unsupervised and does not use labels. If you need a dimensionality reduction that uses labels, that is LDA (Linear Discriminant Analysis), but there is a catch — LDA in SageMaker is a topic model (Latent Dirichlet Allocation) and shares only the name.
ModeWhen to useCharacteristics
regularThe number of features is moderateExact computation
randomizedThe number of features is very largeApproximate computation, fast and scalable
Reason to use PCAEffectCost
Mitigate multicollinearityPrincipal components are orthogonal, so correlation disappearsLoses interpretability of the original features
Lighten training/inferenceFewer input dimensions improve speed and costSome variance (information) is lost
Assist distance-based modelsEases the curse of dimensionality (in front of KNN)Performance does not always improve
VisualizationScatter plot with 2~3 principal componentsThe meaning of the axes is not intuitive

⚠️ Trap: If you skip scaling before PCA, a feature with large units (e.g., salary) monopolizes the variance, and that feature's direction becomes the first principal component. Standardizing before PCA is almost always the correct option.

IP Insights — Entity-IP Anomaly Detection

It learns the association between an entity (user/account) and IPv4 addresses and detects combinations that differ from the usual.

  • Use: Abnormal logins, account takeover, bot detection (unsupervised)
  • Input: CSV — (entity, IP) pairs
  • Output: Likelihood that the entity would use that IP (lower means more anomalous)
  • Technique: Learns entity-IP patterns with neural network embeddings and contrasts them against random negative samples
Key hyperparameters:
  num_entity_vectors   size of the entity embedding hash space
  vector_dim           embedding dimension
  num_ip_encoder_layers
  random_negative_sampling_rate

The fork between RCF and IP Insights: both are anomaly detection, but RCF is for anomalies in general numeric data, while IP Insights specializes in the "entity-IP" relationship. For a login from an unusual IP, use IP Insights; for a sudden change in a general metric, use RCF.

Comparison axisRandom Cut ForestIP Insights
Input dataNumeric feature vectors(entity, IPv4) pairs
Learning methodIsolation depth of random-cut treesEmbeddings + contrast with random negative samples
Output interpretationAnomaly score (higher means more anomalous)Usage likelihood (lower means more anomalous)
Typical scenarioServer metric spikes, transaction anomaliesAccount takeover, bots, logins from unfamiliar regions
Real-time pathKinesis Data Analytics RCFEndpoint inference

Real-Time vs Batch Anomaly Detection Paths

RequirementPathRationale
Detect immediately in the streamThe RANDOM_CUT_FOREST SQL function in Kinesis Data AnalyticsComputes scores inside the stream without model training or an endpoint
Score each online requestSageMaker RCF model → real-time endpointThe application queries per request
Score a large volume of logs in a nightly batchBatch TransformNo need to keep an endpoint running at all times

If you see only the word "real-time" and always choose a SageMaker real-time endpoint, you will be wrong on a question that says to process within the streaming pipeline. If there is a clue that the data arrives through a Kinesis stream, Kinesis Data Analytics RCF is the more direct answer.

Topic Models: LDA and NTM

They find latent topics and per-topic word distributions in documents without labels. Both are topic models, but their implementations differ.

ItemLDA (Latent Dirichlet Allocation)NTM (Neural Topic Model)
BasisProbabilistic generative modelNeural network (autoencoder)
TrainingCPU, single instance, relatively simpleCan use GPU, large-scale and complex
InputBoW (document-word frequencies)BoW
StrengthsEasy to interpret, small to medium dataRicher representation, large scale
  • Common input: Bag-of-Words (frequency counts per word index), RecordIO-protobuf or CSV
  • The user specifies the number of topics (LDA: num_topics, NTM: num_topics)

Topic models assume that "each document is a mixture of several topics, and each topic is a distribution over words." LDA estimates this with a Bayesian probabilistic model, and NTM approximates the same goal with a neural network. Both are unsupervised, so there are no ground-truth topic labels, and the number of topics is a hyperparameter. When the exam asks "which of the two?", decide by data scale, GPU, and interpretability (large scale/GPU = NTM, simple/interpretable = LDA). This LDA (the topic model) shares only the name with Linear Discriminant Analysis and is completely different.

An option saying "LDA is a dimensionality reduction algorithm" is wrong in the SageMaker context. It is a classic trap that targets the abbreviation collision, and the SageMaker builtin LDA is a topic model.

Preprocessing Requirements and Evaluation Methods

Unsupervised algorithms have no ground-truth labels, so they cannot be evaluated by "accuracy." What you judge them by is the exam point.

BuiltinScalingRequired preprocessingEvaluation method
Random Cut ForestRecommended (if feature units vary)Convert to numeric, handle missing valuesAnomaly score distribution and threshold, operational alert volume
IP InsightsNot applicableOrganize into (entity, IP) pairs, remove duplicatesValidate the low-score range against known incident cases
PCAMandatory (standardize and center)Convert to numeric, handle missing valuesDecide num_components by the cumulative explained variance ratio
LDA / NTMNot applicableTokenize → remove stop words → BoW vectorizationPerplexity, human interpretability of the topic words
DecisionWhat to look atPractical criterion
RCF thresholdWhat top percent of anomaly scores to treat as alertsMatch the alert volume the operations team can handle
Number of PCA componentsCumulative explained variance ratio curveUsually the minimum number of components that exceeds 90~95%
Number of topicsWhether the top words of each topic are distinct from one anotherIf topics look overlapping, reduce num_topics

An option that says to evaluate unsupervised results by "accuracy" is wrong, because there are no ground-truth labels. Judge RCF by the score threshold, PCA by explained variance, and topic models by perplexity and interpretability.

Pipeline That Puts PCA in Front of Other Algorithms

[Original 500 features]
      │  Standardize (mean 0, variance 1)
      ▼
[PCA  algorithm_mode=randomized, num_components=30]
      │  30 principal components (mutually orthogonal, 95% variance preserved)
      ▼
[Downstream]  KNN (eases curse of dimensionality) / K-Means (stabilizes distances) / Visualization (2~3 components)
  • With fewer dimensions, training and inference of distance-based models become faster and more stable.
  • The cost is loss of interpretability. If a regulatory review requires explaining "which features had an influence," PCA is at a disadvantage.

Question Clue → Answer Mapping Table

Question clueAnswer directionWhat gets pushed to wrong answers
"Rare anomalies without labels / real-time on a stream"RCF (real-time = Kinesis Data Analytics RCF)Supervised classification
"A user/account from an IP unlike usual"IP InsightsRCF
"Reduce hundreds to thousands of features as model input"PCA (randomized mode if huge)K-Means, FM
"Discover topics in a pile of documents"LDA / NTMBlazingText supervised (needs labels)
"Topic discovery + large scale + GPU"NTMLDA
"Topic discovery + easy to interpret + small scale"LDANTM
"LDA is Linear Discriminant Analysis"Wrong (name collision)—
"Skip scaling before PCA"Wrong—
"Evaluate unsupervised results by accuracy"Wrong (no ground-truth labels)—
"Enough anomaly labels have accumulated"Supervised classification is also validInsisting on RCF alone

Tomorrow we synthesize all of Week 6 from an algorithm-selection decision-making perspective.

📖 Glossary

  • Anomaly score: A numeric value showing how different a record is from the usual. For RCF, a larger value means more anomalous.
  • Isolation: Leaving only a single point through random cuts. The more anomalous a point is, the fewer cuts it takes to isolate it.
  • Principal component: A new axis in the direction that explains the most variance in the data. They are mutually orthogonal.
  • Multicollinearity: A phenomenon where features are strongly correlated with each other, making the coefficient interpretation of linear models unstable. PCA mitigates it.
  • subtract_mean (centering): A preprocessing step that subtracts the mean from each feature to align the origin. It is a prerequisite for PCA.
  • Entity: In IP Insights, the subject observed paired with an IP, such as a user ID or account ID.
  • Random negative sampling: A technique that artificially creates (entity, IP) combinations that were never actually observed and uses them for contrastive learning.
  • Bag-of-Words (BoW): A representation that discards word order and counts only occurrence frequencies to turn a document into a vector. It is the input to topic models.
  • num_topics: The number of topics a topic model will find. With no ground truth, it is a hyperparameter the user sets.
  • LDA name collision: The SageMaker builtin LDA is a topic model (Latent Dirichlet Allocation), and shares only the abbreviation with Linear Discriminant Analysis, the dimensionality reduction technique.

📝 Practice Questions

Click a choice to reveal the answer and explanation.

Question 1

You want to detect abnormal sudden changes (spikes) in a server metric stream in real time and without labels. Which combination is MOST suitable?

Question 2

A web service wants to detect the anomaly of "a specific user account logging in from an IP address completely different from usual." Which built-in algorithm is the MOST specialized for this?

Question 3

You want to compress 500 highly correlated numeric features to about 30 while preserving as much variance as possible, to use as input to a downstream model. Which built-in algorithm is MOST suitable?

Question 4

You want to discover latent topics in a large unlabeled document corpus. The data is very large and you want to accelerate training with GPUs. Which of LDA and NTM is more suitable, and which statement gives the correct reason?

Question 5

Which is the MOST accurate statement about the name "LDA" in SageMaker?

PreviousSageMaker Builtin 2: Text, Images, Time Series, RecommendationsWeek 6 · Day 3Next Week 6 Comprehensive Review: Algorithm Selection and SageMaker Builtin AlgorithmsWeek 6 · Day 5

Official references

  • MLS-C01 official exam page(opens in a new tab)
  • Amazon SageMaker AI documentation(opens in a new tab)
  • Amazon Kinesis documentation(opens in a new tab)

On this page

  • Key Takeaways
  • Unsupervised Builtins at a Glance
  • Random Cut Forest (RCF) — Anomaly Detection
  • Anomaly Detection: Supervised vs Unsupervised Decision Table
  • PCA — Dimensionality Reduction
  • IP Insights — Entity-IP Anomaly Detection
  • Real-Time vs Batch Anomaly Detection Paths
  • Topic Models: LDA and NTM
  • Preprocessing Requirements and Evaluation Methods
  • Pipeline That Puts PCA in Front of Other Algorithms
  • Question Clue → Answer Mapping Table
  • Glossary
  • Practice Questions