import sklearn
from sklearn.feature_extraction import DictVectorizer
def dictvect():
vect = DictVectorizer(sparse=False)
data = vect.fit_transform([{"city":"bj","temperature":20},{"city":"sh","temperature":30},{"city":"sz","temperature":40}])
print(vect.get_feature_names())
print(data)
return None
if __name__ == '__main__':
dictvect()
C:Python38python.exe D:/Project/Study/python/machine/test.py
['city=bj', 'city=sh', 'city=sz', 'temperature']
[[ 1. 0. 0. 20.]
[ 0. 1. 0. 30.]
[ 0. 0. 1. 40.]]
最后
以上就是英勇未来最近收集整理的关于DictVectorizer的全部内容,更多相关DictVectorizer内容请搜索靠谱客的其他文章。
本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
发表评论 取消回复