我正在研究一種自動化解決方案,用于在 Python 中訓練二元相關性多標簽分類模型。我使用skmultilearn的關鍵元素是 TFIDF 矢量化器和BinaryRelevance(MultinomialNB())函式。
我遇到了準確性問題,需要提高訓練資料的質量。
這是非常勞動密集型的(在 Excel 中閱讀或手動過濾數百篇新聞文章),因此我正在尋找使其自動化的方法。我的資料來自一個大學資料庫,我在其中搜索與我正在學習的內容相關的文章。我的最終目標是為所有文章分配六個標簽,其中一篇文章可以有零個、一個或多個標簽。我目前快速生成訓練資料的想法是使用每個標簽的標準搜索大學資料庫,然后對其進行標記以生成如下所示的內容:
| ID | 標題 | 全文 | 標簽 1 | 標簽 2 | 搜索條件 |
|---|---|---|---|---|---|
| 0 | 第1條 | 廢話 | 1 | 0 | 與標簽 1 相關聯的搜索詞 |
| 1 | 第二條 | 廢話 | 1 | 0 | 與標簽 1 相關聯的搜索詞 |
| 2 | 第二條 | 廢話 | 0 | 1 | 與標簽 2 相關聯的搜索詞 |
| 3 | 第四條 | 巴拉拉 | 0 | 1 | 與標簽 2 相關聯的搜索詞 |
| 4 | 第五條 | 咩咩 | 0 | 1 | 與標簽 2 相關聯的搜索詞 |
這樣做將多次回傳具有多個標簽的同一篇文章。這在上面顯示了符合標簽 1 和 2 的搜索條件的第 2 條。我現在需要將這些實體合并為:
| ID | 標題 | 全文 | 標簽 1 | 標簽 2 |
|---|---|---|---|---|
| 1 | 第二條 | 廢話 | 1 | 1 |
取而代之的是:
| ID | 標題 | 全文 | 標簽 1 | 標簽 2 | 搜索條件 |
|---|---|---|---|---|---|
| 1 | 第二條 | 廢話 | 1 | 0 | 標簽 1 |
| 2 | 第二條 | 廢話 | 0 | 1 | 標簽 2 |
我對 Python 資料處理很陌生。我第一次探索 Python 來探索它的 NLP 包。關于如何解決這個問題的任何想法?是否有一些我可以使用的 Pandas 資料框功能?
uj5u.com熱心網友回復:
嘗試這個:
df.groupby('Title').agg('max').reset_index().drop('Search Criteria', axis=1)
前:
ID Title Full Text Label 1 Label 2 Search Criteria
0 0 Article 1 blahblah 1 0 Search terms associated with label 1
1 1 Article 2 blah 1 0 Search terms associated with label 1
2 2 Article 2 blah 0 1 Search terms associated with label 2
3 3 Article 4 balala 0 1 Search terms associated with label 2
4 4 Article 5 baaa 0 1 Search terms associated with label 2
后:
Title ID Full Text Label 1 Label 2
0 Article 1 0 blahblah 1 0
1 Article 2 2 blah 1 1 <----- Notice that there is only one "Article 2" row, and "Label 1" and "Label 2" are both 1
2 Article 4 3 balala 0 1
3 Article 5 4 baaa 0 1
轉載請註明出處,本文鏈接:https://www.uj5u.com/net/360960.html
上一篇:R:使用條件和行、列索引對列求和
