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”).


目录
相关文章
|
5月前
|
机器学习/深度学习 数据采集 数据处理
掌握时间序列特征工程:常用特征总结与 Feature-engine 的应用
本文介绍了时间序列特征工程,包括滚动统计量、滞后特征、差分和变换等技术,用于提升机器学习模型性能。文章还推荐了Python库`feature-engine`,用于简化特征提取,如处理缺失值、编码分类变量和进行时间序列转换。示例代码展示了如何使用`feature-engine`提取时间戳信息、创建滞后特征和窗口特征。通过创建管道,可以高效地完成整个特征工程流程,优化数据预处理并提高模型效果。
396 15
|
缓存 PyTorch 数据处理
基于Pytorch的PyTorch Geometric(PYG)库构造个人数据集
基于Pytorch的PyTorch Geometric(PYG)库构造个人数据集
902 0
基于Pytorch的PyTorch Geometric(PYG)库构造个人数据集
|
机器学习/深度学习 算法 物联网
时间序列的重采样和pandas的resample方法介绍
重采样是时间序列分析中处理时序数据的一项基本技术。它是关于将时间序列数据从一个频率转换到另一个频率,它可以更改数据的时间间隔,通过上采样增加粒度,或通过下采样减少粒度。在本文中,我们将深入研究Pandas中重新采样的关键问题。
125 1
|
5月前
|
机器学习/深度学习 算法 Python
【Python机器学习】Sklearn库中Kmeans类、超参数K值确定、特征归一化的讲解(图文解释)
【Python机器学习】Sklearn库中Kmeans类、超参数K值确定、特征归一化的讲解(图文解释)
271 0
|
机器学习/深度学习 人工智能 计算机视觉
随机抽样方法——DataFrame.sample()
随机抽样方法——DataFrame.sample()
|
机器学习/深度学习 数据采集 Python
独热编码(One-Hot Encoding)和 LabelEncoder标签编码 区别 数据预处理:(机器学习) sklearn
独热编码(One-Hot Encoding)和 LabelEncoder标签编码 区别 数据预处理:(机器学习) sklearn
675 0
独热编码(One-Hot Encoding)和 LabelEncoder标签编码 区别 数据预处理:(机器学习) sklearn
|
机器学习/深度学习 数据可视化
【解决方案】成功解决将XGBoost中plot_importance绘图时出现的f0、f1、f2、f3、f4、f5等改为对应特征的字段名
成功解决将XGBoost中plot_importance绘图时出现的f0、f1、f2、f3、f4、f5等改为对应特征的字段名。
【解决方案】成功解决将XGBoost中plot_importance绘图时出现的f0、f1、f2、f3、f4、f5等改为对应特征的字段名
|
机器学习/深度学习 Python
【机器学习技巧】之特征工程:数字编码以及One-hot独热编码的几种方式(sklearn与pandas处理方式)
【机器学习技巧】之特征工程:数字编码以及One-hot独热编码的几种方式(sklearn与pandas处理方式)
【机器学习技巧】之特征工程:数字编码以及One-hot独热编码的几种方式(sklearn与pandas处理方式)
|
数据格式
将icdar2015数据集转换成paddleOCR标注数据格式
将icdar2015数据集转换成paddleOCR标注数据格式
将icdar2015数据集转换成paddleOCR标注数据格式