我想使用GridSearchCV优化值。当我这样做时,会出现“权限错误”和类似错误。
# Data
dataset = pd.read_csv('Social_Network_Ads.csv')
X = dataset.iloc[:, [2, 3]].values
y = dataset.iloc[:, 4].values
# Scaling
from sklearn.preprocessing import StandardScaler
sc = StandardScaler()
X = sc.fit_transform(X)
# SVM
from sklearn.svm import SVC
classifier = SVC(kernel='rbf', random_state=0)
问题是从这一点开始的。
# Grid Search with Cross Validation (Params Optimization)
from sklearn.model_selection import GridSearchCV
p = [{'C': [1, 2, 3, 4, 5], 'Kernel':['linear']},
{'C': [1, 10, 100, 1000], 'kernel': ['rbf'],
'gamma': [1, 0.5, 0.1, 0.01, 0.001]}]
gs = GridSearchCV(estimator=classifier, param_grid=p,
scoring='accuracy', cv=10, n_jobs=-1)
grid_search = gs.fit(X, y)
bestScore = grid_search.best_score_
bestParams = grid_search.best_params_
print(bestScore, bestParams)
错误消息如下。 这只是一部分,因为错误太长。
Traceback (most recent call last):
File "C:\Users\user\PycharmProjects\MachineLearning\venv\lib\site-
packages\sklearn\externals\joblib\externals\loky\process_executor.py", line
391, in _process_worker
call_item = call_queue.get(block=True, timeout=timeout)
File
C:\Users\user\AppData\Local\Programs\Python\Python37\lib
\multiprocessing\queue
s.py", line 99, in get
if not self._rlock.acquire(block, timeout):
PermissionError: [WinError 5] Erişim engellendi
答案 0 :(得分:0)
您可以在以下范围内添加完整的sklearn代码,然后尝试。
from joblib import parallel_backend
with parallel_backend('threading', n_jobs=2):
#your sklearn code here
这解决了我的PermissionError: [WinError 5] Access is denied
问题。