sklearn.feature_extraction.DictVectorizer将字典格式的数据转换为特征

class  sklearn.feature_extraction. DictVectorizer ( dtype=<class ‘numpy.float64’> separator=’=’ sparse=True , sort=True )
Transforms lists of feature-value mappings to vectors.
This transformer turns lists of mappings (dict-like objects ) of feature names to feature values into Numpy arrays or scipy. sparse matrices(稀疏矩阵) for use with scikit-learn estimators.
When feature values are strings, this transformer will do a binary one-hot (aka one-of-K) coding: one boolean-valued feature is constructed for each of the possible string values that the feature can take on. For instance, a feature “f” that can take on the values “ham” and “spam” will become two features in the output, one signifying “f=ham”, the other “f=spam”.
However, note that this transformer will only do a binary one-hot encoding when feature values are of type string. If categorical features are represented as numeric values such as int, the DictVectorizer can be followed by OneHotEncoder to complete binary one-hot encoding.
Features that do not occur in a sample (mapping) will have a zero value in the resulting array/matrix.
Read more in the  User Guide .
Parameters:
dtype  : callable, optional
The type of feature values. Passed to Numpy array/scipy.sparse matrix constructors as the dtype argument.
separator  : string, optional
Separator string used when constructing new features for one-hot coding.
sparse  : boolean, optional.
Whether transform should produce scipy.sparse matrices. True by default.
sort  : boolean, optional.
Whether  feature_names_  and  vocabulary_  should be sorted when fitting. True by default.


Attributes:
vocabulary_  : dict
A dictionary mapping feature names to feature indices.
feature_names_  : list
A list of length n_features containing the feature names (e.g., “f=ham” and “f=spam”).


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值