質問編集履歴
2
from sklearn.model_selection import StratifiedKFold変更後
title
CHANGED
File without changes
|
body
CHANGED
@@ -54,6 +54,12 @@
|
|
54
54
|
from sklearn.model_selection import StratifiedKFold
|
55
55
|
|
56
56
|
stf = StratifiedKFold(n_splits=2, random_state=0)
|
57
|
-
for train_indices, test_indices in stf.split(labels,
|
57
|
+
for train_indices, test_indices in stf.split(labels,labels):
|
58
|
-
print(test_indices)
|
58
|
+
print(len(test_indices))
|
59
|
+
```
|
60
|
+
とすると、出力は
|
61
|
+
|
62
|
+
```
|
63
|
+
892
|
64
|
+
899
|
59
65
|
```
|
1
model_selectionに変更
title
CHANGED
File without changes
|
body
CHANGED
@@ -47,4 +47,13 @@
|
|
47
47
|
```
|
48
48
|
このようなリストになります。
|
49
49
|
|
50
|
-
どうして、list()[0]とすることで、リスト化できたのでしょうか?この[0]の意味がよく分かりません。
|
50
|
+
どうして、list()[0]とすることで、リスト化できたのでしょうか?この[0]の意味がよく分かりません。
|
51
|
+
|
52
|
+
model_selection変更後は、このようになると思いました。しかし、split()の引数として、X,yの二つを指定するようになっていますが、私はlabels一つだけの中身をtrainとtestに分けたいと思っています。どうしたらいいでしょうか。出力はエラーです。
|
53
|
+
```
|
54
|
+
from sklearn.model_selection import StratifiedKFold
|
55
|
+
|
56
|
+
stf = StratifiedKFold(n_splits=2, random_state=0)
|
57
|
+
for train_indices, test_indices in stf.split(labels,_):
|
58
|
+
print(test_indices)
|
59
|
+
```
|