python - PermissionError 与 RandomizedSearchCV
问题描述
我正在尝试使用 RandomizedSearchCV 来调整随机森林的超参数,但是在运行代码后我得到了 PermissionError 的瞬间。
最初的运行没有 PermissionError(但是它确实抛出了一个无效的句柄错误),但现在我根本无法运行代码。据我所知,当代码试图在没有适当权限的情况下格式化驱动器时,通常会抛出 WinError 5,但据我所知,RandomizedSearch 并没有试图改变任何东西。我还没有尝试以管理员身份运行,但是访问该帐户会很困难,所以我试图弄清楚是否有其他方法可以解决这个问题。我正在运行 Python 3.7。
n_estimators = [int(x) for x in np.linspace(start=200, stop=2000, num=10)]
max_features = ['auto', 'sqrt']
max_depth = [int(x) for x in np.linspace(10, 110, num=11)]
max_depth.append(None)
min_samples_split = [2, 5, 10]
min_samples_leaf = [1, 2, 4]
bootstrap = [True, False]
random_grid = {'n_estimators': n_estimators,
'max_features': max_features,
'max_depth': max_depth,
'min_samples_split': min_samples_split,
'min_samples_leaf': min_samples_leaf,
'bootstrap': bootstrap}
print(random_grid)
constructed_data = pd.read_csv('Examples/Test_data.CSV')
forest = RandomForestClassifier()
forest.fit(train, train_labels)
forest_random = RandomizedSearchCV(estimator=forest, param_distributions=random_grid, n_iter=100,
cv=3, verbose=2, n_jobs=-1)
forest_random.fit(train, train_labels)
预期:没有错误和推荐的超参数值
实际的:
Fitting 3 folds for each of 100 candidates, totalling 300 fits
[Parallel(n_jobs=-1)]: Using backend LokyBackend with 4 concurrent workers.
exception calling callback for <Future at 0x1013bc90 state=finished raised BrokenProcessPool>
joblib.externals.loky.process_executor._RemoteTraceback:
'''
Traceback (most recent call last):
File "C:\Users\dalinar\PycharmProjects\visualizer\venv\lib\site-packages\joblib\externals\loky\process_executor.py", line 391, in _process_worker
call_item = call_queue.get(block=True, timeout=timeout)
File "C:\Users\dalinar\AppData\Local\Programs\Python\Python37-32\lib\multiprocessing\queues.py", line 99, in get
if not self._rlock.acquire(block, timeout):
PermissionError: [WinError 5] Access is denied
'''
在此之后还会引发其他异常,但上面的错误是其他异常的“直接原因”。
解决方案
看起来您的并行处理有问题,因此n_jobs=1
请在创建RandomizedSearchCV()
对象时尝试设置。
此外,您可能想看看gridsearcCV 中的并行性最终会出现权限错误
希望这可以帮助!
推荐阅读
- php - 使用 Symfony 4 从 twig 文件中的表单获取用户输入数据
- python - AttributeError:“资源”对象没有属性“消息”
- java - 关于通过 HTTPS SSL(/TLS?)正确发布的说明
- sql - 计算月度销售差异
- vba - VBA:选择一个活动的word文档
- postgresql - Postgresql:如何将 curl 与函数一起使用
- python-import - pyinstaller 在运行时导入/加载 python 代码,例如 config.py
- c# - .NET - 使用 DataSet 从 MS Access 数据库中获取行
- docker - 加载 tar 文件时的 docker-compose
- r - 处理geepack R中的缺失值