.. 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 :ref:`Go to the end ` to download the full example code or to run this example in your browser via JupyterLite or 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 `. 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) `__. .. GENERATED FROM PYTHON SOURCE LINES 32-53 .. code-block:: Python 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
sepal length (cm) sepal width (cm) petal length (cm) petal width (cm)
114 -0.052506 -0.592373 3.0 4.0
62 0.189830 -1.973554 2.0 1.0
33 -0.416010 2.630382 0.0 1.0
107 1.765012 -0.362176 4.0 3.0
7 -1.021849 0.788808 1.0 1.0


.. 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 `. In the following example, features are not allowed to interact. .. GENERATED FROM PYTHON SOURCE LINES 61-71 .. code-block:: Python 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
HistGradientBoostingRegressor(interaction_cst=[[0], [1], [2], [3], [4], [5],
                                                   [6], [7], [8], [9]],
                                  random_state=0)
In a Jupyter environment, please rerun this cell to show the HTML representation or trust the notebook.
On GitHub, the HTML representation is unable to render, please try loading this page with nbviewer.org.


.. 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:: Python 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:: Python 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:: Python 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:: Python 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:: Python 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:: Python X, y = fetch_openml( "titanic", version=1, as_frame=True, return_X_y=True, parser="pandas" ) X.head() .. raw:: html
pclass name sex age sibsp parch ticket fare cabin embarked boat body home.dest
0 1 Allen, Miss. Elisabeth Walton female 29.0000 0 0 24160 211.3375 B5 S 2 NaN St Louis, MO
1 1 Allison, Master. Hudson Trevor male 0.9167 1 2 113781 151.5500 C22 C26 S 11 NaN Montreal, PQ / Chesterville, ON
2 1 Allison, Miss. Helen Loraine female 2.0000 1 2 113781 151.5500 C22 C26 S NaN NaN Montreal, PQ / Chesterville, ON
3 1 Allison, Mr. Hudson Joshua Creighton male 30.0000 1 2 113781 151.5500 C22 C26 S NaN 135.0 Montreal, PQ / Chesterville, ON
4 1 Allison, Mrs. Hudson J C (Bessie Waldo Daniels) female 25.0000 1 2 113781 151.5500 C22 C26 S NaN NaN Montreal, PQ / Chesterville, ON


.. GENERATED FROM PYTHON SOURCE LINES 145-152 Experimental Array API support in :class:`~discriminant_analysis.LinearDiscriminantAnalysis` -------------------------------------------------------------------------------------------- Experimental support for the `Array API `_ specification was added to :class:`~discriminant_analysis.LinearDiscriminantAnalysis`. The estimator can now run on any Array API compliant libraries such as `CuPy `__, a GPU-accelerated array library. For details, see the :ref:`User Guide `. .. 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 `. .. rst-class:: sphx-glr-timing **Total running time of the script:** (0 minutes 6.200 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/main?urlpath=lab/tree/notebooks/auto_examples/release_highlights/plot_release_highlights_1_2_0.ipynb :alt: Launch binder :width: 150 px .. container:: lite-badge .. image:: images/jupyterlite_badge_logo.svg :target: ../../lite/lab/?path=auto_examples/release_highlights/plot_release_highlights_1_2_0.ipynb :alt: Launch JupyterLite :width: 150 px .. container:: sphx-glr-download sphx-glr-download-jupyter :download:`Download Jupyter notebook: plot_release_highlights_1_2_0.ipynb ` .. container:: sphx-glr-download sphx-glr-download-python :download:`Download Python source code: plot_release_highlights_1_2_0.py ` .. include:: plot_release_highlights_1_2_0.recommendations .. only:: html .. rst-class:: sphx-glr-signature `Gallery generated by Sphinx-Gallery `_