質問するログイン新規登録

質問編集履歴

1

コードを加えました

2018/05/06 10:23

投稿

mimamoru
mimamoru

スコア19

title CHANGED
File without changes
body CHANGED
@@ -1,3 +1,79 @@
1
+ ```ここに言語を入力
2
+ import numpy as np
3
+ from sklearn import datasets
4
+ from sklearn.model_selection import GridSearchCV
5
+ from sklearn.linear_model import LogisticRegression
6
+ from sklearn.decomposition import PCA
7
+ from sklearn.svm import SVC
8
+ from sklearn.pipeline import Pipeline
9
+ digits = datasets.load_digits()
10
+
11
+ X,y=digits.data,digits.target
12
+
13
+ from sklearn.model_selection import train_test_split
14
+ X_train,X_test,y_train,y_test=train_test_split(X,y,test_size=0.2,random_state=0)
15
+
16
+ clf1=LogisticRegression()
17
+ clf2=SVC()
18
+
19
+ estimators = [('pca', PCA()),
20
+ ('clf', clf1)]
21
+ pipe1 = Pipeline(estimators)
22
+
23
+ param1 = {'clf__C':[1e-5, 1e-3, 1e-2, 1, 1e2, 1e5, 1e10],
24
+ 'pca__whiten':[True,False],
25
+ }
26
+
27
+ gs = GridSearchCV(pipe1, param1)
28
+ gs.fit(X_train, y_train)
29
+
30
+ gs.score(X_test, y_test)
31
+
32
+ from sklearn.model_selection import RandomizedSearchCV
33
+ estimators= [('pca', PCA()),
34
+ ('clf',SVC())]
35
+ pipe2 = Pipeline(estimators)
36
+ gamma_range_exp = np.arange(-10.0, 0.0, 3)
37
+ gamma_range = 10 ** gamma_range_exp
38
+
39
+ param2 =[ {'clf__C':[1e-5, 1e-3, 1e-2, 1, 1e2, 1e5, 1e10],
40
+ 'clf__kernel':['linear'],
41
+ 'pca__whiten':[True,False],
42
+ 'pca__n_components': [30, 20, 10]},
43
+
44
+ {'clf__C':[1e-5, 1e-3, 1e-2, 1, 1e2, 1e5, 1e10],
45
+ 'clf__kernel':['rbf'],
46
+ 'gamma': gamma_range,
47
+ 'pca__whiten':[True,False],
48
+ 'pca__n_components': [30, 20, 10]}
49
+ ]
50
+
51
+ gs = RandomizedSearchCV(pipe2, param2, n_jobs=-1, verbose=2)
52
+ gs.fit(X_train, y_train)
53
+ ```
54
+ エラー内容
55
+ AttributeError Traceback (most recent call last)
56
+ <ipython-input-11-21305e2006cc> in <module>()
57
+ 12
58
+ 13 gs = RandomizedSearchCV(pipe2, param2, n_jobs=-1, verbose=2)
59
+ ---> 14 gs.fit(X_train, y_train)
60
+
61
+ ~/anaconda3/lib/python3.6/site-packages/sklearn/model_selection/_search.py in fit(self, X, y, groups, **fit_params)
62
+ 616 n_splits = cv.get_n_splits(X, y, groups)
63
+ 617 # Regenerate parameter iterable for each fit
64
+ --> 618 candidate_params = list(self._get_param_iterator())
65
+ 619 n_candidates = len(candidate_params)
66
+ 620 if self.verbose > 0:
67
+
68
+ ~/anaconda3/lib/python3.6/site-packages/sklearn/model_selection/_search.py in __iter__(self)
69
+ 236 # in this case we want to sample without replacement
70
+ 237 all_lists = np.all([not hasattr(v, "rvs")
71
+ --> 238 for v in self.param_distributions.values()])
72
+ 239 rnd = check_random_state(self.random_state)
73
+ 240
74
+
75
+ AttributeError: 'list' object has no attribute 'values'
76
+
1
77
  ![イメージ説明](168d763492519882668efddcde7ef8a6.png)
2
78
 
3
79
  ![イメージ説明](b3d7e58c75630d2ab06e556e36dc980d.png)