현재 Naive Bayes를 사용하여 많은 텍스트를 분류하고 있습니다. 여러 카테고리가 있습니다. 지금 방금 후 확률과 범주를 출력하지만, 내가하고자하는 것은 사후 확률에 따라 범주의 순위를 매기고 두 번째, 세 번째 범주를 "백업"범주로 사용하는 것입니다.NLTK를 사용하여 Naive Bayes를 사용하여 텍스트 문자열을 여러 클래스로 분류
df = pandas.DataFrame({ 'text' : pandas.Categorical(["I have wings","Metal wings","Feathers","Airport"]), 'true_cat' : pandas.Categorical(["bird","plane","bird","plane"])})
text true_cat
-----------------------
I have wings bird
Metal wings plane
Feathers bird
Airport plane
내가 뭘하는지 : 여기
은 예입니다new_cat = classifier.classify(features(text))
prob_cat = classifier.prob_classify(features(text))
에 생길 출력 : 내가 classify_many 및 를 사용하여 몇 가지 예제를 발견
new_cat prob_cat text true_cat
bird 0.67 I have wings bird
bird 0.6 Feathers bird
bird 0.51 Metal wings plane
plane 0.8 Airport plane
prob_classify_many하지만 파이썬에 익숙하지 않아 문제를 해결하는 데 어려움이 있습니다. 팬더와 함께 사용되는 것을 보지 못했습니다.
df_new = pandas.DataFrame({'text': pandas.Categorical(["I have wings","Metal wings","Feathers","Airport"]),'true_cat': pandas.Categorical(["bird","plane","bird","plane"]), 'new_cat1': pandas.Categorical(["bird","bird","bird","plane"]), 'new_cat2': pandas.Categorical(["plane","plane","plane","bird"]), 'prob_cat1': pandas.Categorical(["0.67","0.51","0.6","0.8"]), 'prob_cat2': pandas.Categorical(["0.33","0.49","0.4","0.2"])})
new_cat1 new_cat2 prob_cat1 prob_cat2 text true_cat
-----------------------------------------------------------------------
bird plane 0.67 0.33 I have wings bird
bird plane 0.51 0.49 Metal wings plane
bird plane 0.6 0.4 Feathers bird
plane bird 0.8 0.2 Airport plane
어떤 도움을 주시면 감사하겠습니다 :
나는 그것을 같이하고 싶다.
완벽한, 감사합니다! –