Reputation: 101
I was trying to run a python3 code for isolated speech recognition, there I got a DeprecationWarning for using:
from sklearn.cross_validation import StratifiedShuffleSplit
In order to remove this warning, I just imported StratifiedShuffleSplit
from sklearn.model_selection
instead of sklearn.cross_validation
and after running the code, I got:
TypeError: 'StratifiedShuffleSplit' object is not iterable
Maybe because in
class sklearn.cross_validation.StratifiedShuffleSplit(y, n_iter=10, test_size=0.1, train_size=None, random_state=None)
y
is an array.
While in:
class sklearn.cross_validation.StratifiedShuffleSplit(y, n_iter=10, test_size=0.1, train_size=None, random_state=None)
There is no array:
from sklearn.model_selection import StratifiedShuffleSplit
sss = StratifiedShuffleSplit(all_labels, test_size=0.1, random_state=0)
for n,i in enumerate(all_obs):
all_obs[n] /= all_obs[n].sum(axis=0)
for train_index, test_index in sss:
X_train, X_test = all_obs[train_index, ...], all_obs[test_index, ...]
y_train, y_test = all_labels[train_index], all_labels[test_index]
ys = set(all_labels)
ms = [gmmhmm(7) for y in ys]
How to replace all_labels
because it is an array according to sklearn.cross_validation
but sklearn.model_selection
don't accept an array parameter.
Upvotes: 1
Views: 551
Reputation: 979
The difference between the two is that
sklearn.model_selection.StratifiedShuffleSplit
is a cross-validator
sklearn.cross_validation.StratifiedShuffleSplit
is a cross-validator iterator
Hence the correct usages from your example would be
from sklearn.model_selection import StratifiedShuffleSplit
sss = StratifiedShuffleSplit(test_size=0.1, random_state=0)
for n,i in enumerate(all_obs):
all_obs[n] /= all_obs[n].sum(axis=0)
for train_index, test_index in sss.split(all_obs, all_labels):
print(train_index, test_index)
It might be helpful to read the example in the docs of sklearn.model_selection.StratifiedShuffleSplit
Upvotes: 0