回答編集履歴
5
追記
test
CHANGED
@@ -79,3 +79,111 @@
|
|
79
79
|
```
|
80
80
|
|
81
81
|
joblibはどこに・・・
|
82
|
+
|
83
|
+
|
84
|
+
|
85
|
+
---
|
86
|
+
|
87
|
+
|
88
|
+
|
89
|
+
mkgreiさんに教えて頂いた[リンク](https://stackoverflow.com/questions/40803684/parallel-error-with-gridsearchcv-works-fine-with-other-methods)により質問文のコードを改造した処
|
90
|
+
|
91
|
+
Windows環境でもエラーは発生しないようにできました。
|
92
|
+
|
93
|
+
|
94
|
+
|
95
|
+
```Python
|
96
|
+
|
97
|
+
import numpy as np
|
98
|
+
|
99
|
+
from sklearn import datasets
|
100
|
+
|
101
|
+
from sklearn.model_selection import GridSearchCV
|
102
|
+
|
103
|
+
from sklearn.linear_model import LogisticRegression
|
104
|
+
|
105
|
+
from sklearn.decomposition import PCA
|
106
|
+
|
107
|
+
from sklearn.svm import SVC
|
108
|
+
|
109
|
+
from sklearn.pipeline import Pipeline
|
110
|
+
|
111
|
+
from sklearn.model_selection import train_test_split
|
112
|
+
|
113
|
+
from sklearn.model_selection import RandomizedSearchCV
|
114
|
+
|
115
|
+
|
116
|
+
|
117
|
+
|
118
|
+
|
119
|
+
def main() ->None:
|
120
|
+
|
121
|
+
digits = datasets.load_digits()
|
122
|
+
|
123
|
+
X, y = digits.data, digits.target
|
124
|
+
|
125
|
+
X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.2, random_state=0)
|
126
|
+
|
127
|
+
|
128
|
+
|
129
|
+
clf1 = LogisticRegression()
|
130
|
+
|
131
|
+
clf2 = SVC()
|
132
|
+
|
133
|
+
estimators = [('pca', PCA()),
|
134
|
+
|
135
|
+
('clf', clf1)]
|
136
|
+
|
137
|
+
pipe1 = Pipeline(estimators)
|
138
|
+
|
139
|
+
param1 = {'clf__C': [1e-5, 1e-3, 1e-2, 1, 1e2, 1e5, 1e10],
|
140
|
+
|
141
|
+
'pca__whiten': [True, False]}
|
142
|
+
|
143
|
+
gs = GridSearchCV(pipe1, param1)
|
144
|
+
|
145
|
+
gs.fit(X_train, y_train)
|
146
|
+
|
147
|
+
print(gs.score(X_test, y_test))
|
148
|
+
|
149
|
+
estimators = [('pca', PCA()),
|
150
|
+
|
151
|
+
('clf', SVC())]
|
152
|
+
|
153
|
+
pipe2 = Pipeline(estimators)
|
154
|
+
|
155
|
+
gamma_range_exp = np.arange(-10.0, 0.0, 3)
|
156
|
+
|
157
|
+
gamma_range = 10 ** gamma_range_exp
|
158
|
+
|
159
|
+
|
160
|
+
|
161
|
+
param2 = {'clf__C': [1e-5, 1e-3, 1e-2, 1, 1e2, 1e5, 1e10],
|
162
|
+
|
163
|
+
'clf__kernel': ['rbf', 'linear'],
|
164
|
+
|
165
|
+
'clf__gamma': gamma_range,
|
166
|
+
|
167
|
+
'pca__whiten': [True, False],
|
168
|
+
|
169
|
+
'pca__n_components': [30, 20, 10]}
|
170
|
+
|
171
|
+
|
172
|
+
|
173
|
+
print('start')
|
174
|
+
|
175
|
+
gs = RandomizedSearchCV(pipe2, param2, n_jobs=-1, verbose=2)
|
176
|
+
|
177
|
+
gs.fit(X_train, y_train)
|
178
|
+
|
179
|
+
|
180
|
+
|
181
|
+
|
182
|
+
|
183
|
+
if __name__ == '__main__':
|
184
|
+
|
185
|
+
main()
|
186
|
+
|
187
|
+
|
188
|
+
|
189
|
+
```
|
4
追記
test
CHANGED
@@ -70,7 +70,7 @@
|
|
70
70
|
|
71
71
|
OS: Windows 10
|
72
72
|
|
73
|
-
|
73
|
+
PyCharmより実行。
|
74
74
|
|
75
75
|
```txt
|
76
76
|
|
3
追記
test
CHANGED
@@ -59,3 +59,23 @@
|
|
59
59
|
|
60
60
|
|
61
61
|
```
|
62
|
+
|
63
|
+
◇実行環境
|
64
|
+
|
65
|
+
python: 3.6.5
|
66
|
+
|
67
|
+
numpy: 1.13.3
|
68
|
+
|
69
|
+
sklearn: 0.19.1
|
70
|
+
|
71
|
+
OS: Windows 10
|
72
|
+
|
73
|
+
|
74
|
+
|
75
|
+
```txt
|
76
|
+
|
77
|
+
ImportError: [joblib] Attempting to do parallel computing without protecting your import on a system that does not support forking. To use parallel-computing in a script, you must protect your main loop using "if __name__ == '__main__'". Please see the joblib documentation on Parallel for more information
|
78
|
+
|
79
|
+
```
|
80
|
+
|
81
|
+
joblibはどこに・・・
|
2
追記
test
CHANGED
@@ -37,3 +37,25 @@
|
|
37
37
|
追記
|
38
38
|
|
39
39
|
[VotingClassifierを使いつつGridSearchCV/RandomizedSearchCVでパラメータチューニング](https://qiita.com/yagays/items/a503117bd06bb938fdb9)
|
40
|
+
|
41
|
+
|
42
|
+
|
43
|
+
---
|
44
|
+
|
45
|
+
|
46
|
+
|
47
|
+
```Python
|
48
|
+
|
49
|
+
param2 ={'clf__C':[1e-5, 1e-3, 1e-2, 1, 1e2, 1e5, 1e10],
|
50
|
+
|
51
|
+
'clf__kernel':['rbf', 'linear'],
|
52
|
+
|
53
|
+
'clf__gamma': gamma_range,
|
54
|
+
|
55
|
+
'pca__whiten':[True,False],
|
56
|
+
|
57
|
+
'pca__n_components': [30, 20, 10]}
|
58
|
+
|
59
|
+
|
60
|
+
|
61
|
+
```
|
1
追記
test
CHANGED
@@ -33,3 +33,7 @@
|
|
33
33
|
|
34
34
|
|
35
35
|
```
|
36
|
+
|
37
|
+
追記
|
38
|
+
|
39
|
+
[VotingClassifierを使いつつGridSearchCV/RandomizedSearchCVでパラメータチューニング](https://qiita.com/yagays/items/a503117bd06bb938fdb9)
|