:orphan: .. _chart_gallery.elbow: ============== Elbow Curve ============== .. Necessary Code Elements .. ipython:: python :suppress: :okwarning: # importing dataset and elbow function from vastorbit.datasets import load_iris from vastorbit.machine_learning.model_selection import elbow # creating VastFrame data = load_iris() General ------- vastorbit's Elbow Curve tool is a valuable asset for optimizing clustering models, particularly those employing algorithms like K-Means. This tool allows users to assess the performance of the clustering algorithm by plotting the distortion (inertia) against varying numbers of clusters (k values). Analyzing the Elbow Curve helps data analysts pinpoint the optimal number of clusters where the rate of decrease in distortion slows down, resembling the bend in an "elbow". This information is crucial for selecting an appropriate value for the number of clusters in a dataset. By leveraging the insights gained from the Elbow Curve, data analysts can enhance the efficiency of their clustering models, avoid overfitting or underfitting, and make informed decisions to achieve optimal model performance. Let's begin by importing ```vastorbit```. Let's use the iris dataset from ``vastorbit.datasets`` for this example. .. code-block:: python from vastorbit.datasets import load_iris data = load_iris() In the context of data visualization, we have the flexibility to harness multiple plotting libraries to craft a wide range of graphical representations. vastorbit, as a versatile tool, provides support for several graphic libraries, such as Matplotlib and Plotly. Each of these libraries offers unique features and capabilities, allowing us to choose the most suitable one for our specific data visualization needs. .. image:: ../../docs/source/_static/plotting_libs.png :width: 80% :align: center .. note:: To select the desired plotting library, we simply need to use the `:py:func:`~vastorbit.set_option` function. vastorbit offers the flexibility to smoothly transition between different plotting libraries. In instances where a particular graphic is not supported by the chosen library or is not supported within the vastorbit framework, the tool will automatically generate a warning and then switch to an alternative library where the graphic can be created. Please click on the tabs to view the various graphics generated by the different plotting libraries. .. ipython:: python :suppress: import vastorbit as vo .. tab:: Plotly .. ipython:: python :suppress: vo.set_option("plotting_lib", "plotly") We can switch to using the ``plotly`` module. .. code-block:: python vo.set_option("plotting_lib", "plotly") Let's generate the Validation Curve. .. code-block:: python elbow( input_relation = data, X = ["PetalLengthCm", "PetalWidthCm"] ) .. ipython:: python :suppress: :okwarning: fig = elbow( input_relation = data, X = ["PetalLengthCm", "PetalWidthCm"] ) fig.write_html("figures/plotting_plotly_elbow_curve.html") .. raw:: html :file: /Users/badr.ouali/Documents/VastOrbit-master/docs/figures/plotting_plotly_elbow_curve.html .. tab:: Matplotlib .. ipython:: python :suppress: vo.set_option("plotting_lib", "matplotlib") We can switch to using the ``matplotlib`` module. .. code-block:: python vo.set_option("plotting_lib", "matplotlib") Let's generate the Validation Curve. .. ipython:: python :okwarning: @savefig plotting_matplotlib_elbow_curve.png elbow( input_relation = data, X = ["PetalLengthCm", "PetalWidthCm"] ) ___________________ Chart Customization ------------------- vastorbit empowers users with a high degree of flexibility when it comes to tailoring the visual aspects of their plots. This customization extends to essential elements such as **color schemes**, **text labels**, and **plot sizes**, as well as a wide range of other attributes that can be fine-tuned to align with specific design preferences and analytical requirements. Whether you want to make your visualizations more visually appealing or need to convey specific insights with precision, vastorbit's customization options enable you to craft graphics that suit your exact needs. .. ipython:: python :suppress: from vastorbit._utils._sql._sys import purge_memory purge_memory()