.. DO NOT EDIT.
.. THIS FILE WAS AUTOMATICALLY GENERATED BY SPHINX-GALLERY.
.. TO MAKE CHANGES, EDIT THE SOURCE PYTHON FILE:
.. "auto_examples/release_highlights/plot_release_highlights_1_2_0.py"
.. LINE NUMBERS ARE GIVEN BELOW.

.. only:: html

    .. note::
        :class: sphx-glr-download-link-note

        Click :ref:`here <sphx_glr_download_auto_examples_release_highlights_plot_release_highlights_1_2_0.py>`
        to download the full example code or to run this example in your browser via Binder

.. rst-class:: sphx-glr-example-title

.. _sphx_glr_auto_examples_release_highlights_plot_release_highlights_1_2_0.py:


=======================================
Release Highlights for scikit-learn 1.2
=======================================

.. currentmodule:: sklearn

We are pleased to announce the release of scikit-learn 1.2! Many bug fixes
and improvements were added, as well as some new key features. We detail
below a few of the major features of this release. **For an exhaustive list of
all the changes**, please refer to the :ref:`release notes <changes_1_2>`.

To install the latest version (with pip)::

    pip install --upgrade scikit-learn

or with conda::

    conda install -c conda-forge scikit-learn

.. GENERATED FROM PYTHON SOURCE LINES 25-32

Pandas output with `set_output` API
-----------------------------------
scikit-learn's transformers now support pandas output with the `set_output` API.
To learn more about the `set_output` API see the example:
:ref:`sphx_glr_auto_examples_miscellaneous_plot_set_output.py` and
# this `video, pandas DataFrame output for scikit-learn transformers
(some examples) <https://youtu.be/5bCg8VfX2x8>`__.

.. GENERATED FROM PYTHON SOURCE LINES 32-53

.. code-block:: default


    import numpy as np
    from sklearn.datasets import load_iris
    from sklearn.preprocessing import StandardScaler, KBinsDiscretizer
    from sklearn.compose import ColumnTransformer

    X, y = load_iris(as_frame=True, return_X_y=True)
    sepal_cols = ["sepal length (cm)", "sepal width (cm)"]
    petal_cols = ["petal length (cm)", "petal width (cm)"]

    preprocessor = ColumnTransformer(
        [
            ("scaler", StandardScaler(), sepal_cols),
            ("kbin", KBinsDiscretizer(encode="ordinal"), petal_cols),
        ],
        verbose_feature_names_out=False,
    ).set_output(transform="pandas")

    X_out = preprocessor.fit_transform(X)
    X_out.sample(n=5, random_state=0)






.. raw:: html

    <div class="output_subarea output_html rendered_html output_result">
    <div>
    <style scoped>
        .dataframe tbody tr th:only-of-type {
            vertical-align: middle;
        }

        .dataframe tbody tr th {
            vertical-align: top;
        }

        .dataframe thead th {
            text-align: right;
        }
    </style>
    <table border="1" class="dataframe">
      <thead>
        <tr style="text-align: right;">
          <th></th>
          <th>sepal length (cm)</th>
          <th>sepal width (cm)</th>
          <th>petal length (cm)</th>
          <th>petal width (cm)</th>
        </tr>
      </thead>
      <tbody>
        <tr>
          <th>114</th>
          <td>-0.052506</td>
          <td>-0.592373</td>
          <td>3.0</td>
          <td>4.0</td>
        </tr>
        <tr>
          <th>62</th>
          <td>0.189830</td>
          <td>-1.973554</td>
          <td>2.0</td>
          <td>1.0</td>
        </tr>
        <tr>
          <th>33</th>
          <td>-0.416010</td>
          <td>2.630382</td>
          <td>0.0</td>
          <td>1.0</td>
        </tr>
        <tr>
          <th>107</th>
          <td>1.765012</td>
          <td>-0.362176</td>
          <td>4.0</td>
          <td>3.0</td>
        </tr>
        <tr>
          <th>7</th>
          <td>-1.021849</td>
          <td>0.788808</td>
          <td>1.0</td>
          <td>1.0</td>
        </tr>
      </tbody>
    </table>
    </div>
    </div>
    <br />
    <br />

.. GENERATED FROM PYTHON SOURCE LINES 54-61

Interaction constraints in Histogram-based Gradient Boosting Trees
------------------------------------------------------------------
:class:`~ensemble.HistGradientBoostingRegressor` and
:class:`~ensemble.HistGradientBoostingClassifier` now supports interaction constraints
with the `interaction_cst` parameter. For details, see the
:ref:`User Guide <interaction_cst_hgbt>`. In the following example, features are not
allowed to interact.

.. GENERATED FROM PYTHON SOURCE LINES 61-71

.. code-block:: default

    from sklearn.datasets import load_diabetes
    from sklearn.ensemble import HistGradientBoostingRegressor

    X, y = load_diabetes(return_X_y=True, as_frame=True)

    hist_no_interact = HistGradientBoostingRegressor(
        interaction_cst=[[i] for i in range(X.shape[1])], random_state=0
    )
    hist_no_interact.fit(X, y)






.. raw:: html

    <div class="output_subarea output_html rendered_html output_result">
    <style>#sk-container-id-1 {color: black;background-color: white;}#sk-container-id-1 pre{padding: 0;}#sk-container-id-1 div.sk-toggleable {background-color: white;}#sk-container-id-1 label.sk-toggleable__label {cursor: pointer;display: block;width: 100%;margin-bottom: 0;padding: 0.3em;box-sizing: border-box;text-align: center;}#sk-container-id-1 label.sk-toggleable__label-arrow:before {content: "▸";float: left;margin-right: 0.25em;color: #696969;}#sk-container-id-1 label.sk-toggleable__label-arrow:hover:before {color: black;}#sk-container-id-1 div.sk-estimator:hover label.sk-toggleable__label-arrow:before {color: black;}#sk-container-id-1 div.sk-toggleable__content {max-height: 0;max-width: 0;overflow: hidden;text-align: left;background-color: #f0f8ff;}#sk-container-id-1 div.sk-toggleable__content pre {margin: 0.2em;color: black;border-radius: 0.25em;background-color: #f0f8ff;}#sk-container-id-1 input.sk-toggleable__control:checked~div.sk-toggleable__content {max-height: 200px;max-width: 100%;overflow: auto;}#sk-container-id-1 input.sk-toggleable__control:checked~label.sk-toggleable__label-arrow:before {content: "▾";}#sk-container-id-1 div.sk-estimator input.sk-toggleable__control:checked~label.sk-toggleable__label {background-color: #d4ebff;}#sk-container-id-1 div.sk-label input.sk-toggleable__control:checked~label.sk-toggleable__label {background-color: #d4ebff;}#sk-container-id-1 input.sk-hidden--visually {border: 0;clip: rect(1px 1px 1px 1px);clip: rect(1px, 1px, 1px, 1px);height: 1px;margin: -1px;overflow: hidden;padding: 0;position: absolute;width: 1px;}#sk-container-id-1 div.sk-estimator {font-family: monospace;background-color: #f0f8ff;border: 1px dotted black;border-radius: 0.25em;box-sizing: border-box;margin-bottom: 0.5em;}#sk-container-id-1 div.sk-estimator:hover {background-color: #d4ebff;}#sk-container-id-1 div.sk-parallel-item::after {content: "";width: 100%;border-bottom: 1px solid gray;flex-grow: 1;}#sk-container-id-1 div.sk-label:hover label.sk-toggleable__label {background-color: #d4ebff;}#sk-container-id-1 div.sk-serial::before {content: "";position: absolute;border-left: 1px solid gray;box-sizing: border-box;top: 0;bottom: 0;left: 50%;z-index: 0;}#sk-container-id-1 div.sk-serial {display: flex;flex-direction: column;align-items: center;background-color: white;padding-right: 0.2em;padding-left: 0.2em;position: relative;}#sk-container-id-1 div.sk-item {position: relative;z-index: 1;}#sk-container-id-1 div.sk-parallel {display: flex;align-items: stretch;justify-content: center;background-color: white;position: relative;}#sk-container-id-1 div.sk-item::before, #sk-container-id-1 div.sk-parallel-item::before {content: "";position: absolute;border-left: 1px solid gray;box-sizing: border-box;top: 0;bottom: 0;left: 50%;z-index: -1;}#sk-container-id-1 div.sk-parallel-item {display: flex;flex-direction: column;z-index: 1;position: relative;background-color: white;}#sk-container-id-1 div.sk-parallel-item:first-child::after {align-self: flex-end;width: 50%;}#sk-container-id-1 div.sk-parallel-item:last-child::after {align-self: flex-start;width: 50%;}#sk-container-id-1 div.sk-parallel-item:only-child::after {width: 0;}#sk-container-id-1 div.sk-dashed-wrapped {border: 1px dashed gray;margin: 0 0.4em 0.5em 0.4em;box-sizing: border-box;padding-bottom: 0.4em;background-color: white;}#sk-container-id-1 div.sk-label label {font-family: monospace;font-weight: bold;display: inline-block;line-height: 1.2em;}#sk-container-id-1 div.sk-label-container {text-align: center;}#sk-container-id-1 div.sk-container {/* jupyter's `normalize.less` sets `[hidden] { display: none; }` but bootstrap.min.css set `[hidden] { display: none !important; }` so we also need the `!important` here to be able to override the default hidden behavior on the sphinx rendered scikit-learn.org. See: https://github.com/scikit-learn/scikit-learn/issues/21755 */display: inline-block !important;position: relative;}#sk-container-id-1 div.sk-text-repr-fallback {display: none;}</style><div id="sk-container-id-1" class="sk-top-container"><div class="sk-text-repr-fallback"><pre>HistGradientBoostingRegressor(interaction_cst=[[0], [1], [2], [3], [4], [5],
                                                   [6], [7], [8], [9]],
                                  random_state=0)</pre><b>In a Jupyter environment, please rerun this cell to show the HTML representation or trust the notebook. <br />On GitHub, the HTML representation is unable to render, please try loading this page with nbviewer.org.</b></div><div class="sk-container" hidden><div class="sk-item"><div class="sk-estimator sk-toggleable"><input class="sk-toggleable__control sk-hidden--visually" id="sk-estimator-id-1" type="checkbox" checked><label for="sk-estimator-id-1" class="sk-toggleable__label sk-toggleable__label-arrow">HistGradientBoostingRegressor</label><div class="sk-toggleable__content"><pre>HistGradientBoostingRegressor(interaction_cst=[[0], [1], [2], [3], [4], [5],
                                                   [6], [7], [8], [9]],
                                  random_state=0)</pre></div></div></div></div></div>
    </div>
    <br />
    <br />

.. GENERATED FROM PYTHON SOURCE LINES 72-76

New and enhanced displays
-------------------------
:class:`~metrics.PredictionErrorDisplay` provides a way to analyze regression
models in a qualitative manner.

.. GENERATED FROM PYTHON SOURCE LINES 76-87

.. code-block:: default

    import matplotlib.pyplot as plt
    from sklearn.metrics import PredictionErrorDisplay

    fig, axs = plt.subplots(nrows=1, ncols=2, figsize=(12, 5))
    _ = PredictionErrorDisplay.from_estimator(
        hist_no_interact, X, y, kind="actual_vs_predicted", ax=axs[0]
    )
    _ = PredictionErrorDisplay.from_estimator(
        hist_no_interact, X, y, kind="residual_vs_predicted", ax=axs[1]
    )




.. image-sg:: /auto_examples/release_highlights/images/sphx_glr_plot_release_highlights_1_2_0_001.png
   :alt: plot release highlights 1 2 0
   :srcset: /auto_examples/release_highlights/images/sphx_glr_plot_release_highlights_1_2_0_001.png
   :class: sphx-glr-single-img





.. GENERATED FROM PYTHON SOURCE LINES 88-90

:class:`~model_selection.LearningCurveDisplay` is now available to plot
results from :func:`~model_selection.learning_curve`.

.. GENERATED FROM PYTHON SOURCE LINES 90-96

.. code-block:: default

    from sklearn.model_selection import LearningCurveDisplay

    _ = LearningCurveDisplay.from_estimator(
        hist_no_interact, X, y, cv=5, n_jobs=2, train_sizes=np.linspace(0.1, 1, 5)
    )




.. image-sg:: /auto_examples/release_highlights/images/sphx_glr_plot_release_highlights_1_2_0_002.png
   :alt: plot release highlights 1 2 0
   :srcset: /auto_examples/release_highlights/images/sphx_glr_plot_release_highlights_1_2_0_002.png
   :class: sphx-glr-single-img





.. GENERATED FROM PYTHON SOURCE LINES 97-100

:class:`~inspection.PartialDependenceDisplay` exposes a new parameter
`categorical_features` to display partial dependence for categorical features
using bar plots and heatmaps.

.. GENERATED FROM PYTHON SOURCE LINES 100-107

.. code-block:: default

    from sklearn.datasets import fetch_openml

    X, y = fetch_openml(
        "titanic", version=1, as_frame=True, return_X_y=True, parser="pandas"
    )
    X = X.select_dtypes(["number", "category"]).drop(columns=["body"])








.. GENERATED FROM PYTHON SOURCE LINES 108-120

.. code-block:: default

    from sklearn.preprocessing import OrdinalEncoder
    from sklearn.pipeline import make_pipeline

    categorical_features = ["pclass", "sex", "embarked"]
    model = make_pipeline(
        ColumnTransformer(
            transformers=[("cat", OrdinalEncoder(), categorical_features)],
            remainder="passthrough",
        ),
        HistGradientBoostingRegressor(random_state=0),
    ).fit(X, y)








.. GENERATED FROM PYTHON SOURCE LINES 121-132

.. code-block:: default

    from sklearn.inspection import PartialDependenceDisplay

    fig, ax = plt.subplots(figsize=(14, 4), constrained_layout=True)
    _ = PartialDependenceDisplay.from_estimator(
        model,
        X,
        features=["age", "sex", ("pclass", "sex")],
        categorical_features=categorical_features,
        ax=ax,
    )




.. image-sg:: /auto_examples/release_highlights/images/sphx_glr_plot_release_highlights_1_2_0_003.png
   :alt: plot release highlights 1 2 0
   :srcset: /auto_examples/release_highlights/images/sphx_glr_plot_release_highlights_1_2_0_003.png
   :class: sphx-glr-single-img





.. GENERATED FROM PYTHON SOURCE LINES 133-139

Faster parser in :func:`~datasets.fetch_openml`
-----------------------------------------------
:func:`~datasets.fetch_openml` now supports a new `"pandas"` parser that is
more memory and CPU efficient. In v1.4, the default will change to
`parser="auto"` which will automatically use the `"pandas"` parser for dense
data and `"liac-arff"` for sparse data.

.. GENERATED FROM PYTHON SOURCE LINES 139-144

.. code-block:: default

    X, y = fetch_openml(
        "titanic", version=1, as_frame=True, return_X_y=True, parser="pandas"
    )
    X.head()






.. raw:: html

    <div class="output_subarea output_html rendered_html output_result">
    <div>
    <style scoped>
        .dataframe tbody tr th:only-of-type {
            vertical-align: middle;
        }

        .dataframe tbody tr th {
            vertical-align: top;
        }

        .dataframe thead th {
            text-align: right;
        }
    </style>
    <table border="1" class="dataframe">
      <thead>
        <tr style="text-align: right;">
          <th></th>
          <th>pclass</th>
          <th>name</th>
          <th>sex</th>
          <th>age</th>
          <th>sibsp</th>
          <th>parch</th>
          <th>ticket</th>
          <th>fare</th>
          <th>cabin</th>
          <th>embarked</th>
          <th>boat</th>
          <th>body</th>
          <th>home.dest</th>
        </tr>
      </thead>
      <tbody>
        <tr>
          <th>0</th>
          <td>1</td>
          <td>Allen, Miss. Elisabeth Walton</td>
          <td>female</td>
          <td>29.0000</td>
          <td>0</td>
          <td>0</td>
          <td>24160</td>
          <td>211.3375</td>
          <td>B5</td>
          <td>S</td>
          <td>2</td>
          <td>NaN</td>
          <td>St Louis, MO</td>
        </tr>
        <tr>
          <th>1</th>
          <td>1</td>
          <td>Allison, Master. Hudson Trevor</td>
          <td>male</td>
          <td>0.9167</td>
          <td>1</td>
          <td>2</td>
          <td>113781</td>
          <td>151.5500</td>
          <td>C22 C26</td>
          <td>S</td>
          <td>11</td>
          <td>NaN</td>
          <td>Montreal, PQ / Chesterville, ON</td>
        </tr>
        <tr>
          <th>2</th>
          <td>1</td>
          <td>Allison, Miss. Helen Loraine</td>
          <td>female</td>
          <td>2.0000</td>
          <td>1</td>
          <td>2</td>
          <td>113781</td>
          <td>151.5500</td>
          <td>C22 C26</td>
          <td>S</td>
          <td>NaN</td>
          <td>NaN</td>
          <td>Montreal, PQ / Chesterville, ON</td>
        </tr>
        <tr>
          <th>3</th>
          <td>1</td>
          <td>Allison, Mr. Hudson Joshua Creighton</td>
          <td>male</td>
          <td>30.0000</td>
          <td>1</td>
          <td>2</td>
          <td>113781</td>
          <td>151.5500</td>
          <td>C22 C26</td>
          <td>S</td>
          <td>NaN</td>
          <td>135.0</td>
          <td>Montreal, PQ / Chesterville, ON</td>
        </tr>
        <tr>
          <th>4</th>
          <td>1</td>
          <td>Allison, Mrs. Hudson J C (Bessie Waldo Daniels)</td>
          <td>female</td>
          <td>25.0000</td>
          <td>1</td>
          <td>2</td>
          <td>113781</td>
          <td>151.5500</td>
          <td>C22 C26</td>
          <td>S</td>
          <td>NaN</td>
          <td>NaN</td>
          <td>Montreal, PQ / Chesterville, ON</td>
        </tr>
      </tbody>
    </table>
    </div>
    </div>
    <br />
    <br />

.. GENERATED FROM PYTHON SOURCE LINES 145-152

Experimental Array API support in :class:`~discriminant_analysis.LinearDiscriminantAnalysis`
--------------------------------------------------------------------------------------------
Experimental support for the `Array API <https://data-apis.org/array-api/latest/>`_
specification was added to :class:`~discriminant_analysis.LinearDiscriminantAnalysis`.
The estimator can now run on any Array API compliant libraries such as
`CuPy <https://docs.cupy.dev/en/stable/overview.html>`__, a GPU-accelerated array
library. For details, see the :ref:`User Guide <array_api>`.

.. GENERATED FROM PYTHON SOURCE LINES 154-167

Improved efficiency of many estimators
--------------------------------------
In version 1.1 the efficiency of many estimators relying on the computation of
pairwise distances (essentially estimators related to clustering, manifold
learning and neighbors search algorithms) was greatly improved for float64
dense input. Efficiency improvement especially were a reduced memory footprint
and a much better scalability on multi-core machines.
In version 1.2, the efficiency of these estimators was further improved for all
combinations of dense and sparse inputs on float32 and float64 datasets, except
the sparse-dense and dense-sparse combinations for the Euclidean and Squared
Euclidean Distance metrics.
A detailed list of the impacted estimators can be found in the
:ref:`changelog <changes_1_2>`.


.. rst-class:: sphx-glr-timing

   **Total running time of the script:** ( 0 minutes  10.872 seconds)


.. _sphx_glr_download_auto_examples_release_highlights_plot_release_highlights_1_2_0.py:

.. only:: html

  .. container:: sphx-glr-footer sphx-glr-footer-example


    .. container:: binder-badge

      .. image:: images/binder_badge_logo.svg
        :target: https://mybinder.org/v2/gh/scikit-learn/scikit-learn/1.2.X?urlpath=lab/tree/notebooks/auto_examples/release_highlights/plot_release_highlights_1_2_0.ipynb
        :alt: Launch binder
        :width: 150 px

    .. container:: sphx-glr-download sphx-glr-download-python

      :download:`Download Python source code: plot_release_highlights_1_2_0.py <plot_release_highlights_1_2_0.py>`

    .. container:: sphx-glr-download sphx-glr-download-jupyter

      :download:`Download Jupyter notebook: plot_release_highlights_1_2_0.ipynb <plot_release_highlights_1_2_0.ipynb>`


.. only:: html

 .. rst-class:: sphx-glr-signature

    `Gallery generated by Sphinx-Gallery <https://sphinx-gallery.github.io>`_