텍스트 특성 엔지니어링

Python으로 배우는 Machine Learning 전처리

James Chapman

Curriculum Manager, DataCamp

추출

  • 정규 표현식: 패턴을 식별하는 코드
import re

my_string = "temperature:75.6 F"
temp = re.search("\d+\.\d+", my_string)
print(float(temp.group(0)))
75.6
  • \d+
  • \.
  • \d+
Python으로 배우는 Machine Learning 전처리

텍스트 벡터화

TF/IDF: 중요도 기반으로 단어를 벡터화

  • TF = 단어 빈도
  • IDF = 역문서 빈도
Python으로 배우는 Machine Learning 전처리

텍스트 벡터화

from sklearn.feature_extraction.text import TfidfVectorizer
print(documents.head())
0    Building on successful events last summer and ...
1               Build a website for an Afghan business
2    Please join us and the students from Mott Hall...
3    The Oxfam Action Corps is a group of dedicated...
4    Stop 'N' Swap reduces NYC's waste by finding n...
tfidf_vec = TfidfVectorizer()
text_tfidf = tfidf_vec.fit_transform(documents)
Python으로 배우는 Machine Learning 전처리

텍스트 분류

 

$$P(A|B) = \frac{P(B|A)P(A)}{P(B)}$$

Python으로 배우는 Machine Learning 전처리

연습해 봅시다!

Python으로 배우는 Machine Learning 전처리

Preparing Video For Download...