Retrieve Decision Boundary Lines (x,y coordinate format) from SKlearn Decision Tree

后端 未结 3 1594
青春惊慌失措
青春惊慌失措 2021-01-13 08:35

I am trying to create a surface plot on an external visualization platform. I\'m working with the iris data set that is featured on the sklearn decision tree documentation p

3条回答
  •  庸人自扰
    2021-01-13 09:07

    @kazemakase's approach is the "right" one. For completeness sake, here is simple way to get every "pixel" in Z that is a decision boundary:

    steps = np.diff(Z,axis=0)[:,1:] + np.diff(Z,axis=1)[1:,:]
    is_boundary = steps != 0
    x,y = np.where(is_boundary)
    # rescale to convert pixels into into original units
    x = x.astype(np.float) * plot_step
    y = y.astype(np.float) * plot_step
    

    Plot of is_boundary (dilated so one can see all non-zero entries):

提交回复
热议问题