Skip to content

Instantly share code, notes, and snippets.

@Younes-Charfaoui
Created July 1, 2020 19:51
Show Gist options
  • Select an option

  • Save Younes-Charfaoui/c608c37b8363f0db59c1a5a2db6fa03e to your computer and use it in GitHub Desktop.

Select an option

Save Younes-Charfaoui/c608c37b8363f0db59c1a5a2db6fa03e to your computer and use it in GitHub Desktop.
# import the libraries
from sklearn.ensemble import IsolationForest
import pandas as pd
# read your data
data = pd.read_csv("yourData.csv")
# create the isolation forest
outlier_detection = IsolationForest()
# fit and predict the outliers
outliers = outlier_detection.fit_predict(data)
#### OPTIONAL ###
# get index of outliers
outliers_index = np.where(outliers == -1, True, false)
# remove outliers from data.
data = data.loc[~(outliers_index, ]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment