質問編集履歴
2
エラーコードの更新
title
CHANGED
File without changes
|
body
CHANGED
@@ -109,10 +109,10 @@
|
|
109
109
|
pred = model.predict(x_test, batch_size=1, verbose=0)
|
110
110
|
y_pred2 = np.max(pred)
|
111
111
|
```
|
112
|
-
### 新
|
112
|
+
### 最新のエラーコード
|
113
113
|
```
|
114
|
-
|
114
|
+
ValueError Traceback (most recent call last)
|
115
|
-
<ipython-input-
|
115
|
+
<ipython-input-13-b74e493b703b> in <module>
|
116
116
|
70
|
117
117
|
71
|
118
118
|
---> 72 print('confusion matrix 混合行列 =\n ', confusion_matrix(y_true=y_test2, y_pred=y_pred2))#混合行列
|
@@ -134,25 +134,11 @@
|
|
134
134
|
82 type_pred = type_of_target(y_pred)
|
135
135
|
|
136
136
|
~\Anaconda3\lib\site-packages\sklearn\utils\validation.py in check_consistent_length(*arrays)
|
137
|
-
206 """
|
138
|
-
207
|
139
|
-
--> 208 lengths = [_num_samples(X) for X in arrays if X is not None]
|
140
|
-
209 uniques = np.unique(lengths)
|
141
137
|
210 if len(uniques) > 1:
|
138
|
+
211 raise ValueError("Found input variables with inconsistent numbers of"
|
139
|
+
--> 212 " samples: %r" % [int(l) for l in lengths])
|
140
|
+
213
|
141
|
+
214
|
142
142
|
|
143
|
-
~\Anaconda3\lib\site-packages\sklearn\utils\validation.py in <listcomp>(.0)
|
144
|
-
206 """
|
145
|
-
207
|
146
|
-
--> 208 lengths = [_num_samples(X) for X in arrays if X is not None]
|
147
|
-
209 uniques = np.unique(lengths)
|
148
|
-
210 if len(uniques) > 1:
|
149
|
-
|
150
|
-
~\Anaconda3\lib\site-packages\sklearn\utils\validation.py in _num_samples(x)
|
151
|
-
150 if len(x.shape) == 0:
|
152
|
-
151 raise TypeError("Singleton array %r cannot be considered"
|
153
|
-
--> 152 " a valid collection." % x)
|
154
|
-
153 # Check that shape is returning an integer or default to len
|
155
|
-
154 # Dask dataframes may not return numeric shape[0] value
|
156
|
-
|
157
|
-
|
143
|
+
ValueError: Found input variables with inconsistent numbers of samples: [1, 12000]
|
158
144
|
```
|
1
いただいた回答に修正した際のエラーコードを表示しました
title
CHANGED
File without changes
|
body
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
confusion_matrixを表示したいのですがエラーが出てしまいます。
|
2
2
|
どうすれば表示できるのかお聞きしたいです。
|
3
3
|
具体的なプログラムを教えてもらえると助かります。
|
4
|
-
### ソースコード
|
4
|
+
### 最初のソースコード
|
5
5
|
```
|
6
6
|
from __future__ import print_function
|
7
7
|
|
@@ -102,4 +102,57 @@
|
|
102
102
|
92 # We can't have more than one value on y_type => The set is no more needed
|
103
103
|
|
104
104
|
ValueError: Classification metrics can't handle a mix of binary and multiclass-multioutput targets
|
105
|
+
```
|
106
|
+
###修正後のy_pred2
|
107
|
+
回答でいただいたものをもとにy_pred2を変えたらエラーが変わりました
|
108
|
+
```
|
109
|
+
pred = model.predict(x_test, batch_size=1, verbose=0)
|
110
|
+
y_pred2 = np.max(pred)
|
111
|
+
```
|
112
|
+
### 新しいエラーコード
|
113
|
+
```
|
114
|
+
TypeError Traceback (most recent call last)
|
115
|
+
<ipython-input-10-8349a4884248> in <module>
|
116
|
+
70
|
117
|
+
71
|
118
|
+
---> 72 print('confusion matrix 混合行列 =\n ', confusion_matrix(y_true=y_test2, y_pred=y_pred2))#混合行列
|
119
|
+
73 print('accuracy 正解率 = ', accuracy_score(y_true=y_test2, y_pred=y_pred2))#正解率(正しく分類されたデータ数の割合)
|
120
|
+
74 print('precision 適合率 = ', precision_score(y_true=y_test2, y_pred=y_pred2))#適合率(Aに分類されたデータで実際にAであるデータ数の割合)
|
121
|
+
|
122
|
+
~\Anaconda3\lib\site-packages\sklearn\metrics\_classification.py in confusion_matrix(y_true, y_pred, labels, sample_weight, normalize)
|
123
|
+
266
|
124
|
+
267 """
|
125
|
+
--> 268 y_type, y_true, y_pred = _check_targets(y_true, y_pred)
|
126
|
+
269 if y_type not in ("binary", "multiclass"):
|
127
|
+
270 raise ValueError("%s is not supported" % y_type)
|
128
|
+
|
129
|
+
~\Anaconda3\lib\site-packages\sklearn\metrics\_classification.py in _check_targets(y_true, y_pred)
|
130
|
+
78 y_pred : array or indicator matrix
|
131
|
+
79 """
|
132
|
+
---> 80 check_consistent_length(y_true, y_pred)
|
133
|
+
81 type_true = type_of_target(y_true)
|
134
|
+
82 type_pred = type_of_target(y_pred)
|
135
|
+
|
136
|
+
~\Anaconda3\lib\site-packages\sklearn\utils\validation.py in check_consistent_length(*arrays)
|
137
|
+
206 """
|
138
|
+
207
|
139
|
+
--> 208 lengths = [_num_samples(X) for X in arrays if X is not None]
|
140
|
+
209 uniques = np.unique(lengths)
|
141
|
+
210 if len(uniques) > 1:
|
142
|
+
|
143
|
+
~\Anaconda3\lib\site-packages\sklearn\utils\validation.py in <listcomp>(.0)
|
144
|
+
206 """
|
145
|
+
207
|
146
|
+
--> 208 lengths = [_num_samples(X) for X in arrays if X is not None]
|
147
|
+
209 uniques = np.unique(lengths)
|
148
|
+
210 if len(uniques) > 1:
|
149
|
+
|
150
|
+
~\Anaconda3\lib\site-packages\sklearn\utils\validation.py in _num_samples(x)
|
151
|
+
150 if len(x.shape) == 0:
|
152
|
+
151 raise TypeError("Singleton array %r cannot be considered"
|
153
|
+
--> 152 " a valid collection." % x)
|
154
|
+
153 # Check that shape is returning an integer or default to len
|
155
|
+
154 # Dask dataframes may not return numeric shape[0] value
|
156
|
+
|
157
|
+
TypeError: Singleton array 1.0 cannot be considered a valid collection.
|
105
158
|
```
|