Last Updated on August 21, 2019
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
Photo by a.dombrowski, some rights reserved.
Tutorial Overview
This tutorial is divided into four parts; they are:
- Problem of FutureWarnings
- How to Suppress FutureWarnings
- How to Fix FutureWarnings
- 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:
1 2 3 4 5 6 |
# run block of code and catch warnings with warnings.catch_warnings(): # ignore all caught warnings warnings.filterwarnings("ignore") # execute code that 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:
1 2 3 4 |
# import warnings filter from warnings import simplefilter # ignore all future warnings simplefilter(action='ignore', category=FutureWarning) |
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:
1 2 3 |
# check scikit-learn version import sklearn print('sklearn: %s' % sklearn.__version__) |
You will see output like the following:
1 |
sklearn: 0.20.2 |
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.
1 2 3 4 5 6 7 8 9 |
# example of LogisticRegression that generates a FutureWarning from sklearn.datasets import make_blobs from sklearn.linear_model import LogisticRegression # prepare dataset X, y = make_blobs(n_samples=100, centers=2, n_features=2) # create and configure model model = LogisticRegression() # fit model model.fit(X, y) |
Running the example results in the following warning message:
1 |
FutureWarning: Default solver will be changed to 'lbfgs' in 0.22. Specify a solver to silence this warning. |
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:
1 2 |
# create and configure model model = LogisticRegression(solver='liblinear') |
To support the new behavior (recommended), you can specify the argument as follows:
1 2 |
# create and configure model model = LogisticRegression(solver='lbfgs') |
Changes to the Multi-Class
The example below will generate a FutureWarning about the ‘multi_class‘ argument used by LogisticRegression.
1 2 3 4 5 6 7 8 9 |
# example of LogisticRegression that generates a FutureWarning from sklearn.datasets import make_blobs from sklearn.linear_model import LogisticRegression # prepare dataset X, y = make_blobs(n_samples=100, centers=3, n_features=2) # create and configure model model = LogisticRegression(solver='lbfgs') # fit model model.fit(X, y) |
Running the example results in the following warning message:
1 |
FutureWarning: Default multi_class will be changed to 'auto' in 0.22. Specify the multi_class option to silence this warning. |
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:
1 2 |
# create and configure model model = LogisticRegression(solver='lbfgs', multi_class='ovr') |
To support the new behavior (recommended), you can specify the argument as follows:
1 2 |
# create and configure model model = LogisticRegression(solver='lbfgs', multi_class='auto') |
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.
1 2 3 4 5 6 7 8 9 |
# example of SVC that generates a FutureWarning from sklearn.datasets import make_blobs from sklearn.svm import SVC # prepare dataset X, y = make_blobs(n_samples=100, centers=2, n_features=2) # create and configure model model = SVC() # fit model model.fit(X, y) |
Running this example will generate the following warning message:
1 |
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. |
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:
1 2 |
# create and configure model model = SVC(gamma='auto') |
To support the new behavior (recommended), you can specify the argument as follows:
1 2 |
# create and configure model model = SVC(gamma='scale') |
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.
1 2 3 4 5 6 7 8 9 |
# example of RandomForestClassifier that generates a FutureWarning from sklearn.datasets import make_blobs from sklearn.ensemble import RandomForestClassifier # prepare dataset X, y = make_blobs(n_samples=100, centers=2, n_features=2) # create and configure model model = RandomForestClassifier() # fit model model.fit(X, y) |
Running this example will generate the following warning message:
1 |
FutureWarning: The default value of n_estimators will change from 10 in version 0.20 to 100 in 0.22. |
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:
1 2 |
# create and configure model model = RandomForestClassifier(n_estimators=10) |
To support the new behavior (recommended), you can specify the argument as follows:
1 2 |
# create and configure model model = RandomForestClassifier(n_estimators=100) |
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.
- Python Warning control API
- sklearn.linear_model.LogisticRegression API
- sklearn.svm.SVC API
- sklearn.svm.SVR API
- scikit-learn Release History
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.
Thanks for sharing your methodology for dealing with warnings.
You’re welcome, I hope that it helps.
Great!That works for me, thanks!
I’m very happy to hear that!
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
Try this:
/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?
That suggest that the data is not appropriate for the model. You may need to scale the data or select different data.
I begin to learn Python and I found your article about warnings. Thank you for your article.
Thanks, I’m glad it helped.
Thank you Jason, love your posts!
You’re welcome Dennis.
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)
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?
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.
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?
/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)
Nice!
Set to 3 for the old behavior or set to 5 for the new behavior. Probably set to 5.
/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)
Yes, the first warning suggests using the joblib API directly.
The second warning succests importing your scoring function from sklearn.metrics.
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.
Change your import from sklearn.datasets.samples_generator to sklearn.datasets
Thank you so much sir…its resolved..!!
I’m happy to hear that.
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)
Change your import from “sklearn.externals.joblib” to “joblib”
Great Thanks Dr Jason
You’re welcome.
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)
Interesting, I have not seen this one before.
What model were you using? A decision tree of some kind?
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’
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.
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! 😀
Thanks!
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)
Try setting gamma to ‘scale’.
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
Try changing the import statement to sklearn.ensemble as suggested?
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!
Interesting, I have not seen that before, what function or class are you using?
I’m getting this warning, using SMOTE:
sm = SMOTE(random_state=SEED)
X_train, y_train = sm.fit_sample(X_train, y_train)
What warning?
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.
Interesting, I have not seen this one before.
Perhaps check what metrics you are importing and see if you can import them directly?
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!
You can safely ignore the warning.
Perhaps the yellowbrick API requires an update, e.g. out of your control.
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!
Perhaps try providing the parameters as named arguments as suggested in the warning?
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,
Try importing your metric directly from: sklearn.metrics
Delete the .regression part of the import statement.
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)
Sorry, I’m not sure about this one. Perhaps try stackoverflow.com
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)
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.
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
My device has sklearn version 0.24.1
Perhaps specify the variable names to the constructor, e.g. n_splits=3, shuffle=True, random_state=1
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.
Well done!
Thanks for your kind words.
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)
Perhaps try running code on a system where you have control over the library versions.
thank you so much. the code works well.
You’re welcome!
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 “
Sorry, I’ve not seen this error. You might need to check the API docs.
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:
That’s from Openpyxl, probably you have to ignore the error or wait for a version upgrade to fix it.
Thank you so much.
Temporarily I ignored it.
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!
As the message suggested, do not use normalize but use the StandardScaler separately. This is the sure way to mute it.
I do not want to normalize and I’m setting normalize to its default value which is ‘False’. It still shows the warning.
I think leave it to default means you do not even mention about it in the parameter. Can you try?
This worked for me. Thank you so much!
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.
Hi Perchio…I am most able to help address specific questions regarding the code listings within the tutorial and/or our other content.
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.
Hi Daniel…You may find the following of interest:
https://python.tutorialink.com/pytest-how-to-locate-a-futurewarning-and-fix-it/
Hi Daniel, did u find the solution?
I fixed that issue by added a prefix to the class name, here is an example on titanic dataset:
pclass=pd.get_dummies(mydata[‘Pclass’], drop_first=True, prefix=’pc’)
Getting this future warning.
https://github.com/paulgureghian/Python_Notebooks/blob/main/Create_Cust_Segments/Identify_Cust_Segments/identify_cust_segments.ipynb
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)
Thank you Rodrigo! Keep up the great work!
Solved problem in [66] ndarray DecisionTreeRegressor page 81
Thank you for the feedback Rodrigo!
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 🙂
Hi Adam…You are very welcome! The following may be of interest to you:
https://machinelearningmastery.com/how-to-fix-futurewarning-messages-in-scikit-learn/
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 ofmode
typically preserves the axis it acts along. In SciPy 1.11.0, this behavior will change: the default value ofkeepdims
will become False, theaxis
over which the statistic is taken will be eliminated, and the value None will no longer be accepted. Setkeepdims
to True or False to avoid this warning.mode, _ = stats.mode(_y[neigh_ind, k], axis=1)
Hi Dione…The following discussion may prove helpful:
https://stackoverflow.com/questions/74406936/knn-python-implementation
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 ofn_init
explicitly to suppress the warningwhich 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.
Hi Rodrigo…The following resources may be of interest to you:
https://github.com/scikit-learn/scikit-learn/discussions/25016
https://scikit-learn.org/stable/modules/generated/sklearn.cluster.k_means.html