Skip to content Skip to sidebar Skip to footer

How To Choose The Best Model Dynamically Using Python

Here is my code im building 6 models and i am getting accuracy in that, how do i choose that dynamically which accuracy is greater and i want to execute only that model which as hi

Solution 1:

As I mentionned in a comment, most of your snippet is totally irrelevant and should be replaced by a simplified runnable example.

Now if you question is "I have those objects for which I can get a 'score' and I want to select the one with the higher score", it's quite simple: store the scores along with the objects, sort this base on score and keep the one with the highest score:

import random

defget_score(model):
    # dumbed down example return random.randint(1, 10)


classModel1(object):
    passclassModel2(object):
    passclassModel3(object):
    pass

models = [Model1, Model2, Model3]

# build a list of (score, model) tuples
scores = [(get_score(model), model) for model in models]

# sort it on score
scores.sort(key=item[0])

# get the model with the best score, which is the# the second element of the last item
best = scores[-1][1]

Now please do yourself and the world a favour: LEARN TO ASK CLEAR QUESTIONS WITH ALL RELEVANT INFORMATIONS AND ONLY RELEVANT INFORMATIONS.

https://stackoverflow.com/help/how-to-ask

https://stackoverflow.com/help/mcve

https://stackoverflow.com/help/tagging

Post a Comment for "How To Choose The Best Model Dynamically Using Python"