Complete the code to import the correct library for anomaly detection.
from sklearn.[1] import IsolationForest
The IsolationForest model is part of the ensemble module in scikit-learn, used for anomaly detection.
Complete the code to fit the IsolationForest model on data X.
model = IsolationForest()
model.[1](X)To train the model on data, we use the fit method.
Fix the error in the code to predict anomalies using the trained model.
predictions = model.[1](X_test)After training, use predict to get anomaly labels for new data.
Fill both blanks to create a dictionary of anomaly scores for each sample in X.
scores = {i: model.[1](X[i].reshape(1, -1))[0] for i in range(len(X)) if model.[2](X[i].reshape(1, -1))[0] == -1}score_samples gives anomaly scores, and predict labels anomalies (-1). The dictionary stores scores only for anomalies.
Fill all three blanks to train IsolationForest with 100 trees, predict anomalies on X_test, and count how many anomalies were found.
model = IsolationForest(n_estimators=[1]) model.[2](X_train) predictions = model.[3](X_test) anomaly_count = sum(predictions == -1)
Set n_estimators to 100 trees, fit the model on training data, then predict anomalies on test data. Counting -1 labels gives anomaly count.
