How to display both the decision boundary and the class label in scikit-learn?

81 Views Asked by At

I have a pandas dataframe with just 2 features. I would like to use Isolation Forests to identify the outliers and visualise both the attribution (outlier vs non-outlier) and the decision boundary. The following code displays only the decision boundary - all samples appear with the same colour.

from sklearn.inspection import DecisionBoundaryDisplay
from sklearn.ensemble import IsolationForest

ifor = IsolationForest(random_state=0)
ifor.fit(df)
disp = DecisionBoundaryDisplay.from_estimator(
    ifor,
    df,
    response_method="predict",
    alpha=0.5
)
disp.ax_.scatter(df.iloc[:, 0], df.iloc[:, 1], s=20, edgecolor="k")
disp.ax_.set_title("Binary decision boundary \nof IsolationForest")
plt.show()

Here is the plot:

Here is the plot

How can I get the outliers (the points outside of the decision boundary) to be coloured differently?

0

There are 0 best solutions below