Title: How to handle outliers in this dataset?
Tags: pandas;scikit-learn;data-science;sklearn-pandas;isolation-forest
Question: I am doing a project in machine learning using the 'Pump sensor dataset'. In this, while using the IQR method, I got 894997 outliers in our dataset. But with Isolation Forest, I got around 28642 outliers, which is much lesser than the IQR method. The code for Isolation forest is given below.
`from sklearn.ensemble import IsolationForest
model= IsolationForest(contamination=0.13, n_estimators=1000)
model.fit(X.values)
pred= model.predict(X.values)
X['anomalies']= pred
outliers= X.loc[X['anomalies']==-1]
outlier_index= list(outliers.index)`
My question is which is the correct method to handle these outliers.
Replacing all outliers found through the IQR method with the median of each feature?
Deleting the entire rows that were found through Isolation Forest? If so how to do that



{'source': 'StackExchangeDataset', 'subset': 'stackoverflow.com', 'metadata': {'AnswerCount': 0, 'CommentCount': 0, 'ContentLicense': 'CC BY-SA 4.0', 'CreationDate': '2022:00:07/19/22', 'FavoriteCount': None, 'PostTypeId': 1, 'Tags': '<pandas><scikit-learn><data-science><sklearn-pandas><isolation-forest>', 'Title': 'How to handle outliers in this dataset?', 'ViewCount': 27, 'id': 73030101, 'user_AboutMe': None, 'user_AccountId': 14287500.0, 'user_DisplayName': 'šýâm ķřïśhńā', 'user_Reputation': 1.0, 'user_Views': 3.0, 'user_id': 10320475.0}}