Magic Analytics
  • Home
  • Python
    • Pandas
    • Matplotlib
    • Interactive Visualization
    • Folium
  • Spark
    • DataFrame
  • Machine Learning
    • Classification >
      • Logistic Regression
    • Dimension Reduction
    • Model Explaination
  • Blog
  • About

Aries Research Note

Visualize decision boundary in Python

11/24/2016

4 Comments

 
One great way to understanding how classifier works is through visualizing its decision boundary. In scikit-learn, there are several nice posts about visualizing decision boundary (plot_iris, plot_voting_decision_region); however, it usually require quite a few lines of code, and not directly usable. So I write the following function, hope it could serve as a general way to visualize 2D decision boundary for any classification models. (see Github, the notebook is Here)

(Note. a few updates after my first publish, in current version:
1. the API is much simpler
2. add dimension reduction (PCA) to handle higher dimension cases
3. wrap the function into the package (pylib)
)

The usage of this function is quite simple, here it is:

    

    
Picture

    
Picture

    
Picture

    
Picture
In the random forest case, we see the decision boundary is not very continuous as the previous two models. This is because the decision boundary is calculated based on model prediction result: if the predict class changes on this grid, this grid will be identified as on decision boundary. However, if the model has strong volatile behavior in some space, it will be displayed as if decision boundary here. 

Happy Thanksgiving! 
4 Comments
Ghayth AlMahadin
11/8/2018 07:14:37 am

Hi,
I am wondering if you could help me how to use this library as it gives me error " No module named 'pylib' "

Reply
aimendez
3/9/2019 11:33:04 am

Hey there! I am trying to use this function to save some time on the decision boundary plots, but I usually work with data with dim>2. Is it possible to specify in the function which attributes I want to be plotted?

Reply
Rajesh
7/11/2019 11:27:21 pm

How to import this pylib.plot to Anaconda python dist framework

Reply
?
11/14/2019 12:57:59 am

No module named 'pylib.plot'

Reply



Leave a Reply.

    Author

    Data Magician

    Archives

    October 2017
    April 2017
    November 2016
    October 2016
    September 2016

    Categories

    All
    Git
    Hive
    Machine Learning
    Matplotlib
    Pandas
    Plotly
    Python
    R
    Spark

    RSS Feed

Powered by Create your own unique website with customizable templates.
  • Home
  • Python
    • Pandas
    • Matplotlib
    • Interactive Visualization
    • Folium
  • Spark
    • DataFrame
  • Machine Learning
    • Classification >
      • Logistic Regression
    • Dimension Reduction
    • Model Explaination
  • Blog
  • About