質問編集履歴
1
具体的なコードを入力
test
CHANGED
File without changes
|
test
CHANGED
@@ -12,7 +12,507 @@
|
|
12
12
|
|
13
13
|
これはいったいどういうことなのでしょうか?
|
14
14
|
|
15
|
-
ちなみにLogistic回帰やカーネルSVCなどで同じことをやると、きちんとpredict_probaで確率が算出されます。なぜかRandomForestClassifierだけうまくいきません。解決策が分かれば教えて頂けますと幸いです。
|
15
|
+
ちなみにLogistic回帰やカーネルSVCなどで同じことをやると、きちんとpredict_probaで確率が算出されます。なぜかRandomForestClassifierだけうまくいきません。解決策が分かれば教えて頂けますと幸いです。以下コードです。
|
16
|
+
|
17
|
+
|
18
|
+
|
19
|
+
import numpy as np
|
20
|
+
|
21
|
+
from pandas import Series,DataFrame
|
22
|
+
|
23
|
+
import pandas as pd
|
24
|
+
|
25
|
+
from sklearn.ensemble import RandomForestClassifier
|
26
|
+
|
27
|
+
from skmultilearn.problem_transform import BinaryRelevance
|
28
|
+
|
29
|
+
|
30
|
+
|
31
|
+
df1 = pd.read_excel('train.xlsx',sheetname='Sheet1')
|
32
|
+
|
33
|
+
df2 = pd.read_excel('test.xlsx',sheetname='Sheet1')
|
34
|
+
|
35
|
+
|
36
|
+
|
37
|
+
df1_x = df1.copy()
|
38
|
+
|
39
|
+
df1_y = df1.copy()
|
40
|
+
|
41
|
+
|
42
|
+
|
43
|
+
df1_x = df1_x.loc[:, "x1":"x777"]
|
44
|
+
|
45
|
+
df1_y = df1_y.loc[:, "a1":"a10"]
|
46
|
+
|
47
|
+
df1_x = df1_x.where(df1_x>0, 0)
|
48
|
+
|
49
|
+
|
50
|
+
|
51
|
+
>>> df1_y
|
52
|
+
|
53
|
+
a1 a2 a3 a4 a5 a6 a7 a8 a9 a10
|
54
|
+
|
55
|
+
0 1 0 0 0 0 0 0 0 0 0
|
56
|
+
|
57
|
+
1 1 0 0 0 0 0 0 0 0 0
|
58
|
+
|
59
|
+
2 1 0 0 0 0 0 0 0 0 0
|
60
|
+
|
61
|
+
3 1 0 0 0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 0 0 0 0 1 0 0
|
116
|
+
|
117
|
+
31 0 0 0 0 0 0 0 1 0 0
|
118
|
+
|
119
|
+
32 0 0 0 0 0 0 0 0 1 0
|
120
|
+
|
121
|
+
33 0 0 0 0 0 0 0 0 1 0
|
122
|
+
|
123
|
+
34 0 0 0 0 0 0 0 0 1 0
|
124
|
+
|
125
|
+
35 0 0 0 0 0 0 0 0 1 0
|
126
|
+
|
127
|
+
36 0 0 0 0 0 0 0 0 0 1
|
128
|
+
|
129
|
+
37 0 0 0 0 0 0 0 0 0 1
|
130
|
+
|
131
|
+
38 0 0 0 0 0 0 0 0 0 1
|
132
|
+
|
133
|
+
39 0 0 0 0 0 0 0 0 0 1
|
134
|
+
|
135
|
+
|
136
|
+
|
137
|
+
model = BinaryRelevance(RandomForestClassifier(random_state = 0, n_estimators = 500))
|
138
|
+
|
139
|
+
model.fit(df1_x, df1_y)
|
140
|
+
|
141
|
+
|
142
|
+
|
143
|
+
df2_x = df2.copy()
|
144
|
+
|
145
|
+
df2_x = df2_x.loc[:, "x1":"x777"]
|
146
|
+
|
147
|
+
df2_x = df2_x.where(df2_x>0, 0)
|
148
|
+
|
149
|
+
|
150
|
+
|
151
|
+
print(model.predict_proba(df2_x))
|
152
|
+
|
153
|
+
|
154
|
+
|
155
|
+
>>> print(model.predict_proba(df2_x))
|
156
|
+
|
157
|
+
(0, 0) 0.768
|
158
|
+
|
159
|
+
(0, 1) 0.098
|
160
|
+
|
161
|
+
(0, 2) 0.032
|
162
|
+
|
163
|
+
(0, 3) 0.036
|
164
|
+
|
165
|
+
(0, 4) 0.048
|
166
|
+
|
167
|
+
(0, 7) 0.084
|
168
|
+
|
169
|
+
(0, 8) 0.056
|
170
|
+
|
171
|
+
(0, 9) 0.012
|
172
|
+
|
173
|
+
(1, 0) 0.04
|
174
|
+
|
175
|
+
(1, 1) 0.042
|
176
|
+
|
177
|
+
(1, 2) 0.732
|
178
|
+
|
179
|
+
(1, 3) 0.242
|
180
|
+
|
181
|
+
(1, 4) 0.024
|
182
|
+
|
183
|
+
(1, 5) 0.008
|
184
|
+
|
185
|
+
(1, 7) 0.038
|
186
|
+
|
187
|
+
(1, 8) 0.1
|
188
|
+
|
189
|
+
(1, 9) 0.014
|
190
|
+
|
191
|
+
(2, 0) 0.012
|
192
|
+
|
193
|
+
(2, 1) 0.024
|
194
|
+
|
195
|
+
(2, 2) 0.072
|
196
|
+
|
197
|
+
(2, 3) 0.012
|
198
|
+
|
199
|
+
(2, 4) 0.818
|
200
|
+
|
201
|
+
(2, 5) 0.09
|
202
|
+
|
203
|
+
(2, 7) 0.036
|
204
|
+
|
205
|
+
(2, 8) 0.028
|
206
|
+
|
207
|
+
(3, 0) 0.002
|
208
|
+
|
209
|
+
(3, 1) 0.024
|
210
|
+
|
211
|
+
(3, 2) 0.026
|
212
|
+
|
213
|
+
(3, 3) 0.004
|
214
|
+
|
215
|
+
(3, 4) 0.002
|
216
|
+
|
217
|
+
(3, 5) 0.004
|
218
|
+
|
219
|
+
(3, 6) 0.002
|
220
|
+
|
221
|
+
(3, 7) 0.61
|
222
|
+
|
223
|
+
(3, 8) 0.03
|
224
|
+
|
225
|
+
(3, 9) 0.006
|
226
|
+
|
227
|
+
(4, 0) 0.008
|
228
|
+
|
229
|
+
(4, 1) 0.04
|
230
|
+
|
231
|
+
(4, 2) 0.118
|
232
|
+
|
233
|
+
(4, 3) 0.016
|
234
|
+
|
235
|
+
(4, 4) 0.034
|
236
|
+
|
237
|
+
(4, 7) 0.032
|
238
|
+
|
239
|
+
(4, 8) 0.518
|
240
|
+
|
241
|
+
(4, 9) 0.22
|
242
|
+
|
243
|
+
(5, 0) 0.102
|
244
|
+
|
245
|
+
(5, 1) 0.08
|
246
|
+
|
247
|
+
(5, 2) 0.252
|
248
|
+
|
249
|
+
(5, 3) 0.062
|
250
|
+
|
251
|
+
(5, 4) 0.034
|
252
|
+
|
253
|
+
(5, 7) 0.082
|
254
|
+
|
255
|
+
(5, 8) 0.036
|
256
|
+
|
257
|
+
(5, 9) 0.02
|
258
|
+
|
259
|
+
(6, 0) 0.018
|
260
|
+
|
261
|
+
(6, 1) 0.032
|
262
|
+
|
263
|
+
(6, 2) 0.316
|
264
|
+
|
265
|
+
(6, 3) 0.102
|
266
|
+
|
267
|
+
(6, 4) 0.062
|
268
|
+
|
269
|
+
(6, 7) 0.052
|
270
|
+
|
271
|
+
(6, 8) 0.11
|
272
|
+
|
273
|
+
(6, 9) 0.016
|
274
|
+
|
275
|
+
(7, 0) 0.002
|
276
|
+
|
277
|
+
(7, 1) 0.026
|
278
|
+
|
279
|
+
(7, 2) 0.002
|
280
|
+
|
281
|
+
(7, 3) 0.032
|
282
|
+
|
283
|
+
(7, 4) 0.002
|
284
|
+
|
285
|
+
(7, 5) 0.084
|
286
|
+
|
287
|
+
(7, 6) 0.038
|
288
|
+
|
289
|
+
(7, 7) 0.322
|
290
|
+
|
291
|
+
(7, 8) 0.024
|
292
|
+
|
293
|
+
(7, 9) 0.002
|
294
|
+
|
295
|
+
(8, 0) 0.004
|
296
|
+
|
297
|
+
(8, 1) 0.046
|
298
|
+
|
299
|
+
(8, 2) 0.068
|
300
|
+
|
301
|
+
(8, 3) 0.028
|
302
|
+
|
303
|
+
(8, 4) 0.004
|
304
|
+
|
305
|
+
(8, 5) 0.008
|
306
|
+
|
307
|
+
(8, 7) 0.078
|
308
|
+
|
309
|
+
(8, 8) 0.158
|
310
|
+
|
311
|
+
(8, 9) 0.072
|
312
|
+
|
313
|
+
(9, 0) 0.13
|
314
|
+
|
315
|
+
(9, 1) 0.028
|
316
|
+
|
317
|
+
(9, 2) 0.046
|
318
|
+
|
319
|
+
(9, 3) 0.028
|
320
|
+
|
321
|
+
(9, 4) 0.004
|
322
|
+
|
323
|
+
(9, 6) 0.004
|
324
|
+
|
325
|
+
(9, 7) 0.088
|
326
|
+
|
327
|
+
(9, 8) 0.136
|
328
|
+
|
329
|
+
(9, 9) 0.038
|
330
|
+
|
331
|
+
(10, 0) 0.02
|
332
|
+
|
333
|
+
(10, 1) 0.092
|
334
|
+
|
335
|
+
(10, 2) 0.314
|
336
|
+
|
337
|
+
(10, 3) 0.034
|
338
|
+
|
339
|
+
(10, 4) 0.018
|
340
|
+
|
341
|
+
(10, 7) 0.072
|
342
|
+
|
343
|
+
(10, 8) 0.06
|
344
|
+
|
345
|
+
(10, 9) 0.036
|
346
|
+
|
347
|
+
(11, 0) 0.016
|
348
|
+
|
349
|
+
(11, 1) 0.006
|
350
|
+
|
351
|
+
(11, 2) 0.174
|
352
|
+
|
353
|
+
(11, 3) 0.054
|
354
|
+
|
355
|
+
(11, 4) 0.056
|
356
|
+
|
357
|
+
(11, 5) 0.028
|
358
|
+
|
359
|
+
(11, 6) 0.002
|
360
|
+
|
361
|
+
(11, 7) 0.052
|
362
|
+
|
363
|
+
(11, 8) 0.156
|
364
|
+
|
365
|
+
(11, 9) 0.012
|
366
|
+
|
367
|
+
(12, 0) 0.122
|
368
|
+
|
369
|
+
(12, 1) 0.064
|
370
|
+
|
371
|
+
(12, 2) 0.232
|
372
|
+
|
373
|
+
(12, 3) 0.094
|
374
|
+
|
375
|
+
(12, 4) 0.036
|
376
|
+
|
377
|
+
(12, 7) 0.088
|
378
|
+
|
379
|
+
(12, 8) 0.05
|
380
|
+
|
381
|
+
(12, 9) 0.038
|
382
|
+
|
383
|
+
(13, 0) 0.016
|
384
|
+
|
385
|
+
(13, 1) 0.006
|
386
|
+
|
387
|
+
(13, 2) 0.256
|
388
|
+
|
389
|
+
(13, 3) 0.08
|
390
|
+
|
391
|
+
(13, 4) 0.042
|
392
|
+
|
393
|
+
(13, 7) 0.054
|
394
|
+
|
395
|
+
(13, 8) 0.132
|
396
|
+
|
397
|
+
(13, 9) 0.03
|
398
|
+
|
399
|
+
(14, 0) 0.002
|
400
|
+
|
401
|
+
(14, 1) 0.008
|
402
|
+
|
403
|
+
(14, 2) 0.016
|
404
|
+
|
405
|
+
(14, 3) 0.012
|
406
|
+
|
407
|
+
(14, 4) 0.038
|
408
|
+
|
409
|
+
(14, 5) 0.002
|
410
|
+
|
411
|
+
(14, 6) 0.004
|
412
|
+
|
413
|
+
(14, 7) 0.158
|
414
|
+
|
415
|
+
(14, 8) 0.164
|
416
|
+
|
417
|
+
(14, 9) 0.006
|
418
|
+
|
419
|
+
(15, 0) 0.012
|
420
|
+
|
421
|
+
(15, 1) 0.022
|
422
|
+
|
423
|
+
(15, 2) 0.104
|
424
|
+
|
425
|
+
(15, 3) 0.014
|
426
|
+
|
427
|
+
(15, 4) 0.03
|
428
|
+
|
429
|
+
(15, 5) 0.002
|
430
|
+
|
431
|
+
(15, 6) 0.012
|
432
|
+
|
433
|
+
(15, 7) 0.1
|
434
|
+
|
435
|
+
(15, 8) 0.186
|
436
|
+
|
437
|
+
(15, 9) 0.074
|
438
|
+
|
439
|
+
(16, 0) 0.062
|
440
|
+
|
441
|
+
(16, 1) 0.034
|
442
|
+
|
443
|
+
(16, 2) 0.1
|
444
|
+
|
445
|
+
(16, 3) 0.094
|
446
|
+
|
447
|
+
(16, 4) 0.04
|
448
|
+
|
449
|
+
(16, 7) 0.112
|
450
|
+
|
451
|
+
(16, 8) 0.042
|
452
|
+
|
453
|
+
(16, 9) 0.03
|
454
|
+
|
455
|
+
(17, 0) 0.022
|
456
|
+
|
457
|
+
(17, 1) 0.012
|
458
|
+
|
459
|
+
(17, 2) 0.194
|
460
|
+
|
461
|
+
(17, 3) 0.05
|
462
|
+
|
463
|
+
(17, 4) 0.072
|
464
|
+
|
465
|
+
(17, 5) 0.006
|
466
|
+
|
467
|
+
(17, 6) 0.008
|
468
|
+
|
469
|
+
(17, 7) 0.05
|
470
|
+
|
471
|
+
(17, 8) 0.03
|
472
|
+
|
473
|
+
(17, 9) 0.022
|
474
|
+
|
475
|
+
(18, 0) 0.002
|
476
|
+
|
477
|
+
(18, 1) 0.034
|
478
|
+
|
479
|
+
(18, 2) 0.028
|
480
|
+
|
481
|
+
(18, 3) 0.016
|
482
|
+
|
483
|
+
(18, 4) 0.008
|
484
|
+
|
485
|
+
(18, 5) 0.002
|
486
|
+
|
487
|
+
(18, 6) 0.002
|
488
|
+
|
489
|
+
(18, 7) 0.08
|
490
|
+
|
491
|
+
(18, 8) 0.096
|
492
|
+
|
493
|
+
(18, 9) 0.02
|
494
|
+
|
495
|
+
(19, 0) 0.024
|
496
|
+
|
497
|
+
(19, 1) 0.042
|
498
|
+
|
499
|
+
(19, 2) 0.19
|
500
|
+
|
501
|
+
(19, 3) 0.064
|
502
|
+
|
503
|
+
(19, 4) 0.02
|
504
|
+
|
505
|
+
(19, 5) 0.002
|
506
|
+
|
507
|
+
(19, 7) 0.118
|
508
|
+
|
509
|
+
(19, 8) 0.104
|
510
|
+
|
511
|
+
(19, 9) 0.048
|
512
|
+
|
513
|
+
|
514
|
+
|
515
|
+
例えば(0, 5)や(0, 6)の確率値が算出されていません。
|
16
516
|
|
17
517
|
|
18
518
|
|