【发布时间】:2016-09-11 05:53:25
【问题描述】:
假设我有一个字符串数组:
['Laptop Apple Macbook Air A1465, Core i7, 8Gb, 256Gb SSD, 15"Retina, MacOS' ... 'another device description']
我想从这个描述中提取如下特征:
item=Laptop
brand=Apple
model=Macbook Air A1465
cpu=Core i7
...
我应该先准备好预定义的已知特征吗?喜欢
brands = ['apple', 'dell', 'hp', 'asus', 'acer', 'lenovo']
cpu = ['core i3', 'core i5', 'core i7', 'intel pdc', 'core m', 'intel pentium', 'intel core duo']
我不确定我是否需要在这里使用CountVectorizer 和TfidfVectorizer,使用DictVictorizer 更合适,但是如何使用从整个字符串中提取值的键来制作字典?
scikit-learn 的特征提取有可能吗?还是我应该创建自己的 .fit() 和 .transform() 方法?
更新: @sergzach,如果我理解正确,请查看:
data = ['Laptop Apple Macbook..', 'Laptop Dell Latitude...'...]
for d in data:
for brand in brands:
if brand in d:
# ok brand is found
for model in models:
if model in d:
# ok model is found
那么为每个特征创建 N 循环?这可能有效,但不确定它是否正确和灵活。
【问题讨论】:
-
您可以手动列出所有品牌,然后从文本中提取它们(可能使用 str.lower() 并删除不必要的字符),然后检查它们是否大部分被识别。然后查看未被识别的特征并决定如何处理它们。然后使用 DV.fit_transform 将它们转换为数字特征,缩放它们并将它们用作数字。
-
@sergzach 谢谢,我已经更新了我的问题,你能复习一下吗?
-
我认为你可以使用这里提到的 sklearn 的
CountVectorizer():scikit-learn.org/stable/tutorial/text_analytics/…。但无论如何你应该为fit_transform()准备数据。
标签: machine-learning scikit-learn text-classification