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

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

從分類器輸出中提取字典值

從分類器輸出中提取字典值

天涯盡頭無女友 2023-06-20 10:46:15
我正在嘗試零鏡頭分類。我得到如下輸出[{'labels': ['rep_appreciation',   'cx_service_appreciation',   'issue_resolved',   'recommend_product',   'callback_realted',   'billing_payment_related',   'disppointed_product'],  'scores': [0.9198898673057556,   0.8672246932983398,   0.79215407371521,   0.6239275336265564,   0.4782547056674957,   0.39024001359939575,   0.010263209231197834],  'sequence': 'Alan Edwards provided me with nothing less the excellent assistance'}以上是數據框中一行的輸出我希望最終構建一個數據框列和輸出值映射如下。如果分數高于特定閾值,標簽為 1s非常感謝任何解決此問題的推動/幫助。
查看完整描述

1 回答

?
元芳怎么了

TA貢獻1798條經驗 獲得超7個贊

定義一個函數,它返回一個鍵:每行的值字典,鍵是標簽,值是基于閾值的 1/0


def get_label_score_dict(row, threshold):

    result_dict = dict()

    for _label, _score in zip(row['labels'], row['scores']):

        if _score > threshold:

            result_dict.update({_label: 1})

        else:

            result_dict.update({_label: 0})

    return result_dict

現在,如果您有一個list_of_rows,其中每一行都采用如上所示的形式,那么您可以使用map函數為每一行獲取上述字典。一旦你得到它,將它轉換成一個 DataFrame。


th = 0.5    #whatever threshold value you want

result = list(map(lambda x: get_label_score_dict(x, th), list_of_rows))

result_df = pd.DataFrame(result)


查看完整回答
反對 回復 2023-06-20
  • 1 回答
  • 0 關注
  • 115 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

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

幫助反饋 APP下載

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

公眾號

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