Note
Click here to download the full example code
Comparison of crisp and fuzzy classifiers on make_circles dataset¶
A comparison plot for FuzzyDecisionTreeClassifier
and sklearn’s DecisionTreeClassifier
on dataset
generated by sklearn.datasets.make_circles()
import matplotlib.pyplot as plt
from matplotlib import gridspec
from mlxtend.plotting import plot_decision_regions
from sklearn.datasets import make_circles
from sklearn.model_selection import train_test_split
from sklearn.tree import DecisionTreeClassifier
from fuzzytree import FuzzyDecisionTreeClassifier
X, y = make_circles(n_samples=150, noise=0.3, factor=0.4, random_state=42)
X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.2, random_state=42)
clf_fuzz = FuzzyDecisionTreeClassifier().fit(X_train, y_train)
clf_sk = DecisionTreeClassifier().fit(X_train, y_train)
gs = gridspec.GridSpec(2, 2)
fig = plt.figure(figsize=(10, 8))
labels = ["Fuzzy Decision Tree", "sklearn Decision Tree"]
for clf, lab, grd in zip([clf_fuzz, clf_sk], labels, [[0, 0], [0, 1]]):
plt.subplot(gs[grd[0], grd[1]])
plot_decision_regions(X=X_train, y=y_train, clf=clf, legend=2)
plt.title("%s (train)" % lab)
plt.subplot(gs[grd[0] + 1, grd[1]])
plot_decision_regions(X=X_test, y=y_test, clf=clf, legend=2)
plt.title("%s (test)" % lab)
plt.show()
Total running time of the script: ( 0 minutes 7.644 seconds)