mardi 18 mai 2021

How can I make a conditional expression?

I want to see the modeling output with two data frames.

One data frame has a target value of 1 to 8 and another has only 1,2,3,5,6,7

I made a dictionary to map the values, and I made a code as below to make the probability.

my_dict ={1:'a', 2:'b', 3:'c', 4:'d', 5:'e', 6:'f', 7:'g', 8:'f'}
def func(val):
    for key, value in my_dict.items():
        if val == key:
            return value
    return "There is no such Key"


inputData = [1, 2, 3, 4, 5]

inputData2 = np.array([inputData])

index = 1;
result_data = OrderedDict()
for x in xgb_model.predict_proba(inputData2,ntree_limit=None, validate_features=False,base_margin=None)[0]:
    result_data[func(index)] = round(x,2)
    index += 1


print("result_name : ", max(result_data.items(), key=operator.itemgetter(1))[0])
print("result_value : ", max(xgb_model.predict_proba(inputData2, ntree_limit=None, validate_features=False, base_margin=None)[0]))
print(result_data)

But in the second data frame, the key value is pushed back. For example, a: 0.2, b:0.2, c:0.1, e:0.1, f:0.1 g:0.3 should appear, but in real data, the data should be: a:0.2, b:0.2, c:0.1, d:0.1, e:0.1, f:0.3

I don’t know what I should do.

So I've been working on the code below. Only a:0.2, b:0.2, c:0.1 comes out and ends.

for x in xgb_model.predict_proba(inputData2,ntree_limit=None, validate_features=False,base_margin=None)[0]:
    if index not in y.target.unique().tolist():
        continue
    result_data[func(index)] = round(x,2)
    index += 1

please let me know if you can't understand the code. hope for help. Thank you.

Aucun commentaire:

Enregistrer un commentaire