Answers for LLM inference engineers

ImportError: cannot import name 'load_boston' (or 'plot_confusion_matrix', 'joblib', any name) from 'sklearn...': which scikit-learn removed it and what to use

scikit-learn 1.2.0 (2022-12-08) removed sklearn.datasets.load_boston and sklearn.metrics.plot_confusion_matrix (use ConfusionMatrixDisplay.from_estimator); 0.24.0 (2020-12-22) removed 121 modules such as sklearn.ensemble.forest and sklearn.tree.tree, which is why old pickles fail with "No module named"; 0.23.0 removed sklearn.externals.joblib (import joblib); 0.20.0 removed sklearn.cross_validation (sklearn.model_selection). If the error comes from a library you did not write, upgrade the library or pin scikit-learn below the release that removed the name. Paste the error below for the release-by-release answer.

Published 2026-11-25 · 14 scikit-learn releases installed and run, 0.22 to 1.9.1 (22,820 lookups) · how

Examples:

Runs in your browser on the data in this page (sklearn_names.json); nothing you paste is sent anywhere.

Which release removed it, and what replaces it?

161 public names and modules that one scikit-learn release has and a later one does not. "Instead" is scikit-learn's own deprecation text from the last release that had it (144 of 161); for 4 more it names the module that still has the same name in 1.9.1. The 121 modules removed in 0.24.0 are listed after the table.

NameRemoved inInstead
sklearn.cross_validation (module)0.20.0This module was deprecated in version 0.18 in favor of the model_selection module into which all the refactored classes and functions are moved. Also note that the interface of the new CV iterators are different from that of this module. This module will be removed in 0.20.
sklearn.grid_search (module)0.20.0This module was deprecated in version 0.18 in favor of the model_selection module into which all the refactored classes and functions are moved. This module will be removed in 0.20.
sklearn.learning_curve (module)0.20.0This module was deprecated in version 0.18 in favor of the model_selection module into which all the functions are moved. This module will be removed in 0.20
sklearn.preprocessing.Imputer0.22Imputer was deprecated in version 0.20 and will be removed in 0.22. Import impute.SimpleImputer from sklearn instead.
sklearn.ensemble.partial_dependence (module)0.23.0The function ensemble.partial_dependence has been deprecated in favour of inspection.partial_dependence in 0.21 and will be removed in 0.23.
sklearn.externals.joblib (module)0.23.0sklearn.externals.joblib is deprecated in 0.21 and will be removed in 0.23. Please import this functionality directly from joblib, which can be installed with: pip install joblib. If this warning is raised when loading pickled models, you may need to re-serialize those models with scikit-learn 0.21+.
sklearn.externals.six (module)0.23.0The module is deprecated in version 0.21 and will be removed in version 0.23 since we've dropped support for Python 2.7. Please rely on the official version of six (https://pypi.org/project/six/).
sklearn.linear_model.logistic_regression_path0.23.0logistic_regression_path was deprecated in version 0.21 and will be removed in version 0.23.0
sklearn.metrics.calinski_harabaz_score0.23.0
sklearn.metrics.jaccard_similarity_score0.23.0jaccard_similarity_score has been deprecated and replaced with jaccard_score. It will be removed in version 0.23. This implementation has surprising behavior for binary and multiclass classification tasks.
sklearn.utils.cpu_count0.23.0
sklearn.utils.delayed0.23.0From sklearn.calibration import delayed (still there in 1.9.1).
sklearn.utils.effective_n_jobs0.23.0From sklearn.metrics.pairwise import effective_n_jobs (still there in 1.9.1).
sklearn.utils.hash0.23.0
sklearn.utils.linear_assignment_ (module)0.23.0The linear_assignment_ module is deprecated in 0.21 and will be removed from 0.23. Use scipy.optimize.linear_sum_assignment instead.
sklearn.utils.Memory0.23.0
sklearn.utils.Parallel0.23.0From sklearn.calibration import Parallel (still there in 1.9.1).
sklearn.utils.safe_indexing0.24.0safe_indexing is deprecated in version 0.22 and will be removed in version 0.24.
sklearn.model_selection.fit_grid_point1.0fit_grid_point is deprecated in version 0.23 and will be removed in version 1.0 (renaming of 0.25)
sklearn.utils.graph_shortest_path (module)1.0
sklearn.exceptions.ChangedBehaviorWarning1.1.0ChangedBehaviorWarning is deprecated in 0.24 and will be removed in 1.1
sklearn.exceptions.NonBLASDotWarning1.1.0NonBLASDotWarning is deprecated in 0.24 and will be removed in 1.1
sklearn.datasets.load_boston1.2.0`load_boston` is deprecated in 1.0 and will be removed in 1.2. The Boston housing prices dataset has an ethical problem. You can refer to the documentation of this function for further details. The scikit-learn maintainers therefore strongly discourage the use of this dataset unless the purpose of the code is to study and educate about ethical issues in data science and machine learning. In this special case, you can fetch the dataset from the original source:: import pandas as pd import numpy as np data_url = "http://lib.stat.cmu.edu/datasets/boston" raw_df = pd.read_csv(data_url, sep="\s+", skiprows=22, header=None) data = np.hstack([raw_df.values[::2, :], raw_df.values[1::2, :2]]) target = raw_df.values[1::2, 2] Alternative datasets include the California housing dataset (i.e. :func:`~sklearn.datasets.fetch_california_housing`) and the Ames housing dataset. You can load the datasets as follows:: from sklearn.datasets import fetch_california_housing housing = fetch_california_housing() for the California housing dataset and:: from sklearn.datasets import fetch_openml housing = fetch_openml(name="house_prices", as_frame=True) for the Ames housing dataset.
sklearn.inspection.plot_partial_dependence1.2.0Function `plot_partial_dependence` is deprecated in 1.0 and will be removed in 1.2. Use PartialDependenceDisplay.from_estimator instead
sklearn.metrics.plot_confusion_matrix1.2.0Function `plot_confusion_matrix` is deprecated in 1.0 and will be removed in 1.2. Use one of the class methods: ConfusionMatrixDisplay.from_predictions or ConfusionMatrixDisplay.from_estimator.
sklearn.metrics.plot_det_curve1.2.0Function plot_det_curve is deprecated in 1.0 and will be removed in 1.2. Use one of the class methods: DetCurveDisplay.from_predictions or DetCurveDisplay.from_estimator.
sklearn.metrics.plot_precision_recall_curve1.2.0Function `plot_precision_recall_curve` is deprecated in 1.0 and will be removed in 1.2. Use one of the class methods: PrecisionRecallDisplay.from_predictions or PrecisionRecallDisplay.from_estimator.
sklearn.metrics.plot_roc_curve1.2.0Function :func:`plot_roc_curve` is deprecated in 1.0 and will be removed in 1.2. Use one of the class methods: :meth:`sklearn.metric.RocCurveDisplay.from_predictions` or :meth:`sklearn.metric.RocCurveDisplay.from_estimator`.
sklearn.metrics.SCORERS1.3.0sklearn.metrics.SCORERS is deprecated and will be removed in v1.3. Please use sklearn.metrics.get_scorer_names to get a list of available scorers and sklearn.metrics.get_metric to get scorer.
sklearn.neighbors.DistanceMetric1.3.0From sklearn.metrics import DistanceMetric (still there in 1.9.1).
sklearn.utils.metaestimators.if_delegate_has_method1.3.0if_delegate_has_method was deprecated in version 1.1 and will be removed in version 1.3. Use available_if instead.
sklearn.utils.check_matplotlib_support1.5.0
sklearn.utils.indices_to_mask1.5.0
sklearn.linear_model.Hinge1.6.0
sklearn.linear_model.Huber1.6.0
sklearn.linear_model.Log1.6.0
sklearn.linear_model.ModifiedHuber1.6.0
sklearn.linear_model.SquaredLoss1.6.0
sklearn.utils.parallel_backend1.7.0deprecated in 1.5 to be removed in 1.7. Use joblib.parallel_backend instead.
sklearn.utils.register_parallel_backend1.7.0

Modules removed in 0.24.0 (each warned in 0.22 and 0.23 that its contents should be imported from the package above it): cluster.affinity_propagation_, cluster.bicluster, cluster.birch, cluster.dbscan_, cluster.hierarchical, cluster.k_means_, cluster.mean_shift_, cluster.optics_, cluster.spectral, covariance.elliptic_envelope, covariance.empirical_covariance_, covariance.graph_lasso_, covariance.robust_covariance, covariance.shrunk_covariance_, cross_decomposition.cca_, cross_decomposition.pls_, datasets.base, datasets.california_housing, datasets.covtype, datasets.kddcup99, datasets.lfw, datasets.olivetti_faces, datasets.openml, datasets.rcv1, datasets.samples_generator, datasets.species_distributions, datasets.svmlight_format, datasets.twenty_newsgroups, decomposition.base, decomposition.cdnmf_fast, decomposition.factor_analysis, decomposition.fastica_, decomposition.incremental_pca, decomposition.kernel_pca, decomposition.nmf, decomposition.online_lda, decomposition.online_lda_fast, decomposition.pca, decomposition.sparse_pca, decomposition.truncated_svd, ensemble.bagging, ensemble.base, ensemble.forest, ensemble.gradient_boosting, ensemble.iforest, ensemble.voting, ensemble.weight_boosting, feature_extraction.dict_vectorizer, feature_extraction.hashing, feature_extraction.stop_words, feature_selection.base, feature_selection.from_model, feature_selection.mutual_info, feature_selection.rfe, feature_selection.univariate_selection, feature_selection.variance_threshold, gaussian_process.gpc, gaussian_process.gpr, linear_model.base, linear_model.bayes, linear_model.cd_fast, linear_model.coordinate_descent, linear_model.huber, linear_model.least_angle, linear_model.logistic, linear_model.omp, linear_model.passive_aggressive, linear_model.perceptron, linear_model.ransac, linear_model.ridge, linear_model.sag, linear_model.sag_fast, linear_model.sgd_fast, linear_model.stochastic_gradient, linear_model.theil_sen, manifold.isomap, manifold.locally_linear, manifold.mds, manifold.spectral_embedding_, manifold.t_sne, metrics.base, metrics.classification, metrics.pairwise_fast, metrics.ranking, metrics.regression, metrics.scorer, mixture.base, mixture.bayesian_mixture, mixture.gaussian_mixture, neighbors.ball_tree, neighbors.base, neighbors.classification, neighbors.dist_metrics, neighbors.graph, neighbors.kd_tree, neighbors.kde, neighbors.lof, neighbors.nca, neighbors.nearest_centroid, neighbors.quad_tree, neighbors.regression, neighbors.typedefs, neighbors.unsupervised, neural_network.multilayer_perceptron, neural_network.rbm, preprocessing.data, preprocessing.label, semi_supervised.label_propagation, svm.base, svm.bounds, svm.classes, svm.liblinear, svm.libsvm, svm.libsvm_sparse, tree.export, tree.tree, utils.fast_dict, utils.mocking, utils.seq_dataset, utils.testing, utils.weight_vector.

How was this measured?

Each of 14 scikit-learn releases (the first of every minor from 0.22, plus the latest) was installed from PyPI in its own environment, the public names, __all__ and submodules of sklearn and 45 of its modules were listed, and getattr (or import, for a submodule) was run for the union of all names in every release. Releases: 0.22 (Python 3.8, NumPy 1.17.5), 0.23.0 (Python 3.8, NumPy 1.18.5), 0.24.0 (Python 3.9, NumPy 1.19.5), 1.0 (Python 3.9, NumPy 1.21.6), 1.1.0 (Python 3.10, NumPy 1.22.4), 1.2.0 (Python 3.10, NumPy 1.23.5), 1.3.0 (Python 3.11, NumPy 1.24.4), 1.4.0 (Python 3.12, NumPy 1.26.4), 1.5.0 (Python 3.12, NumPy 1.26.4), 1.6.0 (Python 3.12, NumPy 2.5.5), 1.7.0 (Python 3.12, NumPy 2.5.5), 1.8.0 (Python 3.12, NumPy 2.5.5), 1.9.0 (Python 3.12, NumPy 2.5.5), 1.9.1 (Python 3.12, NumPy 2.5.5). A name counts when it is in the module's __all__, or is a submodule, so names a file merely imported are left out. The replacement text is read from the installed source of the last release that had the name (its deprecation decorator or warnings.warn string, or the warning given on import). Removals before 0.22 (no Python 3.8 wheels) were read from the source at the 0.19.2, 0.20.0, 0.21.3 and 0.22 tags.

Patch releases were not read: a name removed in x.y.1 shows at the next minor.

Questions

How do I fix "cannot import name 'load_boston' from 'sklearn.datasets'"?

scikit-learn 1.2.0 (2022-12-08) removed load_boston; 1.0 and 1.1 warned that the dataset has an ethical problem. The warning suggests fetch_california_housing() or the Ames housing data (fetch_openml(name="house_prices", as_frame=True)), and shows how to read the original file from lib.stat.cmu.edu if you must reproduce old work. Or pin scikit-learn<1.2.

How do I fix "cannot import name 'plot_confusion_matrix' from 'sklearn.metrics'"?

scikit-learn 1.2.0 removed plot_confusion_matrix, plot_roc_curve, plot_precision_recall_curve and plot_det_curve (and inspection.plot_partial_dependence). Use the display classes: ConfusionMatrixDisplay.from_estimator(clf, X, y) or .from_predictions(y_true, y_pred), RocCurveDisplay.from_estimator, PrecisionRecallDisplay, DetCurveDisplay, PartialDependenceDisplay.

How do I fix "No module named 'sklearn.ensemble.forest'" when loading a pickle?

The pickle was written by scikit-learn 0.23 or earlier, which had public modules such as sklearn.ensemble.forest, sklearn.tree.tree and sklearn.linear_model.logistic; 0.24.0 (2020-12-22) removed 121 of them (0.22 and 0.23 warned). Load the file in an environment with the same scikit-learn version that wrote it (pip install "scikit-learn<0.24"), and save the model again from there in a format you can rebuild, or retrain it. In code, import from the package: from sklearn.ensemble import RandomForestClassifier.

How do I fix "cannot import name 'joblib' from 'sklearn.externals'"?

scikit-learn 0.23.0 (2020-05-12) removed the vendored copy. pip install joblib, then import joblib (joblib.dump, joblib.load). Old pickles that refer to sklearn.externals.joblib need scikit-learn<0.23 to load.

How do I fix "No module named 'sklearn.cross_validation'"?

scikit-learn 0.20.0 (2018-09-26) removed sklearn.cross_validation, grid_search and learning_curve; their contents are in sklearn.model_selection (train_test_split, KFold, GridSearchCV, learning_curve).

Sources

The same data as JSON: sklearn_names.json, licensed CC BY 4.0.

Related: "cannot import name 'triu' from 'scipy.linalg'" · "module 'numpy' has no attribute 'float_'" · "'DataFrame' object has no attribute 'append'".