0
0
ML Pythonprogramming~10 mins

Anomaly detection basics in ML Python - Interactive Code Practice

Choose your learning style9 modes available
Practice - 5 Tasks
Answer the questions below
1fill in blank
easy

Complete 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'
Aensemble
Blinear_model
Ccluster
Dneighbors
Attempts:
3 left
2fill in blank
medium

Complete 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'
Afit
Bscore_samples
Ctransform
Dpredict
Attempts:
3 left
3fill in blank
hard

Fix 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'
Afit
Bscore_samples
Cfit_predict
Dpredict
Attempts:
3 left
4fill in blank
hard

Fill 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'
Ascore_samples
Bpredict
Cfit
Dtransform
Attempts:
3 left
5fill in blank
hard

Fill 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'
Afit
Bpredict
C100
Dscore_samples
Attempts:
3 left