我的数据框是-
Metric Value Model
0 Accuracy 87.608760 Logistic_Regression
1 Neg_log_loss -0.332951 Logistic_Regression
2 F1_measure 0.854182 Logistic_Regression
3 AUC 0.927378 Logistic_Regression
4 Precision 0.871396 Logistic_Regression
5 Recall 0.837687 Logistic_Regression
6 Accuracy 96.433245 Random_Forest
7 Neg_log_loss -0.105780 Random_Forest
8 F1_measure 0.958133 Random_Forest
9 AUC 0.994008 Random_Forest
10 Precision 0.974733 Random_Forest
11 Recall 0.942097 Random_Forest
12 Accuracy 84.836008 Naive_Bayes
13 Neg_log_loss -0.917701 Naive_Bayes
14 F1_measure 0.823289 Naive_Bayes
15 AUC 0.915744 Naive_Bayes
16 Precision 0.831528 Naive_Bayes
17 Recall 0.815300 Naive_Bayesmetric ='AUC'
现在我想选择Metric列(‘AUC’)最高的Model。在本例中,它将打印model_name Random_Forest
发布于 2020-07-04 15:54:57
使用,Series.eq创建一个布尔掩码,然后将此掩码与Series.idxmax一起使用,以获取度量为AUC的列Value中最大值的index,最后使用此索引获取相应的Model
ind =df.loc[df['Metric'].eq('AUC'), 'Value'].idxmax()
model = df.loc[ind, 'Model']结果:
print(model)
'Random_Forest'发布于 2020-07-04 16:03:27
这就是了:
df.loc[df.Metric == 'AUC', ['Value', 'Model']].max()['Model']
## -- End pasted text --
Out[1]: 'Random_Forest'发布于 2020-07-04 16:27:13
作为其他答案的替代方案,您还可以考虑按所有'Metric'行的max()对df进行分组:
df.groupby(['Metric'], as_index=False)['Value','Model'].max()然后,您还可以为"AUC“指标的”模型“列执行.query():
df.groupby(['Metric'], as_index=False)['Value','Model'].max().query('Metric == "AUC"')['Model']https://stackoverflow.com/questions/62726666
复制相似问题