python中DictVectorizer的使用
2018-02-08 10:08
239 查看
在阅读《机器学习及实践》第三章这本书的时候,看到了DictVectorizer这一用法,后来在网上查询了有关该命令的用法,它是用于对特征进行抽取和向量化,有关代码如下:
转换后形式
from sklearn.feature_extraction import DictVectorizer measurements = [ {'city': 'Dubai', 'temperature': 33.}, {'city': 'London', 'temperature': 12.}, {'city': 'San Fransisco', 'temperature': 18.}, ] vec = DictVectorizer() print(vec.fit_transform(measurements).toarray()) """ 输出: array([[ 1., 0., 0., 33.], [ 0., 1., 0., 12.], [ 0., 0., 1., 18.]]) """ print(vec.get_feature_names()) """ 输出: ['city=Dubai', 'city=London', 'city=San Fransisco', 'temperature'] """原表形式
转换后形式
相关文章推荐
- python中DictVectorizer的使用
- 【python】dict使用方法和快捷查找
- Python中dict使用
- Python 字典dict使用介绍
- python 使用 simplejson 将字符串转换成字典dict
- Python 字典dict使用介绍
- Python 3 collections.defaultdict() 与 dict的使用和区别
- 详解Python中dict与set的使用
- Python 1.6 使用dict和set
- Python下使用help(dict),显示'more'不是内部或外部命令,也不是可运行的程序或批处理文件,该如何处理?
- Python中的dict,List及内建函数的使用
- [Python] 使用dict和set
- Python collections.defaultdict()与dict的使用和区别
- 在Python中使用dict和set方法的教程
- Python中dict字典使用方法
- [Python-tools]defaultdict的使用场景
- Python collections.defaultdict() 与 dict的使用和区别
- 在python2.x中使用dict类型解决没有python3.x中的nonlcoal的问题
- 详解Python中dict与set的使用
- python使用点操作符访问字典(dict)数据