码迷,mamicode.com
首页 > 其他好文 > 详细

sklearn数据变化

时间:2017-06-13 12:39:41      阅读:231      评论:0      收藏:0      [点我收藏+]

标签:orm   word   nsis   sso   .text   cti   encoding   sklearn   input   

一.特征抽取

特征抽取sklearn.feature_extraction 模块提供了从原始数据如文本,图像等众抽取能够被机器学习算法直接处理的特征向量。

技术分享

1.特征抽取方法之 Loading Features from Dicts

技术分享

技术分享

measurements=[
    {city:Dubai,temperature:33.},
    {city:London,temperature:12.},
    {city:San Fransisco,temperature:18.},
]

from sklearn.feature_extraction import DictVectorizer
vec=DictVectorizer()
print(vec.fit_transform(measurements).toarray())
print(vec.get_feature_names())

#[[  1.   0.   0.  33.]
 #[  0.   1.   0.  12.]
 #[  0.   0.   1.  18.]]

#[‘city=Dubai‘, ‘city=London‘, ‘city=San Fransisco‘, ‘temperature‘]

2.特征抽取方法之 Features hashing

技术分享

技术分享

技术分享

技术分享

2.特征抽取方法之 Text Feature Extraction

词袋模型 the bag of words represenatation

技术分享

技术分享

技术分享

#词袋模型
from sklearn.feature_extraction.text import CountVectorizer
#查看默认的参数
vectorizer=CountVectorizer(min_df=1)
print(vectorizer)

"""
CountVectorizer(analyzer=‘word‘, binary=False, decode_error=‘strict‘,
        dtype=<class ‘numpy.int64‘>, encoding=‘utf-8‘, input=‘content‘,
        lowercase=True, max_df=1.0, max_features=None, min_df=1,
        ngram_range=(1, 1), preprocessor=None, stop_words=None,
        strip_accents=None, token_pattern=‘(?u)\\b\\w\\w+\\b‘,
        tokenizer=None, vocabulary=None)

"""

corpus=["this is the first document.",
        "this is the second second document.",
        "and the third one.",
        "Is this the first document?"]
x=vectorizer.fit_transform(corpus)
print(x)

"""
(0, 1)    1
  (0, 2)    1
  (0, 6)    1
  (0, 3)    1
  (0, 8)    1
  (1, 5)    2
  (1, 1)    1
  (1, 6)    1
  (1, 3)    1
  (1, 8)    1
  (2, 4)    1
  (2, 7)    1
  (2, 0)    1
  (2, 6)    1
  (3, 1)    1
  (3, 2)    1
  (3, 6)    1
  (3, 3)    1
  (3, 8)    1
"""

 

sklearn数据变化

标签:orm   word   nsis   sso   .text   cti   encoding   sklearn   input   

原文地址:http://www.cnblogs.com/nolonely/p/7000303.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!