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

質問編集履歴

3

修正

2019/11/04 13:37

投稿

john_doe_
john_doe_

スコア354

title CHANGED
File without changes
body CHANGED
@@ -40,7 +40,7 @@
40
40
  data.feature_names[skb.get_support()]
41
41
  AttributeError: 'numpy.ndarray' object has no attribute 'feature_names'
42
42
 
43
- # arrayに変換しているので、columnsも呼び出せない
43
+ # 下記を試してみましたが上手くかず。。。。
44
44
  df.columns[skb.get_support()]
45
45
  IndexError: boolean index did not match indexed array along dimension 0; dimension is 57 but corresponding boolean dimension is 56
46
46
 

2

修正

2019/11/04 13:37

投稿

john_doe_
john_doe_

スコア354

title CHANGED
File without changes
body CHANGED
@@ -9,10 +9,10 @@
9
9
  from sklearn.feature_selection import chi2
10
10
 
11
11
  df = pd.read_csv('/Users/hoge/Desktop/ファイル名.csv')
12
- df = np.array(df)
12
+ data = np.array(df)
13
13
 
14
- X = df[:,1:58]
14
+ X = data[:,1:58]
15
- y = df[:,0]
15
+ y = data[:,0]
16
16
 
17
17
  ss = ShuffleSplit(n_splits=1, train_size=0.8, test_size=0.2)
18
18
  train_index, test_index = next(ss.split(X, y))
@@ -26,16 +26,23 @@
26
26
 
27
27
  # 絞り込まれた20
28
28
  skb.get_support()
29
+ array([False, False, False, False, True, True, False, False, False,
30
+ True, True, True, False, True, False, False, False, False,
31
+ False, False, True, False, True, True, True, False, False,
32
+ False, True, False, False, True, True, False, True, False,
33
+ True, True, False, False, True, False, True, True, False,
34
+ False, False, False, False, False, False, False, False, False,
35
+ True, False])
29
36
 
30
- # skb.get_support()で絞り込まれた列名(カラム名)を確認したい
37
+ # skb.get_support()で絞り込まれたtrue,false名称で確認したい
31
38
 
32
39
  # feature_namesが入っていないデータなのでおそらく仕方ない
33
- df.feature_names[skb.get_support()]
40
+ data.feature_names[skb.get_support()]
34
41
  AttributeError: 'numpy.ndarray' object has no attribute 'feature_names'
35
42
 
36
43
  # arrayに変換しているので、columnsも呼び出せない
37
44
  df.columns[skb.get_support()]
38
- AttributeError: 'numpy.ndarray' object has no attribute 'columns'
45
+ IndexError: boolean index did not match indexed array along dimension 0; dimension is 57 but corresponding boolean dimension is 56
39
46
 
40
47
  ```
41
48
 

1

追記

2019/11/04 13:29

投稿

john_doe_
john_doe_

スコア354

title CHANGED
File without changes
body CHANGED
@@ -24,9 +24,11 @@
24
24
  X_train_new = skb.transform(X_train)
25
25
  X_train_new.shape, X_train.shape
26
26
 
27
- # 絞り込まれた20と、脱落した38を確認したい
27
+ # 絞り込まれた20
28
28
  skb.get_support()
29
29
 
30
+ # skb.get_support()で絞り込まれた列名(カラム名)を確認したい
31
+
30
32
  # feature_namesが入っていないデータなのでおそらく仕方ない
31
33
  df.feature_names[skb.get_support()]
32
34
  AttributeError: 'numpy.ndarray' object has no attribute 'feature_names'