I want to display informations about the result of isolation forest's output, like the isolation indices (on the graphic) and the accuracy of the prediction.
I use sklearn's isolation forest function.
clf = IsolationForest()
clf.fit(X_train)
yPredTest = clf.predict(X_test)
xx, yy = np.meshgrid(np.linspace(-3, 88), np.linspace(-1, 50))
Z = clf.decision_function(np.c_[xx.ravel(), yy.ravel()])
Z = Z.reshape(xx.shape)
plt.title("Isolation Forest")
plt.contourf(xx, yy, Z, cmap=plt.cm.Blues_r)
b = plt.scatter(X_test[:, 0], X_test[:, 1], c='black')
plt.show()
The result I have is like the image but with only one cluster (and some points spread) and all points are in the same colour : problem resolved by putting yPredTest as colour.
An other problem, is I do not know how to enable more than two features.
I have two sets (train and test) which are like [[0,1,34,38O,24],[98,938,238,23,1],[...],[0,13,3,23,49]]
and the algorithm make me truncate my sets like X_train = np.array(list)[:100,[1,2]]
and X_test = np.array(list)[101:,[1,2]]
otherwise (np.array(list)[:100,]
and np.array(list)[101:,]
)it will stop and alert me:
ValueError: Number of features of the model must match the input. Model n_features is 8 and input n_features is 2
It seems that the issue issues at that line Z = clf.decision_function(np.c_[xx.ravel(), yy.ravel()])