로그인 바로가기 하위 메뉴 바로가기 본문 바로가기

데이터 구조 및 분석: Linear Structure and Dynamic Programming

임시 이미지 KAIST 산업및시스템공학과 문일철
http://kooc.kaist.ac.kr/datastructure-2019s/forum/12570
좋아요 1779 수강생 3365

안녕하세요,

runAnalysis() 메서드 안쪽 중간에 probLogPositive와 probLogNegative가 있습니다. 

제 질문은 for loop를 통해 특정 리뷰에 사용되었던 단어들이 나타나는 긍정/부정 확률을 모두 더했음에도 왜 곧바로 다시 probPositiveAndNegative를 통해 긍정/부정 확률을 더하는지 이해가 가지 않습니다. 

runAnalysis()라는 메서드는 특정한 한개의 리뷰에서 사용된 단어들이 부정적인 리뷰일 확률과 긍정적일 리뷰일 확률을 로그 변환해서 리턴하는것(이라고 이해했습니다..ㅎㅎ) 이것에 왜 전체 리뷰의 긍정/부정일 확률을 더하는지 모르겠습니다.

실제로 probPositiveAndNegative로 추출한 확률값을 제외한다해도 전체적인 결과물에 큰 영향이 없는데, 혹시 다른 이유가 있는건가요? 감사합니다.

    def runAnalysis(self, sentidata, word, idxReview):
        probLogPositive = 0
        probLogNegative = 0
        idxUsedWords, usedWords = self.findUsedWords(sentidata, word, idxReview)

        # Make a for-loop to run from the first word to the last word
        for i in range(len(idxUsedWords)):
            # get the first word from the used word set
            idxWord = idxUsedWords[i]
            # calculate the word's probability to be positive or negative
            pointedWord, positive, negative = self.probWordPositiveAndNegative(sentidata, word, idxWord)
            probLogPositive += math.log(positive)
            probLogNegative += math.log(negative)

        positiveProb1, negativeProb1 = self.probPositiveAndNegative(sentidata)
        probLogPositive += math.log(positiveProb1)
        probLogNegative += math.log(negativeProb1)

        if probLogPositive > probLogNegative:
            sentiment = 'Positive'
            print('Positive')
        else:
            sentiment = 'Negative'
            print('Negative')

        return probLogPositive, probLogNegative, sentiment