In [1]:
import pandas as pd
import numpy as np
from sklearn.ensemble import IsolationForest
In [2]:
x = np.random.randint(1, 10, size=(10, 10))
x[-1, -1] = 100 # anomaly
x[-1, -2] = 200
In [3]:
x
Out[3]:
In [4]:
iforest = IsolationForest(contamination=0.1)
iforest.fit(x)
Out[4]:
In [5]:
iforest.predict(x)
Out[5]:
In [6]:
est = iforest.estimators_[0]
est.tree_.decision_path(x[-1:, :].astype(np.float32)).todense()
Out[6]:
In [8]:
est.tree_.children_right
Out[8]:
In [ ]: