IsolationForest predicts 1 for normal points and -1 for anomalies.
Step 2: Analyze test points relative to training data
Points 1 and 3 are close to training data, so predicted as normal (1). Point 10 is far, predicted as anomaly (-1).
Final Answer:
[ 1 -1 1] -> Option D
Quick Check:
Close points = 1, far point = -1 [OK]
Hint: Normal points get 1, anomalies get -1 in IsolationForest [OK]
Common Mistakes:
Assuming all predictions are 1
Confusing -1 with 0 for anomalies
Ignoring distance of test points from training data
4. The following code throws an error. What is the most likely cause?
from sklearn.ensemble import IsolationForest
model = IsolationForest()
model.predict([[1], [2], [3]])
medium
A. The input data format is incorrect
B. The model was not trained before prediction
C. IsolationForest cannot predict on lists
D. Missing random_state parameter
Solution
Step 1: Check if model is trained before prediction
The code calls predict without calling fit first, so the model is not trained.
Step 2: Understand IsolationForest requirements
Model must be trained with fit() before predict() to avoid error.
Final Answer:
The model was not trained before prediction -> Option B
Quick Check:
Call fit() before predict() [OK]
Hint: Always train model with fit() before predict() [OK]
Common Mistakes:
Trying to predict without training
Thinking input format causes error here
Assuming random_state is mandatory
5. You have a dataset with mostly normal data and a few anomalies. You want to detect anomalies using IsolationForest. Which approach is best to prepare your model?
hard
A. Train IsolationForest only on normal data, then predict on all data
B. Train IsolationForest on all data including anomalies
C. Train IsolationForest only on anomalies
D. Train IsolationForest on random subsets ignoring labels
Solution
Step 1: Understand IsolationForest training strategy
IsolationForest is an unsupervised algorithm designed to be trained on data that mostly contains normal points. Training only on normal data helps the model learn the normal pattern and then detect anomalies during prediction.
Step 2: Evaluate options for training data
Training only on normal data, then predicting on all data (D) is the best approach. Training on all data including anomalies (B) can reduce detection accuracy as anomalies influence the model.
Final Answer:
Train IsolationForest only on normal data, then predict on all data -> Option A
Quick Check:
Train on normal data only [OK]
Hint: Train IsolationForest on normal data only for better anomaly detection [OK]
Common Mistakes:
Training on all data including anomalies
Training only on anomalies
Ignoring the importance of training data quality
Recommended
Ready to prove it?
Pass the test and this pattern moves unknownstrongwhile earning +1 Grip toward your certificate.