机器学习算法的特征用法

时间:2017-01-19 02:40:23

标签: python machine-learning scikit-learn feature-extraction

给出用户作为功能安装的软件列表,例如

  

Microsoft_VC80_DebugCRT_x86_x64 1.0.0
  Microsoft_VC80_DebugCRT_x86 1.0.0
  Windows UPnP浏览器0.1.01
  Adobe Acrobat Professional 10

我想预测学生是否会购买某种产品。

现在的问题是:通过机器学习算法将软件列表转化为可学习的方法有哪些?

1 个答案:

答案 0 :(得分:1)

最简单的方法是使用来自scikit learn的vectorizer

from sklearn.feature_extraction.text import CountVectorizer

#min_df is the minimum number of students 
#that have to have a piece of software installed to be included in 
#the feature set

vectorizer = CountVectorizer(min_df=1)
X = vectorizer.fit_transform(data)

矢量化器将构建一个向量,其中每列映射到一个'术语'在您的数据集(这里是一个软件)中,该值将是该术语对特定学生显示的次数。每个学生现在将由一个向量代表。这些向量可以作为scikit-learn支持的大多数算法的特征输入。