Isolation Forest for Labeled Data

Viewed 28

I have a dataframe with labeled Data, but i want to try the isolation forest an unsupervised algorithm. So basically i remove the column with the label (y=Column with label, x=Dataframe without label). Then I create a test and train set (x_train, x_test, y_test). After this I fit the x_train to my algorithm. Now I use the sklearn method "predict" for x_test and save the result to the variable y_predictions. Now i ran the confusion matrix with y_test and y_predictions.

from sklearn.model_selection import train_test_split
from sklearn.ensemble import IsolationForest
from sklearn.metrics import classification_report
iso=IsolationForest()
iso.fit(X_train)
y_predictions = iso.predict(X_test)                                                                          y_predictions = [1 if i == -1 else 0 for i in y_predictions]
print(classification_report(y_test, y_predictions))

Is this procedure in my code for an unsupervised algorithm (isolation forest) valid or is it wrong?

0 Answers
Related