.. DO NOT EDIT. .. THIS FILE WAS AUTOMATICALLY GENERATED BY SPHINX-GALLERY. .. TO MAKE CHANGES, EDIT THE SOURCE PYTHON FILE: .. "sklearn_ensae_course/plot_ML_flow_chart.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_sklearn_ensae_course_plot_ML_flow_chart.py: Tutorial Diagrams ================= This script plots the flow-charts used in the scikit-learn tutorials. .. GENERATED FROM PYTHON SOURCE LINES 8-130 .. code-block:: default import matplotlib.pyplot as plt from matplotlib.patches import Circle, Rectangle, Polygon, Arrow, FancyArrow def create_base(box_bg='#CCCCCC', arrow1='#88CCFF', arrow2='#88FF88', supervised=True): fig = plt.figure(figsize=(9, 6), facecolor='w') ax = plt.axes((0, 0, 1, 1), xticks=[], yticks=[], frameon=False) ax.set_xlim(0, 9) ax.set_ylim(0, 6) patches = [Rectangle((0.3, 3.6), 1.5, 1.8, zorder=1, fc=box_bg), Rectangle((0.5, 3.8), 1.5, 1.8, zorder=2, fc=box_bg), Rectangle((0.7, 4.0), 1.5, 1.8, zorder=3, fc=box_bg), Rectangle((2.9, 3.6), 0.2, 1.8, fc=box_bg), Rectangle((3.1, 3.8), 0.2, 1.8, fc=box_bg), Rectangle((3.3, 4.0), 0.2, 1.8, fc=box_bg), Rectangle((0.3, 0.2), 1.5, 1.8, fc=box_bg), Rectangle((2.9, 0.2), 0.2, 1.8, fc=box_bg), Circle((5.5, 3.5), 1.0, fc=box_bg), Polygon([[5.5, 1.7], [6.1, 1.1], [5.5, 0.5], [4.9, 1.1]], fc=box_bg), FancyArrow(2.3, 4.6, 0.35, 0, fc=arrow1, width=0.25, head_width=0.5, head_length=0.2), FancyArrow(3.75, 4.2, 0.5, -0.2, fc=arrow1, width=0.25, head_width=0.5, head_length=0.2), FancyArrow(5.5, 2.4, 0, -0.4, fc=arrow1, width=0.25, head_width=0.5, head_length=0.2), FancyArrow(2.0, 1.1, 0.5, 0, fc=arrow2, width=0.25, head_width=0.5, head_length=0.2), FancyArrow(3.3, 1.1, 1.3, 0, fc=arrow2, width=0.25, head_width=0.5, head_length=0.2), FancyArrow(6.2, 1.1, 0.8, 0, fc=arrow2, width=0.25, head_width=0.5, head_length=0.2)] if supervised: patches += [Rectangle((0.3, 2.4), 1.5, 0.5, zorder=1, fc=box_bg), Rectangle((0.5, 2.6), 1.5, 0.5, zorder=2, fc=box_bg), Rectangle((0.7, 2.8), 1.5, 0.5, zorder=3, fc=box_bg), FancyArrow(2.3, 2.9, 2.0, 0, fc=arrow1, width=0.25, head_width=0.5, head_length=0.2), Rectangle((7.3, 0.85), 1.5, 0.5, fc=box_bg)] else: patches += [Rectangle((7.3, 0.2), 1.5, 1.8, fc=box_bg)] for p in patches: ax.add_patch(p) plt.text(1.45, 4.9, "Training\nText,\nDocuments,\nImages,\netc.", ha='center', va='center', fontsize=14) plt.text(3.6, 4.9, "Feature\nVectors", ha='left', va='center', fontsize=14) plt.text(5.5, 3.5, "Machine\nLearning\nAlgorithm", ha='center', va='center', fontsize=14) plt.text(1.05, 1.1, "New Text,\nDocument,\nImage,\netc.", ha='center', va='center', fontsize=14) plt.text(3.3, 1.7, "Feature\nVector", ha='left', va='center', fontsize=14) plt.text(5.5, 1.1, "Predictive\nModel", ha='center', va='center', fontsize=12) if supervised: plt.text(1.45, 3.05, "Labels", ha='center', va='center', fontsize=14) plt.text(8.05, 1.1, "Expected\nLabel", ha='center', va='center', fontsize=14) plt.text(8.8, 5.8, "Supervised Learning Model", ha='right', va='top', fontsize=18) else: plt.text(8.05, 1.1, "Likelihood\nor Cluster ID\nor Better\nRepresentation", ha='center', va='center', fontsize=12) plt.text(8.8, 5.8, "Unsupervised Learning Model", ha='right', va='top', fontsize=18) def plot_supervised_chart(annotate=False): create_base(supervised=True) if annotate: fontdict = dict(color='r', weight='bold', size=14) plt.text(1.9, 4.55, 'X = vec.fit_transform(input)', fontdict=fontdict, rotation=20, ha='left', va='bottom') plt.text(3.7, 3.2, 'clf.fit(X, y)', fontdict=fontdict, rotation=20, ha='left', va='bottom') plt.text(1.7, 1.5, 'X_new = vec.transform(input)', fontdict=fontdict, rotation=20, ha='left', va='bottom') plt.text(6.1, 1.5, 'y_new = clf.predict(X_new)', fontdict=fontdict, rotation=20, ha='left', va='bottom') def plot_unsupervised_chart(): create_base(supervised=False) .. GENERATED FROM PYTHON SOURCE LINES 131-133 Suggested course of action in a machine learning problem when there are labels. .. GENERATED FROM PYTHON SOURCE LINES 133-135 .. code-block:: default plot_supervised_chart(False) .. image-sg:: /sklearn_ensae_course/images/sphx_glr_plot_ML_flow_chart_001.png :alt: plot ML flow chart :srcset: /sklearn_ensae_course/images/sphx_glr_plot_ML_flow_chart_001.png :class: sphx-glr-single-img .. GENERATED FROM PYTHON SOURCE LINES 136-138 Same graph with name of the function to use with the scikit-learn API. .. GENERATED FROM PYTHON SOURCE LINES 138-140 .. code-block:: default plot_supervised_chart(True) .. image-sg:: /sklearn_ensae_course/images/sphx_glr_plot_ML_flow_chart_002.png :alt: plot ML flow chart :srcset: /sklearn_ensae_course/images/sphx_glr_plot_ML_flow_chart_002.png :class: sphx-glr-single-img .. GENERATED FROM PYTHON SOURCE LINES 141-143 Suggested course of action in a machine learning problem when there is no label. .. GENERATED FROM PYTHON SOURCE LINES 143-144 .. code-block:: default plot_unsupervised_chart() .. image-sg:: /sklearn_ensae_course/images/sphx_glr_plot_ML_flow_chart_003.png :alt: plot ML flow chart :srcset: /sklearn_ensae_course/images/sphx_glr_plot_ML_flow_chart_003.png :class: sphx-glr-single-img .. rst-class:: sphx-glr-timing **Total running time of the script:** ( 0 minutes 1.485 seconds) .. _sphx_glr_download_sklearn_ensae_course_plot_ML_flow_chart.py: .. only:: html .. container:: sphx-glr-footer sphx-glr-footer-example .. container:: sphx-glr-download sphx-glr-download-python :download:`Download Python source code: plot_ML_flow_chart.py ` .. container:: sphx-glr-download sphx-glr-download-jupyter :download:`Download Jupyter notebook: plot_ML_flow_chart.ipynb ` .. only:: html .. rst-class:: sphx-glr-signature `Gallery generated by Sphinx-Gallery `_