首页 > 其他 > 详细

特征维中词矩阵

时间:2018-04-28 18:49:04      阅读:188      评论:0      收藏:0      [点我收藏+]

在处理数据的时候偶尔会遇到特征维如下情况:

技术分享图片

可以将other维中的以分号分隔的词转化为词向量的形式:

import pandas as pd
from sklearn.feature_extraction.text import CountVectorizer

df = pd.read_csv("data.txt",index_col=0)
df[other] = df[other].apply(lambda x:  .join(x.split(;)))
cv = CountVectorizer()
other_list = cv.fit_transform(df[other])
df1 = pd.DataFrame(other_list.toarray(), columns = cv.get_feature_names())
df = df.reset_index(drop = True)
df_tmp = df.drop(other, axis=1)
df_final = df_tmp.join(df1)

最终得到结果:

技术分享图片

 

特征维中词矩阵

原文:https://www.cnblogs.com/hbwxcw/p/8968881.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!