.. DO NOT EDIT. .. THIS FILE WAS AUTOMATICALLY GENERATED BY SPHINX-GALLERY. .. TO MAKE CHANGES, EDIT THE SOURCE PYTHON FILE: .. "auto_examples/plot_blobs_comparison.py" .. LINE NUMBERS ARE GIVEN BELOW. .. only:: html .. note:: :class: sphx-glr-download-link-note Click :ref:`here ` to download the full example code .. rst-class:: sphx-glr-example-title .. _sphx_glr_auto_examples_plot_blobs_comparison.py: =============================================================== Comparison of crisp and fuzzy classifiers on make_blobs dataset =============================================================== A comparison plot for :class:`FuzzyDecisionTreeClassifier` and sklearn's :class:`DecisionTreeClassifier` on dataset generated by :meth:`sklearn.datasets.make_blobs` .. GENERATED FROM PYTHON SOURCE LINES 10-42 .. image:: /auto_examples/images/sphx_glr_plot_blobs_comparison_001.png :alt: Fuzzy Decision Tree (train), Fuzzy Decision Tree (test), sklearn Decision Tree (train), sklearn Decision Tree (test) :class: sphx-glr-single-img .. code-block:: default import matplotlib.pyplot as plt from matplotlib import gridspec from mlxtend.plotting import plot_decision_regions from sklearn.datasets import make_blobs from sklearn.model_selection import train_test_split from sklearn.tree import DecisionTreeClassifier from fuzzytree import FuzzyDecisionTreeClassifier X, y = make_blobs(n_samples=150, n_features=2, centers=[[0, 5], [10, 20], [20, 5]], cluster_std=[10, 5, 10], 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() .. rst-class:: sphx-glr-timing **Total running time of the script:** ( 0 minutes 7.630 seconds) .. _sphx_glr_download_auto_examples_plot_blobs_comparison.py: .. only :: html .. container:: sphx-glr-footer :class: sphx-glr-footer-example .. container:: sphx-glr-download sphx-glr-download-python :download:`Download Python source code: plot_blobs_comparison.py ` .. container:: sphx-glr-download sphx-glr-download-jupyter :download:`Download Jupyter notebook: plot_blobs_comparison.ipynb ` .. only:: html .. rst-class:: sphx-glr-signature `Gallery generated by Sphinx-Gallery `_