gpt4 book ai didi

python - 属性错误 : 'slice' object has no attribute 'flags' Error

转载 作者:太空宇宙 更新时间:2023-11-04 02:03:54 29 4
gpt4 key购买 nike

我试图在没有交叉验证的情况下使用 GridSearchCv,因为我有一套单独的验证。我找到了 this解决方案建议我应该对 cv 参数使用 cv=[(slice(None), slice(None))] 代码并且它有效。但是这段代码在我同事的 PyCharm 编辑器中失败了。这是错误:AttributeError: 'slice' object has no attribute 'flags'

这是完整的错误堆栈:

Traceback (most recent call last):
File "<input>", line 1, in <module>
File "C:\Program Files\JetBrains\PyCharm 2018.3.5\helpers\pydev\_pydev_bundle\pydev_umd.py", line 197, in runfile
pydev_imports.execfile(filename, global_vars, local_vars) # execute the script
File "C:\Program Files\JetBrains\PyCharm 2018.3.5\helpers\pydev\_pydev_imps\_pydev_execfile.py", line 18, in execfile
exec(compile(contents+"\n", file, 'exec'), glob, loc)
File "C:/Users/user/PycharmProjects/aitrading/src/studies/ModelRunner.py", line 61, in <module>
ModelRunner()
File "C:/Users/user/PycharmProjects/aitrading/src/studies/ModelRunner.py", line 58, in _init_
grid_result = grid.fit(self.train_X, self.train_y, validation_data=(self.valid_X, self.valid_y))
File "C:\Users\user\AppData\Local\Programs\Python\Python36\lib\site-packages\sklearn\model_selection\_search.py", line 722, in fit
self._run_search(evaluate_candidates)
File "C:\Users\user\AppData\Local\Programs\Python\Python36\lib\site-packages\sklearn\model_selection\_search.py", line 1191, in _run_search
evaluate_candidates(ParameterGrid(self.param_grid))
File "C:\Users\user\AppData\Local\Programs\Python\Python36\lib\site-packages\sklearn\model_selection\_search.py", line 711, in evaluate_candidates
cv.split(X, y, groups)))
File "C:\Users\user\AppData\Local\Programs\Python\Python36\lib\site-packages\sklearn\externals\joblib\parallel.py", line 917, in _call_
if self.dispatch_one_batch(iterator):
File "C:\Users\user\AppData\Local\Programs\Python\Python36\lib\site-packages\sklearn\externals\joblib\parallel.py", line 759, in dispatch_one_batch
self._dispatch(tasks)
File "C:\Users\user\AppData\Local\Programs\Python\Python36\lib\site-packages\sklearn\externals\joblib\parallel.py", line 716, in _dispatch
job = self._backend.apply_async(batch, callback=cb)
File "C:\Users\user\AppData\Local\Programs\Python\Python36\lib\site-packages\sklearn\externals\joblib\_parallel_backends.py", line 182, in apply_async
result = ImmediateResult(func)
File "C:\Users\user\AppData\Local\Programs\Python\Python36\lib\site-packages\sklearn\externals\joblib\_parallel_backends.py", line 549, in _init_
self.results = batch()
File "C:\Users\user\AppData\Local\Programs\Python\Python36\lib\site-packages\sklearn\externals\joblib\parallel.py", line 225, in _call_
for func, args, kwargs in self.items]
File "C:\Users\user\AppData\Local\Programs\Python\Python36\lib\site-packages\sklearn\externals\joblib\parallel.py", line 225, in <listcomp>
for func, args, kwargs in self.items]
File "C:\Users\user\AppData\Local\Programs\Python\Python36\lib\site-packages\sklearn\model_selection\_validation.py", line 518, in _fit_and_score
X_train, y_train = _safe_split(estimator, X, y, train)
File "C:\Users\user\AppData\Local\Programs\Python\Python36\lib\site-packages\sklearn\utils\metaestimators.py", line 203, in _safe_split
X_subset = safe_indexing(X, indices)
File "C:\Users\user\AppData\Local\Programs\Python\Python36\lib\site-packages\sklearn\utils\_init_.py", line 202, in safe_indexing
indices = indices if indices.flags.writeable else indices.copy()
AttributeError: 'slice' object has no attribute 'flags'

我该如何解决这个问题?

最佳答案

尝试在 GridSearch 中不使用 kfolds 时遇到完全相同的问题。我尝试改用另一种方法:

cv = ShuffleSplit(test_size=0.01, n_splits=1)

这应该是一样的效果

关于python - 属性错误 : 'slice' object has no attribute 'flags' Error,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55143629/

29 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com