特征工程-特征抽取

概述

将原始数据的 文本特征 转换为 数字特征,转化为数字后,便于计算,让计算机更好的理解数据。

One-Hot Encoding 独热编码

One-Hot Encoding 独热编码

感性认识

# coding=utf-8
from sklearn.feature_extraction.text import CountVectorizer

# 实例化
vector=CountVectorizer()

# 调用fit_transform输入并转换数据
res=vector.fit_transform(['Well I wonder could it be','When I was dreaming about you baby'])
# 打印结果
print(vector.get_feature_names())
print(res.toarray())

结果:

['about', 'baby', 'be', 'could', 'dreaming', 'it', 'was', 'well', 'when', 'wonder', 'you']
[[0 0 1 1 0 1 0 1 0 1 0]
 [1 1 0 0 1 0 1 0 1 0 1]]

原文出处:/show_1EF3Q0uF0nfi.html