I am trying to detect anomalies in some data. I have normal data and data which are considered anomalous.
I use Isolation Forest from scikit-learn library in python. I have create a model from the normal data like that:
model = IsolationForest(n_estimators=100, contamination=0.002)
model.fit(new_features)
When I am trying to do prediction:
predicted = model.predict(transformed_anomaly)
It works correctly. 35 out of 36 are detected as anomalies.
If I do this:
for anomaly in transformed_anomaly:
predicted = model.predict(anomaly.reshape(1,-1))
Suddenly all points are classified as inliers.
I checked the shape of 'anomaly.reshape(1,-1)', it is (1, 2). The shape of 'transformed_anomaly' is (36,2)
Could someone point out the problem with it?