Created
July 1, 2020 19:51
-
-
Save Younes-Charfaoui/c608c37b8363f0db59c1a5a2db6fa03e to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # 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