简体   繁体   中英

SKLearn: TypeError: __init__() got an unexpected keyword argument n_splits

I'm trying to use SKLearn (version 0.18.1) as follows:

from sklearn.model_selection import KFold
kfold = KFold(n_splits=5, random_state=100)

But I get this strange error:

---------------------------------------------------------------------------
TypeError                                 Traceback (most recent call last)
<ipython-input-17-b8dd4f5596be> in <module>()
----> 1 kfold = KFold(k=5, random_state=100)
      2 results = cross_val_score(estimator, X, Y, cv=kfold)
      3 print("Results: %.2f (%.2f) MSE" % (results.mean(), results.std()))

TypeError: __init__() got an unexpected keyword argument 'k'

I've consulted the docs here:

http://scikit-learn.org/stable/modules/generated/sklearn.model_selection.KFold.html

and n_splits does look like a parameter I should be able to pass...

Any idea what's going on here / how to fix?

Thanks!

Open your terminal (cmd) and try these before you try to import the sklearn.

pip install -U scikit-learn

or if you have anaconda installed

conda install scikit-learn

or

conda update conda 
conda update scikit-learn

Also make sure your have numpy and scipy:

pip install numpy 
pip install scipy

Restart the python shell after installing scipy !

You have a problem with your Scikit-Learn version, try to check it and look for the right documentation ( here ):

import sklearn
print(sklearn.__version__)

Or download the lastest version with pip install -U scikit-learn .

I'm trying to use SKLearn (version 0.18.1) as follows:

from sklearn.model_selection import KFold
kfold = KFold(n_splits=5, random_state=100)

But I get this strange error:

---------------------------------------------------------------------------
TypeError                                 Traceback (most recent call last)
<ipython-input-17-b8dd4f5596be> in <module>()
----> 1 kfold = KFold(k=5, random_state=100)
      2 results = cross_val_score(estimator, X, Y, cv=kfold)
      3 print("Results: %.2f (%.2f) MSE" % (results.mean(), results.std()))

TypeError: __init__() got an unexpected keyword argument 'k'

I've consulted the docs here:

http://scikit-learn.org/stable/modules/generated/sklearn.model_selection.KFold.html

and n_splits does look like a parameter I should be able to pass...

Any idea what's going on here / how to fix?

Thanks!

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM