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()
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 eg 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?
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
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.