“TypeError:‘StratifiedShuffleSplit’对象不可迭代”的原因可能是什么?

2024-01-15

我必须交付一个机器学习项目,我收到了一个名为tester.py。在另一个文件中编写完代码后,我必须运行 tester.py 才能查看结果,但出现错误:TypeError: 'StratifiedShuffleSplit' object is not iterable

我在另一个主题和网站中研究了这个错误,解决方案总是相同的:使用sklearn.model_selection导入GridSearchCV。我从一开始就已经这样做了,但是文件 tester.py 没有运行。

tester.py 中出现问题的代码部分是:

def main():
    ### load up student's classifier, dataset, and feature_list
    clf, dataset, feature_list = load_classifier_and_data()
    ### Run testing script
    test_classifier(clf, dataset, feature_list)

if __name__ == '__main__':
    main()

我自己的代码运行良好。

有什么帮助吗?


尝试更改 tester.py 的以下行 当前版本的 StratifiedShuffleSplit 的工作方式与开发 tester.py 时的预期不同。

[..]
from sklearn.model_selection import StratifiedShuffleSplit
[..]
#cv = StratifiedShuffleSplit(labels, folds, random_state = 42)
cv = StratifiedShuffleSplit(n_splits=folds, random_state=42)
[..]
#for train_idx, test_idx in cv:
for train_idx, test_idx in cv.split(features, labels):
[..]

希望对你有帮助

本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

“TypeError:‘StratifiedShuffleSplit’对象不可迭代”的原因可能是什么? 的相关文章

随机推荐