0

I created a dictionary in a for loop which gave me the following 192 results:

dic_aic = {0: 16.83024400288158,
1: 10.580792750644934,
2: 10.460203246761916,
3: 10.44309674334913,
4: 10.425859422774248,
        ...
191: 10.273789550619007,
192: 10.272853618268071}

When I plot this out with pandas I get the following:

aic_df = pd.DataFrame(aic_dic.items(), columns=['Order', 'AIC'])
aic_df = aic_df.set_index('Order')
aic_df[1:].plot()

enter image description here

With

 min(aic_dic, key=aic_dic.get)

I get the minimum value in my dic with 192. But as you can see in the picture the difference between the AIC at 192 and e.g. 96 is very small with only 10.272853618268071 - 10.28435108717606 = 0.01149... I am trying to find the optimized value around 96. Does anybody have an idea on how to solve this with python? Maybe with an integral?

1 Answer 1

1

You can first set min value as you just did.

Then you need to set a tolerance value like 0.1.

Then you can return smallest key value with with satisfies min +- tolerance

minimum = min(aic_dic, key=aic_dic.get)  #your code here
tolerance = 0.1 #could be higher lower up to you
possible_answers = []
for key,value in your_dict.items():
    if minimum + tolerance > value:
          possible_answers(key)
print(min(possible_answers)) # you can adjust here as according to your need
Sign up to request clarification or add additional context in comments.

2 Comments

Good approach, but I don't know the min yet. I want to find it automatically. Do you have another idea?
I was thinking minimum = min(aic_dic, key=aic_dic.get) PS: since you will going to use min function afterward, you need to use different variable naming then min in the variable names, I will edit my answer accordingly. For tolerance you set equal to one percent of min , ie. tolerance = 0.01 * minimum @chriuxenman1

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.