亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

過濾列和排名熊貓

過濾列和排名熊貓

弒天下 2023-02-15 17:28:30
我的數據框是 -      Metric       Value              Model0   Accuracy        87.608760       Logistic_Regression1   Neg_log_loss    -0.332951       Logistic_Regression2   F1_measure      0.854182        Logistic_Regression3   AUC             0.927378        Logistic_Regression4   Precision       0.871396        Logistic_Regression5   Recall          0.837687        Logistic_Regression6   Accuracy        96.433245       Random_Forest7   Neg_log_loss   -0.105780        Random_Forest8   F1_measure      0.958133        Random_Forest9   AUC             0.994008        Random_Forest10  Precision       0.974733        Random_Forest11  Recall          0.942097        Random_Forest12  Accuracy        84.836008       Naive_Bayes13  Neg_log_loss   -0.917701        Naive_Bayes14  F1_measure      0.823289        Naive_Bayes15  AUC             0.915744        Naive_Bayes16  Precision       0.831528        Naive_Bayes17  Recall          0.815300        Naive_Bayesmetric ='AUC'現在我想選擇 Metric 列('AUC')最高的模型。在這種情況下,它將打印 model_nameRandom_Forest
查看完整描述

4 回答

?
MM們

TA貢獻1886條經驗 獲得超2個贊

使用,Series.eq創建一個布爾掩碼,然后使用此掩碼以及Series.idxmax獲取指標所在index列中的最大值,最后使用此索引獲取相應的:ValueAUCModel

ind =df.loc[df['Metric'].eq('AUC'), 'Value'].idxmax()

model = df.loc[ind, 'Model']

結果:


print(model)


'Random_Forest'




查看完整回答
反對 回復 2023-02-15
?
拉丁的傳說

TA貢獻1789條經驗 獲得超8個贊

除了其他答案,您還可以考慮dfmax()所有'Metric'行對您進行分組:

df.groupby(['Metric'], as_index=False)['Value','Model'].max()

然后你也可以.query()為“AUC”指標的“模型”列:

df.groupby(['Metric'], as_index=False)['Value','Model'].max().query('Metric == "AUC"')['Model']


查看完整回答
反對 回復 2023-02-15
?
慕妹3146593

TA貢獻1820條經驗 獲得超9個贊

干得好:


df.loc[df.Metric == 'AUC', ['Value', 'Model']].max()['Model']


## -- End pasted text --

Out[1]: 'Random_Forest'


查看完整回答
反對 回復 2023-02-15
?
慕容森

TA貢獻1853條經驗 獲得超18個贊

如果你想用基礎知識來做,那么:


empty_value_list=[]


for i,j in zip(df['Metric'],df['Value']):

    if i=='AUC':

        empty_value_list.append(j)


max_value=max(empty_value_list)


for i,j,k in zip(df['Metric'],df['Value'],df['Model'])

    if i=='AUC' and j==max_value:

        print(k)

      

Out[1]: 'Random_Forest'  


查看完整回答
反對 回復 2023-02-15
  • 4 回答
  • 0 關注
  • 141 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號