이 번역 페이지는 최신 내용을 담고 있지 않습니다. 최신 내용을 영문으로 보려면 여기를 클릭하십시오.
단순 전처리 함수 만들기
이 예제에서는 분석할 텍스트 데이터를 정리하고 전처리하는 함수를 만드는 방법을 보여줍니다.
텍스트 데이터가 클수록 통계 분석에 부정적 영향을 주는 잡음 데이터가 많이 들어 있을 수 있습니다. 예를 들어 텍스트 데이터에 다음이 포함되어 있을 수 있습니다.
대/소문자가 변형된 단어. 예를 들면 "new"와 "New"
어형이 변형된 단어. 예를 들면 "walk"와 "walking"
잡음을 추가하는 단어. 예를 들면 "the"와 "of" 같은 불용어(stop word)
문장 부호 및 특수 문자
HTML 및 XML 태그
다음 워드 클라우드는 날씨 보고서의 원시 텍스트 데이터에 단어 빈도 분석을 적용한 버전과 동일한 텍스트 데이터를 전처리한 버전을 나타낸 것입니다.
서로 다른 텍스트 데이터 모음을 동일한 방식으로 준비할 수 있기 때문에, 전처리 함수를 만드는 편이 유용할 수 있습니다. 예를 들어 모델을 훈련시킬 때 함수를 사용하여 훈련 데이터와 동일한 단계로 새 데이터를 전처리할 수 있습니다.
이 예제의 마지막에 나오는 함수 preprocessTextData
는 다음 단계를 수행합니다.
tokenizedDocument
를 사용하여 텍스트를 토큰화합니다.normalizeWords
를 사용하여 단어의 표제어를 추출합니다.erasePunctuation
을 사용하여 문장 부호를 지웁니다.removeStopWords
를 사용하여 불용어 목록(예: "and", "of", "the")을 제거합니다.removeShortWords
를 사용하여 2자 이하로 이루어진 단어를 제거합니다.removeLongWords
를 사용하여 15자 이상으로 이루어진 단어를 제거합니다.
이 함수를 사용하려면 텍스트 데이터를 preprocessTextData
에 입력값으로 지정하기만 하면 됩니다.
textData = [ "A large tree is downed and blocking traffic outside Apple Hill." "There is lots of damage to many car windshields in the parking lot."]; documents = preprocessTextData(textData)
documents = 2x1 tokenizedDocument: 8 tokens: large tree down block traffic outside apple hill 7 tokens: lot damage many car windshield parking lot
전처리 함수
function documents = preprocessTextData(textData) % Tokenize the text. documents = tokenizedDocument(textData); % Lemmatize the words. To improve lemmatization, first use % addPartOfSpeechDetails. documents = addPartOfSpeechDetails(documents); documents = normalizeWords(documents,'Style','lemma'); % Erase punctuation. documents = erasePunctuation(documents); % Remove a list of stop words. documents = removeStopWords(documents); % Remove words with 2 or fewer characters, and words with 15 or more % characters. documents = removeShortWords(documents,2); documents = removeLongWords(documents,15); end
자세한 워크플로를 보여주는 예제는 분석할 텍스트 데이터 준비하기 항목을 참조하십시오.
텍스트 분석의 다음 단계로, 분류 모델을 만들어 보거나 토픽 모델을 사용하여 데이터를 분석할 수 있습니다. 예제는 분류를 위한 간단한 텍스트 모델 만들기 및 토픽 모델을 사용하여 텍스트 데이터 분석하기 항목을 참조하십시오.
참고 항목
tokenizedDocument
| erasePunctuation
| removeStopWords
| removeShortWords
| removeLongWords
| normalizeWords
| addPartOfSpeechDetails