1. 程式人生 > >機器學習-特徵值的抽取

機器學習-特徵值的抽取

特徵值化為了計算機更好的理解資料

# 匯入包
from sklearn.feature_extraction.text import CountVectorizer

# 例項化CountVectorizer

vector = CountVectorizer()

# 呼叫fit_transform輸入並轉換資料
res = vector.fit_transform(["life is short like python","life is tolang,i dislike python"])

# 列印結果
print(vector.get_feature_names())
print(res.toarray())

結果:

['dislike', 'is', 'life', 'like', 'python', 'short', 'tolang']
[[0 1 1 1 1 1 0]
 [1 1 1 0 1 0 1]]