質問編集履歴
2
記載の修正
title
CHANGED
File without changes
|
body
CHANGED
@@ -1,19 +1,24 @@
|
|
1
1
|
目的: scikit-learnのrandom forest classifier, RFECV, GridsearchCVを使って、特徴量選択をしたい。RFECVで特徴量が削減されるごとにGridsearchCVで最適なrandom forest classifierのパラメータを設定したい。
|
2
2
|
解決したいこと: 以下のコードを実行したが、エラーがでてしまう。コードを適切に修正したいです。
|
3
3
|
|
4
|
-
|
4
|
+
```
|
5
|
+
from sklearn.ensemble import RandomForestClassifier
|
6
|
+
from sklearn.model_selection import GridSearchCV
|
7
|
+
from sklearn.feature_selection import RFECV
|
8
|
+
|
5
9
|
param_grid = {'estimator__n_estimators': [10, 20, 50, 100, 200],
|
6
10
|
'estimator__max_depth': [1, 2, 3, 4, 5, 6, 7, 8, 9, 10],
|
7
11
|
'estimator__max_features': [0.1, 0.2, 0.3, 0.4, 0.5, 0.6, 0.7, 0.8],
|
8
12
|
'estimator__max_samples' : [0.1, 0.2, 0.3, 0.4, 0.5, 0.6, 0.7, 0.8]}
|
9
13
|
|
10
14
|
estimator = RandomForestClassifier()
|
15
|
+
selector = RFECV(estimator, scoring = 'f1_macro', cv = 5, step=1)
|
16
|
+
clf = GridSearchCV(selector, param_grid, scoring = 'f1_macro', cv = 5)
|
17
|
+
clf.fit(X, y)
|
11
18
|
|
12
|
-
|
19
|
+
コード
|
20
|
+
```
|
13
21
|
|
14
|
-
clf = GridSearchCV(selector, param_grid, scoring = 'f1_macro', cv = index_cv)
|
15
|
-
clf.fit(X, y)
|
16
|
-
|
17
22
|
エラー:
|
18
23
|
FitFailedWarning: Estimator fit failed. The score on this train-test partition for these parameters will be set to nan. Details:
|
19
24
|
IndexError: index 376 is out of bounds for axis 0 with size 376
|
1
書式の改善
title
CHANGED
File without changes
|
body
CHANGED
@@ -1,21 +1,19 @@
|
|
1
1
|
目的: scikit-learnのrandom forest classifier, RFECV, GridsearchCVを使って、特徴量選択をしたい。RFECVで特徴量が削減されるごとにGridsearchCVで最適なrandom forest classifierのパラメータを設定したい。
|
2
2
|
解決したいこと: 以下のコードを実行したが、エラーがでてしまう。コードを適切に修正したいです。
|
3
3
|
|
4
|
-
|
4
|
+
コード:
|
5
5
|
param_grid = {'estimator__n_estimators': [10, 20, 50, 100, 200],
|
6
6
|
'estimator__max_depth': [1, 2, 3, 4, 5, 6, 7, 8, 9, 10],
|
7
7
|
'estimator__max_features': [0.1, 0.2, 0.3, 0.4, 0.5, 0.6, 0.7, 0.8],
|
8
8
|
'estimator__max_samples' : [0.1, 0.2, 0.3, 0.4, 0.5, 0.6, 0.7, 0.8]}
|
9
|
-
|
9
|
+
|
10
10
|
estimator = RandomForestClassifier()
|
11
11
|
|
12
|
-
#RFECV
|
13
12
|
selector = RFECV(estimator, scoring = 'f1_macro', cv = index_cv, step=1)
|
14
13
|
|
15
|
-
#gridsearch
|
16
14
|
clf = GridSearchCV(selector, param_grid, scoring = 'f1_macro', cv = index_cv)
|
17
15
|
clf.fit(X, y)
|
18
16
|
|
19
|
-
|
17
|
+
エラー:
|
20
18
|
FitFailedWarning: Estimator fit failed. The score on this train-test partition for these parameters will be set to nan. Details:
|
21
19
|
IndexError: index 376 is out of bounds for axis 0 with size 376
|