Skip to content

Instantly share code, notes, and snippets.

@erykml
Created March 9, 2019 22:52
Show Gist options
  • Select an option

  • Save erykml/cd9e596c3295405b3be012ac8ddc38de to your computer and use it in GitHub Desktop.

Select an option

Save erykml/cd9e596c3295405b3be012ac8ddc38de to your computer and use it in GitHub Desktop.
if_eif = iso.iForest(X.values,
ntrees = 100,
sample_size = 256,
ExtensionLevel = 0)
# calculate anomaly scores
anomaly_scores = if_eif.compute_paths(X_in = X.values)
# sort the scores
anomaly_scores_sorted = np.argsort(anomaly_scores)
# retrieve indices of anomalous observations
indices_with_preds = anomaly_scores_sorted[-int(np.ceil(anomalies_ratio * X.shape[0])):]
# create predictions
y_pred = np.zeros_like(y)
y_pred[indices_with_preds] = 1
@ksaha79
Copy link
Copy Markdown

ksaha79 commented Jun 7, 2022

Is the anomalous ratio equivalent to the contamination rate here?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment