テキスト特徴量のエンジニアリング

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...