I have a dictionary storing machine learning prediction probabilities. The keys of the dictionary are the indices of predicted instances and the values are lists containing class probabilities. I want to create a new dictionary to store all class probabilities that are between two numbers (0.48 and 0.55). With the code below I did not get the expected result as it seems my for loop does not iterate through all the values of my dictionary.
d={348: [0,0,0,0.5,0,0,0.49], 349: [0,0,0.3,0.48,0.49,0.55,0.9], 350:
[0,0,0.3,0.45,0.0,0.52,0.8]}
dt={}
for i in d:
for index, value in enumerate(d[i]):
if value >= 0.45 and value <= 0.55:
dt={i: {(str(index + 1)): [value]} }
print(dt)
My output is now is only:
{350: {'6': 0.52}}.
However, I want to get all the numbers from all the values list between 0.48 and 0.55 and get the keys associated with the numbers selected as well as the indices of the numbers in the values list. My desired output is below:
{348: {'4': 0.5, '7': 0,49}, 349: {'4': 0.48, '5': 0.49, '6', 0.55}, 350: {'4': 0.45,
'6': 0.52}