How to Fix FutureWarning Messages in scikit-learn

Upcoming changes to the scikit-learn library for machine learning are reported through the use of FutureWarning messages when the code is run.

Warning messages can be confusing to beginners as it looks like there is a problem with the code or that they have done something wrong. Warning messages are also not good for operational code as they can obscure errors and program output.

There are many ways to handle a warning message, including ignoring the message, suppressing warnings, and fixing the code.

In this tutorial, you will discover FutureWarning messages in the scikit-learn API and how to handle them in your own machine learning projects.

After completing this tutorial, you will know:

  • FutureWarning messages are designed to inform you about upcoming changes to default values for arguments in the scikit-learn API.
  • FutureWarning messages can be ignored or suppressed as they do not halt the execution of your program.
  • Examples of FutureWarning messages and how to interpret the message and change your code to address the upcoming change.

Kick-start your project with my new book Machine Learning Mastery With Python, including step-by-step tutorials and the Python source code files for all examples.

Let’s get started.

How to Fix FutureWarning Messages in scikit-learn

How to Fix FutureWarning Messages in scikit-learn
Photo by a.dombrowski, some rights reserved.

Tutorial Overview

This tutorial is divided into four parts; they are:

  1. Problem of FutureWarnings
  2. How to Suppress FutureWarnings
  3. How to Fix FutureWarnings
  4. FutureWarning Recommendations

Problem of FutureWarnings

The scikit-learn library is an open-source library that offers tools for data preparation and machine learning algorithms.

It is a widely used and constantly updated library.

Like many actively maintained software libraries, the APIs often change over time. This may be because better practices are discovered or preferred usage patterns change.

Most functions available in the scikit-learn API have one or more arguments that let you customize the behavior of the function. Many arguments have sensible defaults so that you don’t have to specify a value for the arguments. This is particularly helpful when you are starting out with machine learning or with scikit-learn and you don’t know what impact each of the arguments has.

Change to the scikit-learn API over time often comes in the form of changes to the sensible defaults to arguments to functions. Changes of this type are often not performed immediately; instead, they are planned.

For example, if your code was written for a prior version of the scikit-learn library and relies on a default value for a function argument and a subsequent version of the API plans to change this default value, then the API will alert you to the upcoming change.

This alert comes in the form of a warning message each time your code is run. Specifically, a “FutureWarning” is reported on standard error (e.g. on the command line).

This is a useful feature of the API and the project, designed for your benefit. It allows you to change your code ready for the next major release of the library to either retain the old behavior (specify a value for the argument) or adopt the new behavior (no change to your code).

A Python script that reports warnings when it runs can be frustrating.

  • For a beginner, it may feel like the code is not working correctly, that perhaps you have done something wrong.
  • For a professional, it is a sign of a program that requires updating.

In either case, warning messages may obscure real error messages or output from the program.

How to Suppress FutureWarnings

Warning messages are not error messages.

As such, a warning message reported by your program, such as a FutureWarning, will not halt the execution of your program. The warning message will be reported and the program will carry on executing.

You can, therefore, ignore the warning each time your code is executed, if you wish.

It is also possible to programmatically ignore the warning messages. This can be done by suppressing warning messages when your program is run.

This can be achieved by explicitly configuring the Python warning system to ignore warning messages of a specific type, such as ignore all FutureWarnings, or more generally, to ignore all warnings.

This can be achieved by adding the following block around your code that you know will generate warnings:

Or, if you have a very simple flat script (no functions or blocks), you can suppress all FutureWarnings by adding two lines to the top of your file:

To learn more about suppressing in Python, see:

How to Fix FutureWarnings

Alternately, you can change your code to address the reported change to the scikit-learn API.

Typically, the warning message itself will instruct you on the nature of the change and how to change your code to address the warning.

Nevertheless, let’s look at a few recent examples of FutureWarnings that you may encounter and be struggling with.

The examples in this section were developed with scikit-learn version 0.20.2. You can check your scikit-learn version by running the following code:

You will see output like the following:

As new versions of scikit-learn are released over time, the nature of the warning messages reported will change and new defaults will be adopted.

As such, although the examples below are specific to a version of scikit-learn, the approach to diagnosing and addressing the nature of each API change and provide good examples for handling future changes.

FutureWarning for LogisticRegression

The LogisticRegression algorithm has two recent changes to the default argument values that result in FutureWarning messages.

The first has to do with the solver for finding coefficients and the second has to do with how the model should be used to make multi-class classifications. Let’s look at each with code examples.

Changes to the Solver

The example below will generate a FutureWarning about the solver argument used by LogisticRegression.

Running the example results in the following warning message:

This issue involves a change from the ‘solver‘ argument that used to default to ‘liblinear‘ and will change to default to ‘lbfgs‘ in a future version. You must now specify the ‘solver‘ argument.

To maintain the old behavior, you can specify the argument as follows:

To support the new behavior (recommended), you can specify the argument as follows:

Changes to the Multi-Class

The example below will generate a FutureWarning about the ‘multi_class‘ argument used by LogisticRegression.

Running the example results in the following warning message:

This warning message only affects the use of logistic regression for multi-class classification problems, instead of the binary classification problems for which the method was designed.

The default of the ‘multi_class‘ argument is changing from ‘ovr‘ to ‘auto‘.

To maintain the old behavior, you can specify the argument as follows:

To support the new behavior (recommended), you can specify the argument as follows:

FutureWarning for SVM

The support vector machine implementation has had a recent change to the ‘gamma‘ argument that results in a warning message, specifically the SVC and SVR classes.

The example below will generate a FutureWarning about the ‘gamma‘ argument used by SVC, but just as equally applies to SVR.

Running this example will generate the following warning message:

This warning message reports that the default for the ‘gamma‘ argument is changing from the current value of ‘auto‘ to a new default value of ‘scale‘.

The gamma argument only impacts SVM models that use the RBF, Polynomial, or Sigmoid kernel.

The parameter controls the value of the ‘gamma‘ coefficient used in the algorithm and if you do not specify a value, a heuristic is used to specify the value. The warning is about a change in the way that the default will be calculated.

To maintain the old behavior, you can specify the argument as follows:

To support the new behavior (recommended), you can specify the argument as follows:

FutureWarning for Decision Tree Ensemble Algorithms

The decision-tree based ensemble algorithms will change the number of sub-models or trees used in the ensemble controlled by the ‘n_estimators‘ argument.

This affects models’ random forest and extra trees for classification and regression, specifically the classes: RandomForestClassifier, RandomForestRegressor, ExtraTreesClassifier, ExtraTreesRegressor, and RandomTreesEmbedding.

The example below will generate a FutureWarning about the ‘n_estimators‘ argument used by RandomForestClassifier, but just as equally applies to RandomForestRegressor and the extra trees classes.

Running this example will generate the following warning message:

This warning message reports that the number of submodels is increasing from 10 to 100, likely because computers are getting faster and 10 is very small, even 100 is small.

To maintain the old behavior, you can specify the argument as follows:

To support the new behavior (recommended), you can specify the argument as follows:

More Future Warnings?

Are you struggling with a FutureWarning that is not covered?

Let me know in the comments below and I will do my best to help.

FutureWarning Recommendations

Generally, I do not recommend ignoring or suppressing warning messages.

Ignoring warning messages means that the message may obscure real errors or program output and that API future changes may negatively impact your program unless you have considered them.

Suppressing warnings might be a quick fix for R&D work, but should not be used in a production system. Worse than simply ignoring the messages, suppressing the warnings may also suppress messages from other APIs.

Instead, I recommend that you fix the warning messages in your software.

How should you change your code?

In general, I recommend almost always adopting the new behavior of the API, e.g. the new default, unless you explicitly rely on the prior behavior of the function.

For long-lived operational or production code, it might be a good idea to explicitly specify all function arguments and not use defaults, as they might be subject to change in the future.

I also recommend that you keep your scikit-learn library up to date, and keep track of the changes to the API in each new release.

The easiest way to do this is to review the release notes for each release, available here:

Further Reading

This section provides more resources on the topic if you are looking to go deeper.

Summary

In this tutorial, you discovered FutureWarning messages in the scikit-learn API and how to handle them in your own machine learning projects.

Specifically, you learned:

  • FutureWarning messages are designed to inform you about upcoming changes to default values for arguments in the scikit-learn API.
  • FutureWarning messages can be ignored or suppressed as they do not halt the execution of your program.
  • Examples of FutureWarning messages and how to interpret the message and change your code to address the upcoming change.

Do you have any questions?
Ask your questions in the comments below and I will do my best to answer.

Discover Fast Machine Learning in Python!

Master Machine Learning With Python

Develop Your Own Models in Minutes

...with just a few lines of scikit-learn code

Learn how in my new Ebook:
Machine Learning Mastery With Python

Covers self-study tutorials and end-to-end projects like:
Loading data, visualization, modeling, tuning, and much more...

Finally Bring Machine Learning To
Your Own Projects

Skip the Academics. Just Results.

See What's Inside

92 Responses to How to Fix FutureWarning Messages in scikit-learn

  1. Avatar
    Jesús February 27, 2019 at 1:44 am #

    Thanks for sharing your methodology for dealing with warnings.

  2. Avatar
    grapefruit June 13, 2019 at 6:30 pm #

    Great!That works for me, thanks!

  3. Avatar
    Mathias Sønderskov June 16, 2019 at 5:27 pm #

    how about this one on my model.fit()

    /usr/local/lib/python3.6/dist-packages/sklearn/utils/validation.py:724: DataConversionWarning: A column-vector y was passed when a 1d array was expected. Please change the shape of y to (n_samples, ), for example using ravel().
    y = column_or_1d(y, warn=True)

    all the best,
    Mathias

    • Avatar
      Jason Brownlee June 17, 2019 at 8:18 am #

      Try this:

  4. Avatar
    KKG July 2, 2019 at 3:42 pm #

    /home/keerat/anaconda3/lib/python3.7/site-packages/sklearn/svm/base.py:931: ConvergenceWarning: Liblinear failed to converge, increase the number of iterations.
    “the number of iterations.”, ConvergenceWarning)

    What about this?

    • Avatar
      Jason Brownlee July 3, 2019 at 8:21 am #

      That suggest that the data is not appropriate for the model. You may need to scale the data or select different data.

  5. Avatar
    Virginia Perez Perez July 10, 2019 at 2:02 am #

    I begin to learn Python and I found your article about warnings. Thank you for your article.

  6. Avatar
    Dennis Peters August 11, 2019 at 10:26 pm #

    Thank you Jason, love your posts!

  7. Avatar
    IKRAM November 9, 2019 at 1:23 pm #

    Hi Jason,
    Thank you for ALL..
    What do you recommand for the following warning: (MLP for multiclass classification)

    Python37\lib\site-packages\sklearn\neural_network\multilayer_perceptron.py:566: ConvergenceWarning: Stochastic Optimizer: Maximum iterations (200) reached and the optimization hasn’t converged yet. % self.max_iter, ConvergenceWarning)

    • Avatar
      Jason Brownlee November 10, 2019 at 8:15 am #

      Perhaps try increasing the number of iterations for the solver?
      Perhaps try a different solver?
      Perhaps try scaling the data prior to fitting the model?

  8. Avatar
    kitojo December 1, 2019 at 3:21 pm #

    Warning: The least populated class in y has only 1 members, which is too few. The minimum number of members in any class cannot be less than n_splits=5.

    • Avatar
      Jason Brownlee December 2, 2019 at 5:59 am #

      This suggests a problem with your data.

      Specifically that you only have 1 example of one of the classes.

      Perhaps you can collect more/different data?
      Perhaps you can remove the class with one example?

  9. Avatar
    Yang January 9, 2020 at 1:30 am #

    /anaconda3/lib/python3.7/site-packages/sklearn/model_selection/_split.py:2053: FutureWarning: You should specify a value for ‘cv’ instead of relying on the default value. The default value will change from 3 to 5 in version 0.22.
    warnings.warn(CV_WARNING, FutureWarning)

    • Avatar
      Jason Brownlee January 9, 2020 at 7:28 am #

      Nice!

      Set to 3 for the old behavior or set to 5 for the new behavior. Probably set to 5.

  10. Avatar
    Sara January 28, 2020 at 8:50 pm #

    /anaconda3/lib/python3.7/site-packages/sklearn/externals/joblib/__init__.py:15: FutureWarning: sklearn.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+.
    warnings.warn(msg, category=FutureWarning)

    FutureWarning: The sklearn.metrics.scorer module is deprecated in version 0.22 and will be removed in version 0.24. The corresponding classes / functions should instead be imported from sklearn.metrics. Anything that cannot be imported from sklearn.metrics is now part of the private API.
    warnings.warn(message, FutureWarning)

    • Avatar
      Jason Brownlee January 29, 2020 at 6:35 am #

      Yes, the first warning suggests using the joblib API directly.

      The second warning succests importing your scoring function from sklearn.metrics.

  11. Avatar
    Nikhila January 30, 2020 at 9:02 pm #

    How to solve this error?IN ORDER TO PRINT SSE VALUE FOR FUZZY C-MEANS CLUSTERING TECHNIQUE

    FutureWarning: The sklearn.datasets.samples_generator module is deprecated in version 0.22 and will be removed in version 0.24. The corresponding classes / functions should instead be imported from sklearn.datasets. Anything that cannot be imported from sklearn.datasets is now part of the private API.
    warnings.warn(message, FutureWarning)

    i am using scikit learn of version 0.22.1 for python 3.7 version.

    • Avatar
      Jason Brownlee January 31, 2020 at 7:46 am #

      Change your import from sklearn.datasets.samples_generator to sklearn.datasets

  12. Avatar
    Nikhila January 31, 2020 at 4:31 pm #

    Thank you so much sir…its resolved..!!

  13. Avatar
    Premanand February 3, 2020 at 9:33 pm #

    file:///C:/Users/91735/Anaconda3/lib/site-packages/sklearn/externals/joblib/__init__.py:15: DeprecationWarning: sklearn.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+. warnings.warn(msg, category=DeprecationWarning)

    • Avatar
      Jason Brownlee February 4, 2020 at 7:52 am #

      Change your import from “sklearn.externals.joblib” to “joblib”

  14. Avatar
    Ashraf Al-Warraquiy March 31, 2020 at 7:16 am #

    Great Thanks Dr Jason

  15. Avatar
    Toàn Đỗ April 14, 2020 at 1:19 am #

    E:\Anaconda3\New folder\envs\ML scikit learn\lib\site-packages\sklearn\tree\_classes.py:1233: FutureWarning: the classes_ attribute is to be deprecated from version 0.22 and will be removed in 0.24.
    warnings.warn(msg, FutureWarning)

    • Avatar
      Jason Brownlee April 14, 2020 at 6:21 am #

      Interesting, I have not seen this one before.

      What model were you using? A decision tree of some kind?

  16. Avatar
    ANES RADMAN April 15, 2020 at 6:08 pm #

    Hello, i got the following Error while usiing the LogisticRegression algorithm.

    F:\Python_Anaconda_Software\lib\site-packages\sklearn\linear_model\logistic.py:432: FutureWarning: Default solver will be changed to ‘lbfgs’ in 0.22. Specify a solver to silence this warning.

    FutureWarning)
    —————————————————————————

    ValueError Traceback (most recent call last)
    in
    —-> 1 log.fit(X_train,y_train)

    F:\Python_Anaconda_Software\lib\site-packages\sklearn\linear_model\logistic.py in fit(self, X, y, sample_weight)
    1530
    1531 X, y = check_X_y(X, y, accept_sparse=’csr’, dtype=_dtype, order=”C”,
    -> 1532 accept_large_sparse=solver != ‘liblinear’)
    1533 check_classification_targets(y)
    1534 self.classes_ = np.unique(y)

    F:\Python_Anaconda_Software\lib\site-packages\sklearn\utils\validation.py in check_X_y(X, y, accept_sparse, accept_large_sparse, dtype, order, copy, force_all_finite, ensure_2d, allow_nd, multi_output, ensure_min_samples, ensure_min_features, y_numeric, warn_on_dtype, estimator)
    717 ensure_min_features=ensure_min_features,
    718 warn_on_dtype=warn_on_dtype,
    –> 719 estimator=estimator)
    720 if multi_output:
    721 y = check_array(y, ‘csr’, force_all_finite=True, ensure_2d=False,

    F:\Python_Anaconda_Software\lib\site-packages\sklearn\utils\validation.py in check_array(array, accept_sparse, accept_large_sparse, dtype, order, copy, force_all_finite, ensure_2d, allow_nd, ensure_min_samples, ensure_min_features, warn_on_dtype, estimator)
    494 try:
    495 warnings.simplefilter(‘error’, ComplexWarning)
    –> 496 array = np.asarray(array, dtype=dtype, order=order)
    497 except ComplexWarning:
    498 raise ValueError(“Complex data not supported\n”

    F:\Python_Anaconda_Software\lib\site-packages\numpy\core\numeric.py in asarray(a, dtype, order)
    536
    537 “””
    –> 538 return array(a, dtype, copy=False, order=order)
    539
    540

    ValueError: could not convert string to float: ‘E12’

    • Avatar
      Jason Brownlee April 16, 2020 at 5:59 am #

      Perhaps try changing the solver to ‘lbfgs’ as a first step.

      Then look at your data and convert at least one of your columns to numbers using an integer encoding or a one hot encoding.

  17. Avatar
    AnalyticAscent May 19, 2020 at 8:49 am #

    I appreciate that you’re still making posts like these!

    First found your site three years ago when I started ML projects, and it’s nice to see your site is still just as relevant and useful today as it was back then.

    Keep it up! 😀

  18. Avatar
    raakeshsri May 23, 2020 at 4:56 am #

    FutureWarning: The default value of gamma will change from ‘auto’ to ‘scale’ in version 0.22 to account better for unscaled features. Set gamma explicitly to ‘auto’ or ‘scale’ to avoid this warning.
    “avoid this warning.”, FutureWarning)

  19. Avatar
    Jamie Walker June 2, 2020 at 11:39 pm #

    Hi Jason,

    How would you go about fixing this future warning?

    FutureWarning: The sklearn.ensemble.bagging module is deprecated in version 0.22 and will be removed in version 0.24. The corresponding classes / functions should instead be imported from sklearn.ensemble. Anything that cannot be imported from sklearn.ensemble is now part of the private API.

    Thanks

    • Avatar
      Jason Brownlee June 3, 2020 at 7:59 am #

      Try changing the import statement to sklearn.ensemble as suggested?

  20. Avatar
    Laís June 26, 2020 at 11:06 pm #

    I’m getting this warning, how can I resolve it?
    FutureWarning: Function safe_indexing is deprecated; safe_indexing is deprecated in version 0.22 and will be removed in version 0.24. warnings.warn(msg, category=FutureWarning)

    Thank you in advance!

    • Avatar
      Jason Brownlee June 27, 2020 at 5:32 am #

      Interesting, I have not seen that before, what function or class are you using?

      • Avatar
        Nevo September 16, 2020 at 12:59 am #

        I’m getting this warning, using SMOTE:

        sm = SMOTE(random_state=SEED)
        X_train, y_train = sm.fit_sample(X_train, y_train)

  21. Avatar
    Rohit Sharma July 3, 2020 at 6:52 pm #

    AttributeError: Can’t get attribute ‘DeprecationDict’ on
    Getting this error along with ” FutureWarning: The sklearn.metrics.regression module is deprecated in version 0.22 and will be removed in version 0.24. The corresponding classes / functions should instead be imported from sklearn.metrics. Anything that cannot be imported from sklearn.metrics is now part of the private API.” this kind of warnings. Please help me.

    • Avatar
      Jason Brownlee July 4, 2020 at 5:54 am #

      Interesting, I have not seen this one before.

      Perhaps check what metrics you are importing and see if you can import them directly?

  22. Avatar
    Regine August 30, 2020 at 7:36 pm #

    Hi Thanks for the useful tips!

    I am following this website (https://www.scikit-yb.org/en/latest/api/model_selection/rfecv.html#:~:text=Recursive%20feature%20elimination%20(RFE)%20is,number%20of%20features%20is%20reached.&text=RFE%20requires%20a%20specified%20number,how%20many%20features%20are%20valid.) to do Recursive Feature Elimination.

    When I run the following codes:
    from sklearn.ensemble import RandomForestClassifier
    from sklearn.model_selection import StratifiedKFold

    from yellowbrick.model_selection import rfecv
    from yellowbrick.datasets import load_credit

    I received this future warning message:
    FutureWarning: The sklearn.metrics.classification module is deprecated in version 0.22 and will be removed in version 0.24. The corresponding classes / functions should instead be imported from sklearn.metrics. Anything that cannot be imported from sklearn.metrics is now part of the private API.
    warnings.warn(message, FutureWarning)

    I am new in Python. Hope to receive advice from you! Thanks!

    • Avatar
      Jason Brownlee August 31, 2020 at 6:14 am #

      You can safely ignore the warning.

      Perhaps the yellowbrick API requires an update, e.g. out of your control.

  23. Avatar
    Eva September 21, 2020 at 9:43 pm #

    Hey, thank you for the tips! I’m getting a different warning and I was hoping you could help, here it is:
    FutureWarning: Pass param_name=polynomialfeatures__degree, param_range=[ 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20] as keyword args. From version 0.25 passing these as positional arguments will result in an error
    FutureWarning)

    Thank you in advance!

    • Avatar
      Jason Brownlee September 22, 2020 at 6:45 am #

      Perhaps try providing the parameters as named arguments as suggested in the warning?

  24. Avatar
    Abdullah November 22, 2020 at 11:28 pm #

    Hi Jason,

    How would you go about fixing this future warning?

    FutureWarning: The sklearn.metrics.regression module is deprecated in version 0.22 and will be removed in version 0.24. The corresponding classes / functions should instead be imported from sklearn.metrics. Anything that cannot be imported from sklearn.metrics is now part of the private API.
    warnings.warn(message, FutureWarning)

    Best regars,

    • Avatar
      Jason Brownlee November 23, 2020 at 6:16 am #

      Try importing your metric directly from: sklearn.metrics

      Delete the .regression part of the import statement.

  25. Avatar
    Rodica December 17, 2020 at 1:52 am #

    Hi Jason,

    Thank you so much for the helpful posts and ebooks!

    How about this:
    lib/python3.7/site-packages/sklearn/utils/validation.py:70: FutureWarning: Pass classes=[0 1 2], y=136 2
    29 0
    226 2
    254 2
    66 0
    ..
    165 2
    241 2
    484 0
    448 2
    360 2
    Name: label, Length: 690, dtype: int64 as keyword args. From version 0.25 passing these as positional arguments will result in an error
    FutureWarning)

    • Avatar
      Jason Brownlee December 17, 2020 at 6:37 am #

      Sorry, I’m not sure about this one. Perhaps try stackoverflow.com

  26. Avatar
    Joe May 1, 2021 at 2:10 am #

    Thank you for this nice article. It helps a lot.

    I am not sure how to solve these two future warnings:

    UserWarning: Trying to unpickle estimator RandomForestClassifier from version 0.23.1 when using version 0.24.1. This might lead to breaking code or invalid results. Use at your own risk.

    /Users/joe/.virtualenvs/venv/scripts2/lib/python3.6/site-packages/sklearn/utils/validation.py:72: FutureWarning: Pass input=[‘refactor: update requirements file \n\n- I added the django-test library to generate testing data\n\n- the docker library will be used in the perf testing script’, ‘refactor: update perf testing script to use the new fixtures’] as keyword args. From version 1.0 (renaming of 0.25) passing these as positional arguments will result in an error
    “will result in an error”, FutureWarning)

    • Avatar
      Jason Brownlee May 1, 2021 at 6:08 am #

      Perhaps you can load then re-save your model with your current system to fix the first one? Try it and see.

      Not sure about the second sorry.

  27. Avatar
    Dhruvanshu Parmar May 9, 2021 at 11:14 pm #

    Hi Jason,
    I was trying to understand k-fold cross-validation, and I somehow copy pasted your code:

    # scikit-learn k-fold cross-validation
    from numpy import array
    from sklearn.model_selection import KFold
    # data sample
    data = array([0.1, 0.2, 0.3, 0.4, 0.5, 0.6])
    # prepare cross validation
    kfold = KFold(3, True, 1)
    # enumerate splits
    for train, test in kfold.split(data):
    print(‘train: %s, test: %s’ % (data[train], data[test]))

    I am getting the following warnings:
    Warning (from warnings module):
    File “C:\Users\Dhruvanshu\AppData\Local\Programs\Python\Python38\lib\site-packages\sklearn\utils\validation.py”, line 70
    warnings.warn(f”Pass {args_msg} as keyword args. From version ”
    FutureWarning: Pass shuffle=True as keyword args. From version 1.0 (renaming of 0.25) passing these as positional arguments will result in an error

    • Avatar
      Dhruvanshu Parmar May 9, 2021 at 11:15 pm #

      My device has sklearn version 0.24.1

    • Avatar
      Jason Brownlee May 10, 2021 at 6:22 am #

      Perhaps specify the variable names to the constructor, e.g. n_splits=3, shuffle=True, random_state=1

      • Avatar
        Dhruvanshu Parmar May 13, 2021 at 4:15 am #

        Hi Jason,
        Thanks, that worked.
        Also, just wanted to say that your blog has helped me a lot when I was stuck trying to understand some concepts.

  28. Avatar
    Mina Naseh July 23, 2021 at 5:44 pm #

    Hey Jason,
    Thanks a lot for this useful article.
    I am using google colaboratory and I don’t know how to fix these future warnings:

    from importing these:

    from imblearn.over_sampling import SMOTE
    from imblearn.under_sampling import RandomUnderSampler

    I get these:

    /usr/local/lib/python3.7/dist-packages/sklearn/externals/six.py:31: FutureWarning: The 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/).
    “(https://pypi.org/project/six/).”, FutureWarning)
    /usr/local/lib/python3.7/dist-packages/sklearn/utils/deprecation.py:144: FutureWarning: The sklearn.neighbors.base module is deprecated in version 0.22 and will be removed in version 0.24. The corresponding classes / functions should instead be imported from sklearn.neighbors. Anything that cannot be imported from sklearn.neighbors is now part of the private API.
    warnings.warn(message, FutureWarning)

    • Avatar
      Jason Brownlee July 24, 2021 at 5:13 am #

      Perhaps try running code on a system where you have control over the library versions.

  29. Avatar
    seshasai July 27, 2021 at 3:31 pm #

    thank you so much. the code works well.

  30. Avatar
    Maria July 29, 2021 at 10:49 pm #

    Hi Jason, I love your site and it has helped me endlessly when I hit a problem. I wonder if you could help me with this Future Warning as I am struggling to resolve it…

    I am splitting my dataframe data into X_data and Y_data and converting to np.array ready for KMeans clustering. X_data is the dataframe with the two target variable columns dropped, and Y_data is the the two target variable columns from the dataframe. Once split I am oversampling using SMOTE.

    Here is the code and the future warning
    oversample = SMOTE()
    X_data = np.array(complete_dataset.drop([‘target1’, ‘target2’],1))
    subset = complete_dataset[[‘target1’, ‘target2’]]
    y_data = np.array(subset)
    X_data, y_data = oversample.fit_resample(X_data, y_data)

    /Users/maria/opt/anaconda3/lib/python3.8/site-packages/sklearn/utils/validation.py:70: FutureWarning: Pass classes=[0 1] as keyword args. From version 1.0 (renaming of 0.25) passing these as positional arguments will result in an error
    warnings.warn(f”Pass {args_msg} as keyword args. From version “

    • Avatar
      Jason Brownlee July 30, 2021 at 6:29 am #

      Sorry, I’ve not seen this error. You might need to check the API docs.

  31. Avatar
    CuongPham November 8, 2021 at 1:04 pm #

    I encounterd this FutureWarning when I run my code, I found out the reason from wb.save(filename= out_file) because when I remove it then the Warning disappeared.
    I do not seen any related b/w wb.save with below WARNING. Could you please give me a recommendation? Do we need to solve it or ignore?

    WARNING:
    /common/appl/python/anaconda3-5.2.0/lib/python3.6/site-packages/openpyxl/comments/shape_writer.py:75: FutureWarning: The behavior of this method will change in future versions. Use specific ‘len(elem)’ or ‘elem is not None’ test instead.
    if not shape_types:

    • Adrian Tam
      Adrian Tam November 14, 2021 at 12:07 pm #

      That’s from Openpyxl, probably you have to ignore the error or wait for a version upgrade to fix it.

      • Avatar
        CuongPham November 15, 2021 at 11:45 pm #

        Thank you so much.
        Temporarily I ignored it.

  32. Avatar
    Sulthana November 20, 2021 at 12:28 am #

    FutureWarning: ‘normalize’ was deprecated in version 1.0 and will be removed in 1.2. Please leave the normalize parameter to its default value to silence this warning. The default behavior of this estimator is to not do any normalization. If normalization is needed please use sklearn.preprocessing.StandardScaler instead.

    How can I silence this warning. I’m using class sklearn.linear_model.ElasticNet.

    Thank you!

    • Adrian Tam
      Adrian Tam November 20, 2021 at 2:40 am #

      As the message suggested, do not use normalize but use the StandardScaler separately. This is the sure way to mute it.

  33. Avatar
    Sulthana November 21, 2021 at 9:31 pm #

    I do not want to normalize and I’m setting normalize to its default value which is ‘False’. It still shows the warning.

    • Adrian Tam
      Adrian Tam November 23, 2021 at 1:10 pm #

      I think leave it to default means you do not even mention about it in the parameter. Can you try?

      • Avatar
        Goriola July 15, 2022 at 1:16 am #

        This worked for me. Thank you so much!

  34. Avatar
    Perchio December 20, 2021 at 6:36 pm #

    I tried to fix the error myself, but I couldn’t succeed.

    I was reading a well-written book about NLP. The examples inside all feature a todense() method call:

    Problem with todense() is it returns an np.matrix, so I get:

    FutureWarning: np.matrix usage is deprecated in 1.0 and will raise a TypeError in 1.2. Please convert to a numpy array with np.asarray. (I’m using 1.0.1).

    I tried to convert to asarray and other conversions but anything I tried causes next code to fail probably because cosine_similarity function expects a certain kind of data type.

    • Avatar
      James Carmichael February 15, 2022 at 12:47 pm #

      Hi Perchio…I am most able to help address specific questions regarding the code listings within the tutorial and/or our other content.

  35. Avatar
    Daniel April 14, 2022 at 5:25 pm #

    FutureWarning: Feature names only support names that are all strings. Got feature names with dtypes: [‘int’, ‘str’]. An error will be raised in 1.2.FutureWarning.

    I believe this is due to using encoding features with sklearn.preprocessing.OneHotEncoder, which onehotencodes features as 0.1.2.3.4.5…..N.
    Pd.dummies doesn’t have this problem (does featurename + number), but is not as flexible as the OneHotEncoder. Not sure how to find a workaround.

  36. Avatar
    Rodrigo Joaquim Almeida August 13, 2022 at 3:44 am #

    I found many notebooks with same error, but no one gave me back a solution to this issue:

    X_train = data_train.date[:, np.newaxis]

    “Support for multi-dimensional indexing (e.g. obj[:, None]) is deprecated and will be removed in a future version.”

    So, after looking for some answers i found this:

    instead using ndarray, use just an array and them reshape it from an 1D array to 2D array with array.reshape(-1, 1) and it will be done

    from sklearn.tree import DecisionTreeRegressor

    data_train = ram_prices[ram_prices.date = 2000]

    X_train = np.array(data_train.date)
    X_train = X_train.reshape(-1, 1)
    y_train = np.log(data_train.price)

    tree = DecisionTreeRegressor().fit(X_train, y_train)
    linear_reg = LinearRegression().fit(X_train, y_train)

    X_all = np.array(ram_prices.date)
    X_all = X_all.reshape(-1, 1)

    pred_tree = tree.predict(X_all)
    pred_lr = linear_reg.predict(X_all)

    price_tree = np.exp(pred_tree)
    price_lr = np.exp(pred_lr)

    • Avatar
      James Carmichael August 13, 2022 at 6:01 am #

      Thank you Rodrigo! Keep up the great work!

  37. Avatar
    Rodrigo Joaquim Almeida August 13, 2022 at 3:46 am #

    Solved problem in [66] ndarray DecisionTreeRegressor page 81

    • Avatar
      James Carmichael August 13, 2022 at 6:00 am #

      Thank you for the feedback Rodrigo!

  38. Avatar
    Adam October 19, 2022 at 1:10 am #

    Hi James – Thank you so much for this wonderful article and for being so active in the comments. I fall into the beginner category, so apologies if it’s a basic question but I was wondering if you could help with the error below:

    FutureWarning: Feature names only support names that are all strings. Got feature names with dtypes: [‘tuple’]. An error will be raised in 1.2.

    My ‘two cents’ is I think it has to do with the fact my column headers have two levels so when I reference them in ‘predictors I need to use [(“A,B”),(“C,D”)] but I don’t know how else to do it…..Please help 🙂

  39. Avatar
    Dione March 3, 2023 at 9:50 pm #

    Hi ,

    I’m getting the following future warning when I try to use knn.predict or knn.score for KNN model. I silenced the warning with a warnings filter for now, but how can I solve it? Thank you.

    FutureWarning: Unlike other reduction functions (e.g. skew, kurtosis), the default behavior of mode typically preserves the axis it acts along. In SciPy 1.11.0, this behavior will change: the default value of keepdims will become False, the axis over which the statistic is taken will be eliminated, and the value None will no longer be accepted. Set keepdims to True or False to avoid this warning.
    mode, _ = stats.mode(_y[neigh_ind, k], axis=1)

  40. Avatar
    RODRIGO April 20, 2023 at 9:04 am #

    I am running

    model=Summarizer()
    model(docToRead, num_sentences=2)

    and it gives me the message:
    /usr/local/lib/python3.9/dist-packages/sklearn/cluster/_kmeans.py:870: FutureWarning:

    The default value of n_init will change from 10 to ‘auto’ in 1.4. Set the value of n_init explicitly to suppress the warning

    which is weird because I am calling just the summarizer, so I do not even know how to change n_init for Kmeans. Actually, Kmeans is called (most likely) directly from the Summarizer() function directly.

  41. Avatar
    Mehdi February 23, 2024 at 9:06 am #

    I had this error when I was using grid_search with xgboost.
    …FutureWarning: Pass sample_weight=…

    It seems the scorer I was passing had an issue. This solved the problem:

    from sklearn.metrics import r2_score, mean_squared_error
    from sklearn.metrics import make_scorer
    my_scorer = make_scorer(mean_squared_error, greater_is_better=False)

    • Avatar
      James Carmichael February 23, 2024 at 10:20 am #

      Thank you Mehdi for sharing your suggestion!

Leave a Reply