

.. _example_applications_plot_prediction_latency.py:


==================
Prediction Latency
==================

This is an example showing the prediction latency of various scikit-learn
estimators.

The goal is to measure the latency one can expect when doing predictions
either in bulk or atomic (i.e. one by one) mode.

The plots represent the distribution of the prediction latency as a boxplot.




.. rst-class:: horizontal


    *

      .. image:: images/plot_prediction_latency_001.png
            :scale: 47

    *

      .. image:: images/plot_prediction_latency_002.png
            :scale: 47

    *

      .. image:: images/plot_prediction_latency_003.png
            :scale: 47

    *

      .. image:: images/plot_prediction_latency_004.png
            :scale: 47


**Script output**::

  Benchmarking SGDRegressor(alpha=0.01, epsilon=0.1, eta0=0.01, fit_intercept=True,
         l1_ratio=0.25, learning_rate='invscaling', loss='squared_loss',
         n_iter=5, penalty='elasticnet', power_t=0.25, random_state=None,
         shuffle=False, verbose=0, warm_start=False)
  Benchmarking RandomForestRegressor(bootstrap=True, compute_importances=None,
             criterion='mse', max_depth=None, max_features='auto',
             max_leaf_nodes=None, min_density=None, min_samples_leaf=1,
             min_samples_split=2, n_estimators=10, n_jobs=1, oob_score=False,
             random_state=None, verbose=0)
  Benchmarking SVR(C=1.0, cache_size=200, coef0=0.0, degree=3, epsilon=0.1, gamma=0.0,
    kernel='rbf', max_iter=-1, probability=False, random_state=None,
    shrinking=True, tol=0.001, verbose=False)
    agg_filter: unknown
    alpha: float (0.0 transparent through 1.0 opaque)         
    animated: [True | False]         
    axes: an :class:`~matplotlib.axes.Axes` instance         
    backgroundcolor: any matplotlib color         
    bbox: rectangle prop dict         
    clip_box: a :class:`matplotlib.transforms.Bbox` instance         
    clip_on: [True | False]         
    clip_path: [ (:class:`~matplotlib.path.Path`,         :class:`~matplotlib.transforms.Transform`) |         :class:`~matplotlib.patches.Patch` | None ]         
    color: any matplotlib color         
    contains: a callable function         
    family or fontfamily or fontname or name: [ FONTNAME | 'serif' | 'sans-serif' | 'cursive' | 'fantasy' | 'monospace' ]         
    figure: a :class:`matplotlib.figure.Figure` instance         
    fontproperties or font_properties: a :class:`matplotlib.font_manager.FontProperties` instance         
    gid: an id string         
    horizontalalignment or ha: [ 'center' | 'right' | 'left' ]         
    label: string or anything printable with '%s' conversion.         
    linespacing: float (multiple of font size)         
    lod: [True | False]         
    multialignment: ['left' | 'right' | 'center' ]         
    path_effects: unknown
    picker: [None|float|boolean|callable]         
    position: (x,y)         
    rasterized: [True | False | None]         
    rotation: [ angle in degrees | 'vertical' | 'horizontal' ]         
    rotation_mode: unknown
    size or fontsize: [ size in points | 'xx-small' | 'x-small' | 'small' | 'medium' | 'large' | 'x-large' | 'xx-large' ]         
    snap: unknown
    stretch or fontstretch: [ a numeric value in range 0-1000 | 'ultra-condensed' | 'extra-condensed' | 'condensed' | 'semi-condensed' | 'normal' | 'semi-expanded' | 'expanded' | 'extra-expanded' | 'ultra-expanded' ]         
    style or fontstyle: [ 'normal' | 'italic' | 'oblique']         
    text: string or anything printable with '%s' conversion.         
    transform: :class:`~matplotlib.transforms.Transform` instance         
    url: a url string         
    variant or fontvariant: [ 'normal' | 'small-caps' ]         
    verticalalignment or va or ma: [ 'center' | 'top' | 'bottom' | 'baseline' ]         
    visible: [True | False]         
    weight or fontweight: [ a numeric value in range 0-1000 | 'ultralight' | 'light' | 'normal' | 'regular' | 'book' | 'medium' | 'roman' | 'semibold' | 'demibold' | 'demi' | 'bold' | 'heavy' | 'extra bold' | 'black' ]         
    x: float         
    y: float         
    zorder: any number         
    agg_filter: unknown
    alpha: float (0.0 transparent through 1.0 opaque)         
    animated: [True | False]         
    axes: an :class:`~matplotlib.axes.Axes` instance         
    backgroundcolor: any matplotlib color         
    bbox: rectangle prop dict         
    clip_box: a :class:`matplotlib.transforms.Bbox` instance         
    clip_on: [True | False]         
    clip_path: [ (:class:`~matplotlib.path.Path`,         :class:`~matplotlib.transforms.Transform`) |         :class:`~matplotlib.patches.Patch` | None ]         
    color: any matplotlib color         
    contains: a callable function         
    family or fontfamily or fontname or name: [ FONTNAME | 'serif' | 'sans-serif' | 'cursive' | 'fantasy' | 'monospace' ]         
    figure: a :class:`matplotlib.figure.Figure` instance         
    fontproperties or font_properties: a :class:`matplotlib.font_manager.FontProperties` instance         
    gid: an id string         
    horizontalalignment or ha: [ 'center' | 'right' | 'left' ]         
    label: string or anything printable with '%s' conversion.         
    linespacing: float (multiple of font size)         
    lod: [True | False]         
    multialignment: ['left' | 'right' | 'center' ]         
    path_effects: unknown
    picker: [None|float|boolean|callable]         
    position: (x,y)         
    rasterized: [True | False | None]         
    rotation: [ angle in degrees | 'vertical' | 'horizontal' ]         
    rotation_mode: unknown
    size or fontsize: [ size in points | 'xx-small' | 'x-small' | 'small' | 'medium' | 'large' | 'x-large' | 'xx-large' ]         
    snap: unknown
    stretch or fontstretch: [ a numeric value in range 0-1000 | 'ultra-condensed' | 'extra-condensed' | 'condensed' | 'semi-condensed' | 'normal' | 'semi-expanded' | 'expanded' | 'extra-expanded' | 'ultra-expanded' ]         
    style or fontstyle: [ 'normal' | 'italic' | 'oblique']         
    text: string or anything printable with '%s' conversion.         
    transform: :class:`~matplotlib.transforms.Transform` instance         
    url: a url string         
    variant or fontvariant: [ 'normal' | 'small-caps' ]         
    verticalalignment or va or ma: [ 'center' | 'top' | 'bottom' | 'baseline' ]         
    visible: [True | False]         
    weight or fontweight: [ a numeric value in range 0-1000 | 'ultralight' | 'light' | 'normal' | 'regular' | 'book' | 'medium' | 'roman' | 'semibold' | 'demibold' | 'demi' | 'bold' | 'heavy' | 'extra bold' | 'black' ]         
    x: float         
    y: float         
    zorder: any number         
  benchmarking with 100 features
  benchmarking with 250 features
  benchmarking with 500 features
  example run in 5.19s



**Python source code:** :download:`plot_prediction_latency.py <plot_prediction_latency.py>`

.. literalinclude:: plot_prediction_latency.py
    :lines: 15-

**Total running time of the example:**  5.32 seconds
( 0 minutes  5.32 seconds)
    