@@ -1281,7 +1281,7 @@ def _binary_target(
1281
1281
# For h2o models with only one metric provided, return the classification
1282
1282
if h2o_model :
1283
1283
cls .score_code += (
1284
- f"{ '' :4} if input_array.shape[0] == 1\n "
1284
+ f"{ '' :4} if input_array.shape[0] == 1: \n "
1285
1285
f"{ '' :8} if prediction[1][2] > { threshold } :\n "
1286
1286
f"{ '' :12} { metrics } = \" { target_values [0 ]} \" \n "
1287
1287
f"{ '' :8} else:\n "
@@ -1303,7 +1303,7 @@ def _binary_target(
1303
1303
# One return that is the classification
1304
1304
elif len (returns ) == 1 and returns [0 ]:
1305
1305
cls .score_code += (
1306
- f"{ '' :4} if input_array.shape[0] == 1\n "
1306
+ f"{ '' :4} if input_array.shape[0] == 1: \n "
1307
1307
f"{ '' :8} return prediction\n "
1308
1308
f"{ '' :4} else:\n "
1309
1309
f"{ '' :8} return pd.DataFrame({{'{ metrics } ': prediction}})" )
@@ -1313,7 +1313,7 @@ def _binary_target(
1313
1313
# One return that is a probability
1314
1314
elif len (returns ) == 1 and not returns [0 ]:
1315
1315
cls .score_code += (
1316
- f"{ '' :4} if input_array.shape[0] == 1\n "
1316
+ f"{ '' :4} if input_array.shape[0] == 1: \n "
1317
1317
f"{ '' :8} if prediction > { threshold } :\n "
1318
1318
f"{ '' :12} { metrics } = \" { target_values [0 ]} \" \n "
1319
1319
f"{ '' :8} else:\n "
@@ -1334,7 +1334,7 @@ def _binary_target(
1334
1334
elif len (returns ) == 2 and sum (returns ) == 0 :
1335
1335
# Only probabilities returned; return classification for larger value
1336
1336
cls .score_code += (
1337
- f"{ '' :4} if input_array.shape[0] == 1\n "
1337
+ f"{ '' :4} if input_array.shape[0] == 1: \n "
1338
1338
f"{ '' :8} if prediction[0] > prediction[1]:\n "
1339
1339
f"{ '' :12} { metrics } = \" { target_values [0 ]} \" \n "
1340
1340
f"{ '' :8} else:\n "
@@ -1357,7 +1357,7 @@ def _binary_target(
1357
1357
# Determine which return is the classification value
1358
1358
class_index = [i for i , x in enumerate (returns ) if x ][0 ]
1359
1359
cls .score_code += (
1360
- f"{ '' :4} if input_array.shape[0] == 1\n "
1360
+ f"{ '' :4} if input_array.shape[0] == 1: \n "
1361
1361
f"{ '' :8} { metrics } = prediction[{ class_index } ]\n \n return { metrics } \n "
1362
1362
f"{ '' :4} else:\n "
1363
1363
f"{ '' :8} output_table = pd.DataFrame({{'{ metrics } ': [p[{ class_index } ] for p in prediction]}})\n "
@@ -1379,7 +1379,7 @@ def _binary_target(
1379
1379
"the target event to occur."
1380
1380
)
1381
1381
cls .score_code += (
1382
- f"{ '' :4} if input_array.shape[0] == 1\n "
1382
+ f"{ '' :4} if input_array.shape[0] == 1: \n "
1383
1383
f"{ '' :8} return prediction[1][0], float(prediction[1][2])"
1384
1384
f"{ '' :4} else:\n "
1385
1385
f"{ '' :8} output_table = pd.DataFrame(prediction[1:], columns=[{ ',drop,' .join (metrics )} ])\n "
@@ -1396,7 +1396,7 @@ def _binary_target(
1396
1396
"metric is returned first."
1397
1397
)
1398
1398
cls .score_code += (
1399
- f"{ '' :4} if input_array.shape[0] == 1\n "
1399
+ f"{ '' :4} if input_array.shape[0] == 1: \n "
1400
1400
f"{ '' :8} if prediction > { threshold } :\n "
1401
1401
f"{ '' :12} { metrics [0 ]} = \" { target_values [0 ]} \" \n "
1402
1402
f"{ '' :8} else:\n "
@@ -1422,7 +1422,7 @@ def _binary_target(
1422
1422
"target event probability should be returned."
1423
1423
)
1424
1424
cls .score_code += (
1425
- f"{ '' :4} if input_array.shape[0] == 1\n "
1425
+ f"{ '' :4} if input_array.shape[0] == 1: \n "
1426
1426
f"{ '' :8} if prediction[0] > prediction[1]:\n "
1427
1427
f"{ '' :12} { metrics [0 ]} = \" { target_values [0 ]} \" \n "
1428
1428
f"{ '' :8} else:\n "
@@ -1443,7 +1443,7 @@ def _binary_target(
1443
1443
# Return classification and probability value
1444
1444
elif sum (returns ) == 1 and len (returns ) == 2 :
1445
1445
cls .score_code += (
1446
- f"{ '' :4} if input_array.shape[0] == 1\n "
1446
+ f"{ '' :4} if input_array.shape[0] == 1: \n "
1447
1447
f"{ '' :8} return prediction[0], prediction[1]\n "
1448
1448
f"{ '' :4} else:\n "
1449
1449
f"{ '' :8} return pd.DataFrame(prediction, columns=[{ ',' .join (metrics )} ])" )
@@ -1460,7 +1460,7 @@ def _binary_target(
1460
1460
class_index = [i for i , x in enumerate (returns ) if x ][0 ]
1461
1461
if class_index == 0 :
1462
1462
cls .score_code += (
1463
- f"{ '' :4} if input_array.shape[0] == 1\n "
1463
+ f"{ '' :4} if input_array.shape[0] == 1: \n "
1464
1464
f"{ '' :8} return prediction[0], prediction[1]\n "
1465
1465
f"{ '' :4} else:\n "
1466
1466
f"{ '' :8} output_table = pd.DataFrame(prediction, columns=[{ ',' .join (metrics )} ,drop])\n "
@@ -1471,7 +1471,7 @@ def _binary_target(
1471
1471
"""
1472
1472
else :
1473
1473
cls .score_code += (
1474
- f"{ '' :4} if input_array.shape[0] == 1\n "
1474
+ f"{ '' :4} if input_array.shape[0] == 1: \n "
1475
1475
f"{ '' :8} return prediction[{ class_index } ], prediction[0]\n "
1476
1476
f"{ '' :4} else:\n "
1477
1477
f"{ '' :8} output_table = pd.DataFrame(prediction, columns=[{ ',drop,' .join (metrics [::- 1 ])} ])\n "
@@ -1484,7 +1484,7 @@ def _binary_target(
1484
1484
elif len (metrics ) == 3 :
1485
1485
if h2o_model :
1486
1486
cls .score_code += (
1487
- f"{ '' :4} if input_array.shape[0] == 1\n "
1487
+ f"{ '' :4} if input_array.shape[0] == 1: \n "
1488
1488
f"{ '' :8} return prediction[1][0], float(prediction[1][1]), "
1489
1489
f"float(prediction[1][2])\n "
1490
1490
f"{ '' :4} else:\n "
@@ -1500,12 +1500,16 @@ def _binary_target(
1500
1500
"[classification, probability of event, probability of no event]."
1501
1501
)
1502
1502
cls .score_code += (
1503
- f"{ '' :4} if prediction > { threshold } :\n "
1504
- f"{ '' :8} { metrics [0 ]} = \" { target_values [0 ]} \" \n "
1503
+ f"{ '' :4} if input_array.shape[0] == 1:\n "
1504
+ f"{ '' :8} if prediction > { threshold } :\n "
1505
+ f"{ '' :12} { metrics [0 ]} = \" { target_values [0 ]} \" \n "
1506
+ f"{ '' :8} else:\n "
1507
+ f"{ '' :12} { metrics [0 ]} = \" { target_values [1 ]} \" \n "
1508
+ f"{ '' :8} return { metrics [0 ]} , prediction, 1 - prediction\n "
1505
1509
f"{ '' :4} else:\n "
1506
- f"{ '' :8} { metrics [0 ]} = \" { target_values [1 ]} \" \n \n "
1507
- f"{ '' :4 } return { metrics [ 0 ] } , prediction, 1 - prediction"
1508
-
1510
+ f"{ '' :8} classifications = [' { target_values [0 ]} ' if p > { threshold } else ' { target_values [1 ]} ' for p in prediction] \n "
1511
+ f"{ '' :8 } complement = [ 1 - p for p in prediction] \n "
1512
+ f" { '' :8 } return pd.DataFrame({{' { metrics [ 0 ] } ': classifications, ' { metrics [ 1 ] } ': prediction, ' { metrics [ 2 ] } ': complement}})"
1509
1513
)
1510
1514
"""
1511
1515
if prediction > 0.5:
@@ -1522,14 +1526,20 @@ def _binary_target(
1522
1526
"[classification, probability of event, probability of no event]."
1523
1527
)
1524
1528
cls .score_code += (
1525
- f"{ '' :4} if prediction[0] > prediction[1]:\n "
1526
- f"{ '' :8} { metrics [0 ]} = \" { target_values [0 ]} \" \n "
1529
+ f"{ '' :4} if input_array.shape[0] == 1:\n "
1530
+ f"{ '' :8} if prediction[0] > prediction[1]:\n "
1531
+ f"{ '' :12} { metrics [0 ]} = \" { target_values [0 ]} \" \n "
1532
+ f"{ '' :8} else:\n "
1533
+ f"{ '' :12} { metrics [0 ]} = \" { target_values [1 ]} \" \n "
1534
+ f"{ '' :8} return { metrics [0 ]} , prediction[0], prediction[1]\n "
1527
1535
f"{ '' :4} else:\n "
1528
- f"{ '' :8} { metrics [0 ]} = \" { target_values [1 ]} \" \n \n "
1529
- f"{ '' :4} return { metrics [0 ]} , prediction[0], prediction[1]"
1536
+ f"{ '' :8} classifications = ['{ target_values [0 ]} ' if p[0] > p[1] else '{ target_values [1 ]} ' for p in prediction]\n "
1537
+ f"{ '' :8} output_table = pd.DataFrame(prediction, columns=[{ ',' .join (metrics [1 :])} ])\n "
1538
+ f"{ '' :8} output_table = output_table.insert(loc = 0, column = '{ metrics [0 ]} ', value = classifications)\n "
1539
+ f"{ '' :8} return output_table"
1530
1540
)
1531
1541
"""
1532
- if prediction > 0.5 :
1542
+ if prediction[0] > prediction[1] :
1533
1543
classification_variable = 1
1534
1544
else:
1535
1545
classification_variable = 0
@@ -1542,22 +1552,37 @@ def _binary_target(
1542
1552
class_index = [i for i , x in enumerate (returns ) if x ][0 ]
1543
1553
if class_index == 0 :
1544
1554
cls .score_code += (
1545
- f"{ '' :4} return prediction[0], prediction[1], 1 - prediction[1]"
1555
+ f"{ '' :4} if input_array.shape[0] == 1:\n "
1556
+ f"{ '' :8} return prediction[0], prediction[1], 1 - prediction[1]\n "
1557
+ f"{ '' :4} else:\n "
1558
+ f"{ '' :8} complement = [1 - p[1] for p in prediction]\n "
1559
+ f"{ '' :8} output_table = pd.DataFrame(prediction, columns=[{ ',' .join (metrics [:2 ])} ])\n "
1560
+ f"{ '' :8} output_table = output_table.insert(loc = 2, column = '{ metrics [2 ]} ', value = complement)\n "
1561
+ f"{ '' :8} return output_table"
1546
1562
)
1547
1563
"""
1548
1564
return prediction[0], prediction[1], 1 - prediction[1]
1549
1565
"""
1550
1566
else :
1551
1567
cls .score_code += (
1552
- f"{ '' :4} return prediction[1], prediction[0], 1 - prediction[0]"
1568
+ f"{ '' :4} if input_array.shape[0] == 1:\n "
1569
+ f"{ '' :8} return prediction[1], prediction[0], 1 - prediction[0]\n "
1570
+ f"{ '' :4} else:\n "
1571
+ f"{ '' :8} complement = [1 - p[0] for p in prediction]\n "
1572
+ f"{ '' :8} output_table = pd.DataFrame(prediction, columns=[{ ',' .join (metrics [1 ::- 1 ])} ])\n "
1573
+ f"{ '' :8} output_table = output_table.insert(loc = 2, column = '{ metrics [2 ]} ', value = complement)\n "
1574
+ f"{ '' :8} return output_table"
1553
1575
)
1554
1576
"""
1555
1577
return prediction[1], prediction[0], 1 - prediction[0]
1556
1578
"""
1557
1579
# Return all values from prediction method
1558
1580
elif sum (returns ) == 1 and len (returns ) == 3 :
1559
1581
cls .score_code += (
1560
- f"{ '' :4} return prediction[0], prediction[1], prediction[2]"
1582
+ f"{ '' :4} if input_array.shape[0] == 1:\n "
1583
+ f"{ '' :8} return prediction[0], prediction[1], prediction[2]"
1584
+ f"{ '' :4} else:\n "
1585
+ f"{ '' :8} output_table = pd.DataFrame(prediction, columns=[{ ',' .join (metrics )} ])"
1561
1586
)
1562
1587
"""
1563
1588
return prediction[0], prediction[1], prediction[2]
0 commit comments