0

I am getting an error while using from sklearn.model_selection import KFold in my jupyter notebook.

The error says "No module named 'sklearn.model_selection'". When I printed

print(sklearn.__version__)

I got the version to be 0.17.1.

Can anyone help me understand what is the problem?

Guy Avraham
  • 3,482
  • 3
  • 38
  • 50
Khan
  • 81
  • 2
  • 7

2 Answers2

1

Under version 0.17.1 KFold is found under sklearn.cross_validation. Only in versions >= 0.19 can KFold be found under sklearn.model_selection

So you need to change your import to:

from sklearn.cross_validation import KFold

See API for version 0.17

Harpal
  • 12,057
  • 18
  • 61
  • 74
  • Nope, it was available in `model_selection` since version 0.18. But in that time, `cross_validation` also existed as a deprecated version. – Vivek Kumar Dec 26 '17 at 11:06
0

I think it will be better this way:

from sklearn.model_selection import cross_val_score

  • 1
    Your answer could be improved with additional supporting information. Please [edit] to add further details, such as citations or documentation, so that others can confirm that your answer is correct. You can find more information on how to write good answers [in the help center](/help/how-to-answer). – Community Feb 20 '22 at 04:32