'Discrepancy between LightGBM probabilities from Java and Python
I have a PMML file containing a LightGBM model. I want to calculate the probabilities of some dataset records.
I am using Python. I load the .pkl file as follows:
from pypmml import Model
model = Model.fromFile(locationOfThePmmlFile+'flaml_lgbm.pmml')
Then I process a dataset X to calculate the probability as follows:
y_pred_proba = []
for i in range(len(X)):
if(i < 10):
print("# records processed: ",str(i)," ... ")
elif(i%10000 == 0):
print("# records processed: ",str(i)," ... ")
y_pred_proba.append(0)
y_pred_proba[i] = **model.predict**(X[i])[1]
print(y_pred_proba[i])
Notice that I have used model.predict instead of model.predict_probabecause model.predict_proba gave the following error:
AttributeError: 'Model' object has no attribute 'predict_proba'
I have then used model.predict instead: to be honest, I was expecting model.predict to return either 0 or 1, but instead it returns arrays of probabilities (in the code, I keep the second element of the array as I want to see the probability of being 1).
I write out the results to a dataset that also contains the probabilities calculated in Java from exactly the same PMML file. And I notice that the probabilities calculated in Java are completely different than the probabilities calculated in Python. See an example below:
Why are the probabilities so different (there are no missing values in the predictive features)? The Java probabilities make sense to me. Those calculated in Python seem completely wrong.
Can anyone help me with this, please?
Solution 1:[1]
Try this code :D
const arr1=[
{ name: "viet" },
{ name: "hai" },
{ name: "han" }
]
const arr2= ["viet", "hai"];
const result = arr1.filter(item => !arr2.includes(item.name))
console.log(result) // [{name: "han"}]
Solution 2:[2]
const arr1=[
{ name: "viet" },
{ name: "hai" },
{ name: "han" }
]
const arr2= ["viet", "hai"];
let res = arr1.filter(function (n) {
return !this.has(n.name);
}, new Set(arr2));
console.log(res);
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Dae Hyeon Mun |
| Solution 2 | Wang YinXing |

