|
20 | 20 | "trustyai.init(\n", |
21 | 21 | " path=[\n", |
22 | 22 | " \"../dep/org/kie/kogito/explainability-core/1.8.0.Final/*\",\n", |
23 | | - "# \"../dep/org/kie/kogito/explainability-core/1.8.0.Final/explainability-core-2.0.0-SNAPSHOT.jar\",\n", |
24 | | - "# \"../dep/org/kie/kogito/explainability-core/1.8.0.Final/explainability-core-1.8.0.Final-tests.jar\",\n", |
25 | 23 | " \"../dep/org/slf4j/slf4j-api/1.7.30/slf4j-api-1.7.30.jar\",\n", |
26 | 24 | " \"../dep/org/apache/commons/commons-lang3/3.12.0/commons-lang3-3.12.0.jar\",\n", |
27 | 25 | " \"../dep/org/optaplanner/optaplanner-core/8.8.0.Final/optaplanner-core-8.8.0.Final.jar\",\n", |
|
141 | 139 | "name": "stdout", |
142 | 140 | "output_type": "stream", |
143 | 141 | "text": [ |
144 | | - "Feature x1 has value 5.89410604979949\n", |
145 | | - "Feature x2 has value 4.6702081567068525\n", |
146 | | - "Feature x3 has value 7.484002107104038\n", |
147 | | - "Feature x4 has value 8.39980161062865\n", |
| 142 | + "Feature x1 has value 9.135811031480424\n", |
| 143 | + "Feature x2 has value 5.0454318078238245\n", |
| 144 | + "Feature x3 has value 1.1416494951836265\n", |
| 145 | + "Feature x4 has value 0.362431844924509\n", |
148 | 146 | "\n", |
149 | | - "Features sum is 26.44811792423903\n" |
| 147 | + "Features sum is 15.685324179412383\n" |
150 | 148 | ] |
151 | 149 | } |
152 | 150 | ], |
|
378 | 376 | "name": "stdout", |
379 | 377 | "output_type": "stream", |
380 | 378 | "text": [ |
381 | | - "java.lang.DoubleFeature{value=6.143270159874259, intRangeMinimum=0.0, intRangeMaximum=1000.0, id='x1'}\n", |
382 | | - "java.lang.DoubleFeature{value=4.6702081567068525, intRangeMinimum=0.0, intRangeMaximum=1000.0, id='x2'}\n", |
383 | | - "java.lang.DoubleFeature{value=7.484002107104038, intRangeMinimum=0.0, intRangeMaximum=1000.0, id='x3'}\n", |
384 | | - "java.lang.DoubleFeature{value=481.34447531284985, intRangeMinimum=0.0, intRangeMaximum=1000.0, id='x4'}\n", |
| 379 | + "java.lang.DoubleFeature{value=9.135811031480424, intRangeMinimum=0.0, intRangeMaximum=1000.0, id='x1'}\n", |
| 380 | + "java.lang.DoubleFeature{value=6.268698018465302, intRangeMinimum=0.0, intRangeMaximum=1000.0, id='x2'}\n", |
| 381 | + "java.lang.DoubleFeature{value=484.55755944660217, intRangeMinimum=0.0, intRangeMaximum=1000.0, id='x3'}\n", |
| 382 | + "java.lang.DoubleFeature{value=0.362431844924509, intRangeMinimum=0.0, intRangeMaximum=1000.0, id='x4'}\n", |
385 | 383 | "\n", |
386 | | - "Feature sum is 499.641955736535\n" |
| 384 | + "Feature sum is 500.3245003414724\n" |
387 | 385 | ] |
388 | 386 | } |
389 | 387 | ], |
|
472 | 470 | "name": "stdout", |
473 | 471 | "output_type": "stream", |
474 | 472 | "text": [ |
475 | | - "Original x1: 5.89410604979949\n", |
476 | | - "Original x4: 8.39980161062865\n", |
| 473 | + "Original x1: 9.135811031480424\n", |
| 474 | + "Original x4: 0.362431844924509\n", |
477 | 475 | "\n", |
478 | | - "java.lang.DoubleFeature{value=5.89410604979949, intRangeMinimum=5.89410604979949, intRangeMaximum=5.89410604979949, id='x1'}\n", |
479 | | - "java.lang.DoubleFeature{value=4.467150339062309, intRangeMinimum=0.0, intRangeMaximum=1000.0, id='x2'}\n", |
480 | | - "java.lang.DoubleFeature{value=480.4495023914547, intRangeMinimum=0.0, intRangeMaximum=1000.0, id='x3'}\n", |
481 | | - "java.lang.DoubleFeature{value=8.39980161062865, intRangeMinimum=8.39980161062865, intRangeMaximum=8.39980161062865, id='x4'}\n" |
| 476 | + "java.lang.DoubleFeature{value=9.135811031480424, intRangeMinimum=9.135811031480424, intRangeMaximum=9.135811031480424, id='x1'}\n", |
| 477 | + "java.lang.DoubleFeature{value=5.522381982853708, intRangeMinimum=0.0, intRangeMaximum=1000.0, id='x2'}\n", |
| 478 | + "java.lang.DoubleFeature{value=484.5070395184806, intRangeMinimum=0.0, intRangeMaximum=1000.0, id='x3'}\n", |
| 479 | + "java.lang.DoubleFeature{value=0.362431844924509, intRangeMinimum=0.362431844924509, intRangeMaximum=0.362431844924509, id='x4'}\n" |
482 | 480 | ] |
483 | 481 | } |
484 | 482 | ], |
|
659 | 657 | "\n", |
660 | 658 | "def predict(inputs: List[PredictionInput]) -> List[PredictionOutput]:\n", |
661 | 659 | " values = [feature.getValue().asNumber() for feature in inputs.get(0).getFeatures()]\n", |
662 | | - " result = xg_model.predict(np.array([values]))\n", |
663 | | - " value = False if result[0]==0 else True\n", |
664 | | - " output = Output(\"PaidLoan\", Type.BOOLEAN, Value(value), 0.0)\n", |
| 660 | + " result = xg_model.predict_proba(np.array([values]))\n", |
| 661 | + " false_prob, true_prob = result[0]\n", |
| 662 | + " if false_prob > true_prob:\n", |
| 663 | + " prediction = (False, false_prob)\n", |
| 664 | + " else:\n", |
| 665 | + " prediction = (True, true_prob)\n", |
| 666 | + " output = Output(\"PaidLoan\", Type.BOOLEAN, Value(prediction[0]), prediction[1])\n", |
665 | 667 | " return toJList([PredictionOutput([output])])" |
666 | 668 | ] |
667 | 669 | }, |
|
697 | 699 | }, |
698 | 700 | { |
699 | 701 | "cell_type": "code", |
700 | | - "execution_count": 25, |
| 702 | + "execution_count": 27, |
701 | 703 | "id": "06d52535", |
702 | 704 | "metadata": {}, |
703 | 705 | "outputs": [], |
704 | 706 | "source": [ |
705 | | - "features = [\n", |
706 | | - " FeatureFactory.newBooleanFeature(\"NewCreditCustomer\", False),\n", |
707 | | - " FeatureFactory.newNumericalFeature(\"Amount\", 2125.0),\n", |
708 | | - " FeatureFactory.newNumericalFeature(\"Interest\", 20.97),\n", |
709 | | - " FeatureFactory.newNumericalFeature(\"LoanDuration\", 60.0),\n", |
710 | | - " FeatureFactory.newNumericalFeature(\"Education\", 4.0),\n", |
711 | | - " FeatureFactory.newNumericalFeature(\"NrOfDependants\", 0.0),\n", |
712 | | - " FeatureFactory.newNumericalFeature(\"EmploymentDurationCurrentEmployer\", 6.0),\n", |
713 | | - " FeatureFactory.newNumericalFeature(\"IncomeFromPrincipalEmployer\", 0.0),\n", |
714 | | - " FeatureFactory.newNumericalFeature(\"IncomeFromPension\", 301.0),\n", |
715 | | - " FeatureFactory.newNumericalFeature(\"IncomeFromFamilyAllowance\", 0.0),\n", |
716 | | - " FeatureFactory.newNumericalFeature(\"IncomeFromSocialWelfare\", 53.0),\n", |
717 | | - " FeatureFactory.newNumericalFeature(\"IncomeFromLeavePay\", 0.0),\n", |
718 | | - " FeatureFactory.newNumericalFeature(\"IncomeFromChildSupport\", 0.0),\n", |
719 | | - " FeatureFactory.newNumericalFeature(\"IncomeOther\", 0.0),\n", |
720 | | - " FeatureFactory.newNumericalFeature(\"ExistingLiabilities\", 8.0),\n", |
721 | | - " FeatureFactory.newNumericalFeature(\"RefinanceLiabilities\", 6.0),\n", |
722 | | - " FeatureFactory.newNumericalFeature(\"DebtToIncome\", 26.29),\n", |
723 | | - " FeatureFactory.newNumericalFeature(\"FreeCash\", 10.92),\n", |
724 | | - " FeatureFactory.newNumericalFeature(\"CreditScoreEeMini\", 1000.0),\n", |
725 | | - " FeatureFactory.newNumericalFeature(\"NoOfPreviousLoansBeforeLoan\", 1.0),\n", |
726 | | - " FeatureFactory.newNumericalFeature(\"AmountOfPreviousLoansBeforeLoan\", 500.0),\n", |
727 | | - " FeatureFactory.newNumericalFeature(\"PreviousRepaymentsBeforeLoan\", 590.95),\n", |
728 | | - " FeatureFactory.newNumericalFeature(\"PreviousEarlyRepaymentsBefoleLoan\", 0.0),\n", |
729 | | - " FeatureFactory.newNumericalFeature(\"PreviousEarlyRepaymentsCountBeforeLoan\", 0.0),\n", |
730 | | - " FeatureFactory.newBooleanFeature(\"Council_house\", False),\n", |
731 | | - " FeatureFactory.newBooleanFeature(\"Homeless\", False),\n", |
732 | | - " FeatureFactory.newBooleanFeature(\"Joint_ownership\", False),\n", |
733 | | - " FeatureFactory.newBooleanFeature(\"Joint_tenant\", False),\n", |
734 | | - " FeatureFactory.newBooleanFeature(\"Living_with_parents\", False),\n", |
735 | | - " FeatureFactory.newBooleanFeature(\"Mortgage\", False),\n", |
736 | | - " FeatureFactory.newBooleanFeature(\"Other\", False),\n", |
737 | | - " FeatureFactory.newBooleanFeature(\"Owner\", False),\n", |
738 | | - " FeatureFactory.newBooleanFeature(\"Owner_with_encumbrance\", True),\n", |
739 | | - " FeatureFactory.newBooleanFeature(\"Tenant\", True),\n", |
740 | | - " FeatureFactory.newBooleanFeature(\"Entrepreneur\", False),\n", |
741 | | - " FeatureFactory.newBooleanFeature(\"Fully\", False),\n", |
742 | | - " FeatureFactory.newBooleanFeature(\"Partially\", False),\n", |
743 | | - " FeatureFactory.newBooleanFeature(\"Retiree\", True),\n", |
744 | | - " FeatureFactory.newBooleanFeature(\"Self_employed\", False), \n", |
745 | | - "]" |
| 707 | + "def make_feature(name, value):\n", |
| 708 | + " if type(value) is bool:\n", |
| 709 | + " return FeatureFactory.newBooleanFeature(name, value)\n", |
| 710 | + " else:\n", |
| 711 | + " return FeatureFactory.newNumericalFeature(name, value)\n", |
| 712 | + "\n", |
| 713 | + "features = [make_feature(p[0], p[1]) for p in [(\"NewCreditCustomer\", False),\n", |
| 714 | + " (\"Amount\", 2125.0),\n", |
| 715 | + " (\"Interest\", 20.97),\n", |
| 716 | + " (\"LoanDuration\", 60.0),\n", |
| 717 | + " (\"Education\", 4.0),\n", |
| 718 | + " (\"NrOfDependants\", 0.0),\n", |
| 719 | + " (\"EmploymentDurationCurrentEmployer\", 6.0),\n", |
| 720 | + " (\"IncomeFromPrincipalEmployer\", 0.0),\n", |
| 721 | + " (\"IncomeFromPension\", 301.0),\n", |
| 722 | + " (\"IncomeFromFamilyAllowance\", 0.0),\n", |
| 723 | + " (\"IncomeFromSocialWelfare\", 53.0),\n", |
| 724 | + " (\"IncomeFromLeavePay\", 0.0),\n", |
| 725 | + " (\"IncomeFromChildSupport\", 0.0),\n", |
| 726 | + " (\"IncomeOther\", 0.0),\n", |
| 727 | + " (\"ExistingLiabilities\", 8.0),\n", |
| 728 | + " (\"RefinanceLiabilities\", 6.0),\n", |
| 729 | + " (\"DebtToIncome\", 26.29),\n", |
| 730 | + " (\"FreeCash\", 10.92),\n", |
| 731 | + " (\"CreditScoreEeMini\", 1000.0),\n", |
| 732 | + " (\"NoOfPreviousLoansBeforeLoan\", 1.0),\n", |
| 733 | + " (\"AmountOfPreviousLoansBeforeLoan\", 500.0),\n", |
| 734 | + " (\"PreviousRepaymentsBeforeLoan\", 590.95),\n", |
| 735 | + " (\"PreviousEarlyRepaymentsBefoleLoan\", 0.0),\n", |
| 736 | + " (\"PreviousEarlyRepaymentsCountBeforeLoan\", 0.0),\n", |
| 737 | + " (\"Council_house\", False),\n", |
| 738 | + " (\"Homeless\", False),\n", |
| 739 | + " (\"Joint_ownership\", False),\n", |
| 740 | + " (\"Joint_tenant\", False),\n", |
| 741 | + " (\"Living_with_parents\", False),\n", |
| 742 | + " (\"Mortgage\", False),\n", |
| 743 | + " (\"Other\", False),\n", |
| 744 | + " (\"Owner\", False),\n", |
| 745 | + " (\"Owner_with_encumbrance\", True),\n", |
| 746 | + " (\"Tenant\", True),\n", |
| 747 | + " (\"Entrepreneur\", False),\n", |
| 748 | + " (\"Fully\", False),\n", |
| 749 | + " (\"Partially\", False),\n", |
| 750 | + " (\"Retiree\", True),\n", |
| 751 | + " (\"Self_employed\", False)]]" |
746 | 752 | ] |
747 | 753 | }, |
748 | 754 | { |
|
755 | 761 | }, |
756 | 762 | { |
757 | 763 | "cell_type": "code", |
758 | | - "execution_count": 26, |
| 764 | + "execution_count": 28, |
759 | 765 | "id": "2b279cae", |
760 | 766 | "metadata": {}, |
761 | 767 | "outputs": [ |
762 | 768 | { |
763 | 769 | "data": { |
764 | 770 | "text/plain": [ |
765 | | - "'Output{value=false, type=boolean, score=0.0, name='PaidLoan'}'" |
| 771 | + "'Output{value=false, type=boolean, score=0.7835956811904907, name='PaidLoan'}'" |
766 | 772 | ] |
767 | 773 | }, |
768 | | - "execution_count": 26, |
| 774 | + "execution_count": 28, |
769 | 775 | "metadata": {}, |
770 | 776 | "output_type": "execute_result" |
771 | 777 | } |
|
788 | 794 | }, |
789 | 795 | { |
790 | 796 | "cell_type": "code", |
791 | | - "execution_count": 28, |
| 797 | + "execution_count": 29, |
792 | 798 | "id": "18fff350", |
793 | 799 | "metadata": {}, |
794 | 800 | "outputs": [], |
|
808 | 814 | }, |
809 | 815 | { |
810 | 816 | "cell_type": "code", |
811 | | - "execution_count": 29, |
| 817 | + "execution_count": 30, |
812 | 818 | "id": "3a4815d9", |
813 | 819 | "metadata": {}, |
814 | 820 | "outputs": [], |
|
826 | 832 | }, |
827 | 833 | { |
828 | 834 | "cell_type": "code", |
829 | | - "execution_count": 30, |
| 835 | + "execution_count": 31, |
830 | 836 | "id": "7277e246", |
831 | 837 | "metadata": {}, |
832 | 838 | "outputs": [], |
|
850 | 856 | }, |
851 | 857 | { |
852 | 858 | "cell_type": "code", |
853 | | - "execution_count": 31, |
| 859 | + "execution_count": 32, |
854 | 860 | "id": "24d45182", |
855 | 861 | "metadata": {}, |
856 | 862 | "outputs": [], |
|
868 | 874 | }, |
869 | 875 | { |
870 | 876 | "cell_type": "code", |
871 | | - "execution_count": 32, |
| 877 | + "execution_count": 33, |
872 | 878 | "id": "f9340354", |
873 | 879 | "metadata": {}, |
874 | 880 | "outputs": [], |
|
886 | 892 | }, |
887 | 893 | { |
888 | 894 | "cell_type": "code", |
889 | | - "execution_count": 33, |
| 895 | + "execution_count": 34, |
890 | 896 | "id": "ef45bde0", |
891 | 897 | "metadata": {}, |
892 | 898 | "outputs": [], |
|
908 | 914 | }, |
909 | 915 | { |
910 | 916 | "cell_type": "code", |
911 | | - "execution_count": 34, |
| 917 | + "execution_count": 35, |
912 | 918 | "id": "e9ea7928", |
913 | 919 | "metadata": {}, |
914 | 920 | "outputs": [], |
|
926 | 932 | }, |
927 | 933 | { |
928 | 934 | "cell_type": "code", |
929 | | - "execution_count": 35, |
| 935 | + "execution_count": 36, |
930 | 936 | "id": "3433536d", |
931 | 937 | "metadata": {}, |
932 | 938 | "outputs": [ |
933 | 939 | { |
934 | 940 | "data": { |
935 | 941 | "text/plain": [ |
936 | | - "'Output{value=true, type=boolean, score=0.0, name='PaidLoan'}'" |
| 942 | + "'Output{value=true, type=boolean, score=0.6006738543510437, name='PaidLoan'}'" |
937 | 943 | ] |
938 | 944 | }, |
939 | | - "execution_count": 35, |
| 945 | + "execution_count": 36, |
940 | 946 | "metadata": {}, |
941 | 947 | "output_type": "execute_result" |
942 | 948 | } |
|
956 | 962 | }, |
957 | 963 | { |
958 | 964 | "cell_type": "code", |
959 | | - "execution_count": 36, |
| 965 | + "execution_count": 37, |
960 | 966 | "id": "aad1faa7", |
961 | 967 | "metadata": {}, |
962 | 968 | "outputs": [ |
|
1008 | 1014 | }, |
1009 | 1015 | { |
1010 | 1016 | "cell_type": "code", |
1011 | | - "execution_count": 37, |
| 1017 | + "execution_count": 38, |
1012 | 1018 | "id": "3cfa92da", |
1013 | 1019 | "metadata": {}, |
1014 | 1020 | "outputs": [], |
|
1070 | 1076 | }, |
1071 | 1077 | { |
1072 | 1078 | "cell_type": "code", |
1073 | | - "execution_count": 38, |
| 1079 | + "execution_count": 39, |
1074 | 1080 | "id": "6e91cb5f", |
1075 | 1081 | "metadata": {}, |
1076 | 1082 | "outputs": [], |
|
1128 | 1134 | }, |
1129 | 1135 | { |
1130 | 1136 | "cell_type": "code", |
1131 | | - "execution_count": 39, |
| 1137 | + "execution_count": 40, |
1132 | 1138 | "id": "0d39a0ab", |
1133 | 1139 | "metadata": {}, |
1134 | 1140 | "outputs": [], |
|
1150 | 1156 | }, |
1151 | 1157 | { |
1152 | 1158 | "cell_type": "code", |
1153 | | - "execution_count": 40, |
| 1159 | + "execution_count": 41, |
1154 | 1160 | "id": "57a9b194", |
1155 | 1161 | "metadata": {}, |
1156 | 1162 | "outputs": [], |
|
1168 | 1174 | }, |
1169 | 1175 | { |
1170 | 1176 | "cell_type": "code", |
1171 | | - "execution_count": 41, |
| 1177 | + "execution_count": 42, |
1172 | 1178 | "id": "f052a7f1", |
1173 | 1179 | "metadata": {}, |
1174 | 1180 | "outputs": [ |
1175 | 1181 | { |
1176 | 1182 | "data": { |
1177 | 1183 | "text/plain": [ |
1178 | | - "'Output{value=true, type=boolean, score=0.0, name='PaidLoan'}'" |
| 1184 | + "'Output{value=true, type=boolean, score=0.5038489103317261, name='PaidLoan'}'" |
1179 | 1185 | ] |
1180 | 1186 | }, |
1181 | | - "execution_count": 41, |
| 1187 | + "execution_count": 42, |
1182 | 1188 | "metadata": {}, |
1183 | 1189 | "output_type": "execute_result" |
1184 | 1190 | } |
|
1198 | 1204 | }, |
1199 | 1205 | { |
1200 | 1206 | "cell_type": "code", |
1201 | | - "execution_count": 42, |
| 1207 | + "execution_count": 43, |
1202 | 1208 | "id": "0557e545", |
1203 | 1209 | "metadata": {}, |
1204 | 1210 | "outputs": [ |
|
1207 | 1213 | "output_type": "stream", |
1208 | 1214 | "text": [ |
1209 | 1215 | "Feature 'LoanDuration': 60.0 -> 56.947228037333545\n", |
1210 | | - "Feature 'IncomeFromSocialWelfare': 53.0 -> 60.0\n", |
1211 | | - "Feature 'FreeCash': 10.92 -> 10.914352713171315\n", |
1212 | | - "Feature 'Tenant': true -> false\n" |
| 1216 | + "Feature 'IncomeFromSocialWelfare': 53.0 -> 59.6876474017064\n", |
| 1217 | + "Feature 'FreeCash': 10.92 -> 10.914352713171315\n" |
1213 | 1218 | ] |
1214 | 1219 | } |
1215 | 1220 | ], |
|
0 commit comments