Practice - 5 Tasks
Answer the questions below
1fill in blank
easyComplete the code to import the correct library for anomaly detection.
ML Python
from sklearn.[1] import IsolationForest
Drag options to blanks, or click blank then click option'
Attempts:
3 left
2fill in blank
mediumComplete the code to fit the IsolationForest model on data X.
ML Python
model = IsolationForest()
model.[1](X) Drag options to blanks, or click blank then click option'
Attempts:
3 left
3fill in blank
hardFix the error in the code to predict anomalies using the trained model.
ML Python
predictions = model.[1](X_test) Drag options to blanks, or click blank then click option'
Attempts:
3 left
4fill in blank
hardFill both blanks to create a dictionary of anomaly scores for each sample in X.
ML Python
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} Drag options to blanks, or click blank then click option'
Attempts:
3 left
5fill in blank
hardFill all three blanks to train IsolationForest with 100 trees, predict anomalies on X_test, and count how many anomalies were found.
ML Python
model = IsolationForest(n_estimators=[1]) model.[2](X_train) predictions = model.[3](X_test) anomaly_count = sum(predictions == -1)
Drag options to blanks, or click blank then click option'
Attempts:
3 left