0

I have a list of fit models:

model_list = [xgboost_1, xgboost_2, random_forest_1, random_forest_2 ...]

I want to iterate over them and populate a results dataframe with their prediction output metrics:

results = pd.DataFrame(columns=['models', 'fpr', 'tpr', 'auc'])

I want the models column in results to populate with xgboost_1, xgboost_2, etc. by name.

I can populate the df with all the metrics, but I'm having trouble with the models col.

NaiveBae
  • 358
  • 1
  • 10
  • 2
    No, names refer to values unidirectionally. You cannot go from value to name. Use a better datastructure, such as a dict. – timgeb Mar 16 '22 at 17:50
  • 2
    Generally, if your code relies on variables' names, then you're doing something wrong or inefficiently. Code should never rely on the names of variables. Maybe store the variables in a `dict`, with the dict keys being the same as the variables' names? – Random Davis Mar 16 '22 at 17:50
  • Yes, I'll have to use a dictionary it seems. The code itself doesn't rely on the names per se. I'm just using them to the create visualizations, which is why I want to retain them. – NaiveBae Mar 16 '22 at 18:10

0 Answers0