StratifiedShuffledSplit ImportError

I cannot import name ‘StratifiedShuffledSplit’ from ‘sklearn.model_selection’.
i’m a machine learning student working on a simple machine learning project. I’m having trouble using StratifiedShuffledSplit to split the data set. I have version 1.3.2 installed, which includes the StratifiedShuffledSplit. I can successfully import train_test_split , but not StratifiedShuffledSplit. I tried uninstalling and re-installing scikit-learn but nothing is working. I’m facing problem with this part of the code:


miport numpy as np
from sklearn.model_selection import StratifiedShuffledSplit
split = StratifiedShuffledSplit(n_splits=1, test_size=0.2, random_state=42)
for train_index, test_index in split.split(housing, housing[‘CHAS’]):
strat_train_set = housing.loc[train_index]
strat_test_set = housing.loc[test_index]


ImportError Traceback (most recent call last)
Cell In[4], line 2
1 import numpy as np
----> 2 from sklearn.model_selection import StratifiedShuffledSplit
3 split = StratifiedShuffledSplit(n_splits=1, test_size=0.2, random_state=42)
4 for train_index, test_index in split.split(housing, housing[‘CHAS’]):

ImportError: cannot import name ‘StratifiedShuffledSplit’ from ‘sklearn.model_selection’

The documentation of the method shows that it is StratifiedShuffleSplit. That isn’t what you have; you have 'Shuffled` with an extra letter, misspelling the camel case name.

In the future a good idea is just to copy and paste import statements that are longer than a few characters from the documentation examples, such as here under ‘Examples’. That is a large reason why those examples are provided.
Or search the error (again copy the text directly from the traceback and paste it in your search bar) and note that your browser may indicate to you that it is searching with the corrected spelling.

Finally, in the future keep in mind that Jupyter is a framework for running a lot of kernels of software languages, not just Python. And that Python itself is fully capable of being run separate from Jupyter. Running it in the terminal as a script or lines entered into the console is the more traditional way to run Python. And if your suspect you’d get the same result if you ran your Python code the more traditional way, then your issue isn’t Jupyter-related and is not pertinent to this forum.