質問編集履歴
1
コードを加えました
test
CHANGED
File without changes
|
test
CHANGED
@@ -1,3 +1,155 @@
|
|
1
|
+
```ここに言語を入力
|
2
|
+
|
3
|
+
import numpy as np
|
4
|
+
|
5
|
+
from sklearn import datasets
|
6
|
+
|
7
|
+
from sklearn.model_selection import GridSearchCV
|
8
|
+
|
9
|
+
from sklearn.linear_model import LogisticRegression
|
10
|
+
|
11
|
+
from sklearn.decomposition import PCA
|
12
|
+
|
13
|
+
from sklearn.svm import SVC
|
14
|
+
|
15
|
+
from sklearn.pipeline import Pipeline
|
16
|
+
|
17
|
+
digits = datasets.load_digits()
|
18
|
+
|
19
|
+
|
20
|
+
|
21
|
+
X,y=digits.data,digits.target
|
22
|
+
|
23
|
+
|
24
|
+
|
25
|
+
from sklearn.model_selection import train_test_split
|
26
|
+
|
27
|
+
X_train,X_test,y_train,y_test=train_test_split(X,y,test_size=0.2,random_state=0)
|
28
|
+
|
29
|
+
|
30
|
+
|
31
|
+
clf1=LogisticRegression()
|
32
|
+
|
33
|
+
clf2=SVC()
|
34
|
+
|
35
|
+
|
36
|
+
|
37
|
+
estimators = [('pca', PCA()),
|
38
|
+
|
39
|
+
('clf', clf1)]
|
40
|
+
|
41
|
+
pipe1 = Pipeline(estimators)
|
42
|
+
|
43
|
+
|
44
|
+
|
45
|
+
param1 = {'clf__C':[1e-5, 1e-3, 1e-2, 1, 1e2, 1e5, 1e10],
|
46
|
+
|
47
|
+
'pca__whiten':[True,False],
|
48
|
+
|
49
|
+
}
|
50
|
+
|
51
|
+
|
52
|
+
|
53
|
+
gs = GridSearchCV(pipe1, param1)
|
54
|
+
|
55
|
+
gs.fit(X_train, y_train)
|
56
|
+
|
57
|
+
|
58
|
+
|
59
|
+
gs.score(X_test, y_test)
|
60
|
+
|
61
|
+
|
62
|
+
|
63
|
+
from sklearn.model_selection import RandomizedSearchCV
|
64
|
+
|
65
|
+
estimators= [('pca', PCA()),
|
66
|
+
|
67
|
+
('clf',SVC())]
|
68
|
+
|
69
|
+
pipe2 = Pipeline(estimators)
|
70
|
+
|
71
|
+
gamma_range_exp = np.arange(-10.0, 0.0, 3)
|
72
|
+
|
73
|
+
gamma_range = 10 ** gamma_range_exp
|
74
|
+
|
75
|
+
|
76
|
+
|
77
|
+
param2 =[ {'clf__C':[1e-5, 1e-3, 1e-2, 1, 1e2, 1e5, 1e10],
|
78
|
+
|
79
|
+
'clf__kernel':['linear'],
|
80
|
+
|
81
|
+
'pca__whiten':[True,False],
|
82
|
+
|
83
|
+
'pca__n_components': [30, 20, 10]},
|
84
|
+
|
85
|
+
|
86
|
+
|
87
|
+
{'clf__C':[1e-5, 1e-3, 1e-2, 1, 1e2, 1e5, 1e10],
|
88
|
+
|
89
|
+
'clf__kernel':['rbf'],
|
90
|
+
|
91
|
+
'gamma': gamma_range,
|
92
|
+
|
93
|
+
'pca__whiten':[True,False],
|
94
|
+
|
95
|
+
'pca__n_components': [30, 20, 10]}
|
96
|
+
|
97
|
+
]
|
98
|
+
|
99
|
+
|
100
|
+
|
101
|
+
gs = RandomizedSearchCV(pipe2, param2, n_jobs=-1, verbose=2)
|
102
|
+
|
103
|
+
gs.fit(X_train, y_train)
|
104
|
+
|
105
|
+
```
|
106
|
+
|
107
|
+
エラー内容
|
108
|
+
|
109
|
+
AttributeError Traceback (most recent call last)
|
110
|
+
|
111
|
+
<ipython-input-11-21305e2006cc> in <module>()
|
112
|
+
|
113
|
+
12
|
114
|
+
|
115
|
+
13 gs = RandomizedSearchCV(pipe2, param2, n_jobs=-1, verbose=2)
|
116
|
+
|
117
|
+
---> 14 gs.fit(X_train, y_train)
|
118
|
+
|
119
|
+
|
120
|
+
|
121
|
+
~/anaconda3/lib/python3.6/site-packages/sklearn/model_selection/_search.py in fit(self, X, y, groups, **fit_params)
|
122
|
+
|
123
|
+
616 n_splits = cv.get_n_splits(X, y, groups)
|
124
|
+
|
125
|
+
617 # Regenerate parameter iterable for each fit
|
126
|
+
|
127
|
+
--> 618 candidate_params = list(self._get_param_iterator())
|
128
|
+
|
129
|
+
619 n_candidates = len(candidate_params)
|
130
|
+
|
131
|
+
620 if self.verbose > 0:
|
132
|
+
|
133
|
+
|
134
|
+
|
135
|
+
~/anaconda3/lib/python3.6/site-packages/sklearn/model_selection/_search.py in __iter__(self)
|
136
|
+
|
137
|
+
236 # in this case we want to sample without replacement
|
138
|
+
|
139
|
+
237 all_lists = np.all([not hasattr(v, "rvs")
|
140
|
+
|
141
|
+
--> 238 for v in self.param_distributions.values()])
|
142
|
+
|
143
|
+
239 rnd = check_random_state(self.random_state)
|
144
|
+
|
145
|
+
240
|
146
|
+
|
147
|
+
|
148
|
+
|
149
|
+
AttributeError: 'list' object has no attribute 'values'
|
150
|
+
|
151
|
+
|
152
|
+
|
1
153
|
![イメージ説明](168d763492519882668efddcde7ef8a6.png)
|
2
154
|
|
3
155
|
|