dbv
Decision Border Visualizer for Classification Algorithms
Project description
A python package for Machine Learning Engineers who want to visualize a classification algorithm's decision border.
Installation
Use pip
to install dbv
by typing or copying the following command.
pip install dbv
License
This package is licensed under GPL-3.0 License
.
Example usage
If you are working with a classification algorithm and 2-dimensional input data (e.g. tabular data with two input columns) and a target column, you can use the plot_classifier
function to visualize the decision border. The usage of this function inside a Jupyter notebook is recommended.
- Load the data
import pandas as pd
df = pd.read_csv(<path to .csv file>)
df.head()
The dataframe might look like this:
age | interest | success |
---|---|---|
23.657801 | 18.859917 | 0.0 |
22.573729 | 17.969223 | 0.0 |
32.553424 | 29.463651 | 1.0 |
- Define X, y, split data
from sklearn.model_selection import train_test_split
X = df[["age", "interest"]].values
y = df["success"].values
X_train, X_test, y_train, y_test = train_test_split(X, y, random_state = 0, test_size = 0.25)
- Define model
from sklearn.naive_bayes import GaussianNB
model = GaussianNB()
model.fit(X_train, y_train)
print(model.score(X_test, y_test))
- Visualize Decision Border with
plot_classifier
Set parameter proba = False
to see a hard border.
from dbv import plot_classifier
# Plotting decision border for train data
plot_classifier(model, X_train, y_train, proba = False, xlabel = "Age", ylabel = "Interest")
Set parameter proba = True
to see a soft border.
from dbv import plot_classifier
# Plotting decision border for train data
plot_classifier(model, X_train, y_train, proba = True, xlabel = "Age", ylabel = "Interest")
The result looks like this:
Source code & further information
The source code is maintained at https://github.com/sveneschlbeck/dbv
There are also further information concerning the GPL license model, contributing guidelines and more...