File tree Expand file tree Collapse file tree 1 file changed +5
-5
lines changed Expand file tree Collapse file tree 1 file changed +5
-5
lines changed Original file line number Diff line number Diff line change 122
122
remove = remove )
123
123
print ('data loaded' )
124
124
125
- categories = data_train .target_names # for case categories == None
125
+ # order of labels in `target_names` can be different from `categories`
126
+ target_names = data_train .target_names
126
127
127
128
128
129
def size_mb (docs ):
@@ -218,16 +219,15 @@ def benchmark(clf):
218
219
219
220
if opts .print_top10 and feature_names is not None :
220
221
print ("top 10 keywords per class:" )
221
- for i , category in enumerate (categories ):
222
+ for i , label in enumerate (target_names ):
222
223
top10 = np .argsort (clf .coef_ [i ])[- 10 :]
223
- print (trim ("%s: %s"
224
- % (category , " " .join (feature_names [top10 ]))))
224
+ print (trim ("%s: %s" % (label , " " .join (feature_names [top10 ]))))
225
225
print ()
226
226
227
227
if opts .print_report :
228
228
print ("classification report:" )
229
229
print (metrics .classification_report (y_test , pred ,
230
- target_names = categories ))
230
+ target_names = target_names ))
231
231
232
232
if opts .print_cm :
233
233
print ("confusion matrix:" )
You can’t perform that action at this time.
0 commit comments