http://scikit-learn.org/stable/modules/feature_extraction.html

带病在网吧里。

。。。。。

写。求支持。

。。

1、首先澄清两个概念:特征提取和特征选择(

Feature extraction is very different from Feature
selection

)。

the former consists in transforming arbitrary data, such as text or images, into numerical
features usable for machine learning. The latter is a machine learning technique applied on these features(从已经提取的特征中选择更好的特征).

以下分为四大部分来讲。主要还是4、text feature extraction

2、loading features form dicts

class DictVectorizer。举个样例就好:

>>> measurements = [
... {'city': 'Dubai', 'temperature': 33.},
... {'city': 'London', 'temperature': 12.},
... {'city': 'San Fransisco', 'temperature': 18.},
... ]
>>> from sklearn.feature_extraction import DictVectorizer
>>> vec = DictVectorizer()
>>> vec.fit_transform(measurements).toarray()
array([[ 1., 0., 0., 33.],
[ 0., 1., 0., 12.],
[ 0., 0., 1., 18.]])
>>> vec.get_feature_names()
['city=Dubai', 'city=London', 'city=San Fransisco', 'temperature']



class DictVectorizer对于提取某个特定词汇附近的feature
windows很实用
,比如增加我们通过一个已有的algorithm提取了word ‘sat’ 在句子‘The cat sat on the mat.’中的PoS(Part
of Speech)特征。例如以下:

>>> pos_window = [
... {
... 'word-2': 'the',
... 'pos-2': 'DT',
... 'word-1': 'cat',
... 'pos-1': 'NN',
... 'word+1': 'on',
... 'pos+1': 'PP',
... },
... # in a real application one would extract many such dictionaries
... ]

上面的PoS特征就能够vectorized into a sparse two-dimensional matrix suitable for feeding into a classifier (maybe after being piped into a text.TfidfTransformer for
normalization):

>>>

>>> vec = DictVectorizer()
>>> pos_vectorized = vec.fit_transform(pos_window)
>>> pos_vectorized
<1x6 sparse matrix of type '<... 'numpy.float64'>'
with 6 stored elements in Compressed Sparse ... format>
>>> pos_vectorized.toarray()
array([[ 1., 1., 1., 1., 1., 1.]])
>>> vec.get_feature_names()
['pos+1=PP', 'pos-1=NN', 'pos-2=DT', 'word+1=on', 'word-1=cat', 'word-2=the']

3、feature hashing

The class FeatureHasher is
a high-speed, low-memory vectorizer that uses a technique known as feature
hashing
, or the “hashing trick”.

因为hash。所以仅仅保存feature的interger index。而不保存原来feature的string名字。所以没有inverse_transform方法。

FeatureHasher 接收dict对,即 (feature, value) 对,或者strings,由构造函数的參数input_type决定.结果是scipy.sparse matrix。假设是strings,则value默认取1,比如 ['feat1', 'feat2', 'feat2'] 被解释为[('feat1', 1), ('feat2', 2)].

4、text feature extraction

由于内容太多,分开写了。參考着篇博客:http://blog.csdn.net/mmc2015/article/details/46997379

5、image feature extraction

提取部分图片(Patch extraction):

The extract_patches_2d function从图片中提取小块,存储成two-dimensional
array, or three-dimensional with color information along the third axis. 使用reconstruct_from_patches_2d.
可以将全部的小块重构成原图:

>>> import numpy as np
>>> from sklearn.feature_extraction import image >>> one_image = np.arange(4 * 4 * 3).reshape((4, 4, 3))
>>> one_image[:, :, 0] # R channel of a fake RGB picture
array([[ 0, 3, 6, 9],
[12, 15, 18, 21],
[24, 27, 30, 33],
[36, 39, 42, 45]]) >>> patches = image.extract_patches_2d(one_image, (2, 2), max_patches=2,
... random_state=0)
>>> patches.shape
(2, 2, 2, 3)
>>> patches[:, :, :, 0]
array([[[ 0, 3],
[12, 15]], [[15, 18],
[27, 30]]])
>>> patches = image.extract_patches_2d(one_image, (2, 2))
>>> patches.shape
(9, 2, 2, 3)
>>> patches[4, :, :, 0]
array([[15, 18],
[27, 30]])

重构方式例如以下:

>>> reconstructed = image.reconstruct_from_patches_2d(patches, (4, 4, 3))
>>> np.testing.assert_array_equal(one_image, reconstructed)

The PatchExtractor class和 extract_patches_2d,一样,仅仅只是能够同一时候接受多个图片作为输入:

>>> five_images = np.arange(5 * 4 * 4 * 3).reshape(5, 4, 4, 3)
>>> patches = image.PatchExtractor((2, 2)).transform(five_images)
>>> patches.shape
(45, 2, 2, 3)

图片像素的连接(Connectivity graph of an image):

主要是依据像素的区别来推断图片的每两个像素点是否连接。

。。

The function img_to_graph returns
such a matrix from a 2D or 3D image. Similarly, grid_to_graph build
a connectivity matrix for images given the shape of these image.

这有个直观的样例:http://scikit-learn.org/stable/auto_examples/cluster/plot_lena_ward_segmentation.html#example-cluster-plot-lena-ward-segmentation-py

头疼。。。。

碎觉。

。。

scikit-learn:4.2. Feature extraction(特征提取,不是特征选择)的更多相关文章

  1. Feature extraction - sklearn文本特征提取

    http://blog.csdn.net/pipisorry/article/details/41957763 文本特征提取 词袋(Bag of Words)表征 文本分析是机器学习算法的主要应用领域 ...

  2. ufldl学习笔记和编程作业:Feature Extraction Using Convolution,Pooling(卷积和汇集特征提取)

    ufldl学习笔记与编程作业:Feature Extraction Using Convolution,Pooling(卷积和池化抽取特征) ufldl出了新教程,感觉比之前的好,从基础讲起.系统清晰 ...

  3. (原创)(三)机器学习笔记之Scikit Learn的线性回归模型初探

    一.Scikit Learn中使用estimator三部曲 1. 构造estimator 2. 训练模型:fit 3. 利用模型进行预测:predict 二.模型评价 模型训练好后,度量模型拟合效果的 ...

  4. (原创)(四)机器学习笔记之Scikit Learn的Logistic回归初探

    目录 5.3 使用LogisticRegressionCV进行正则化的 Logistic Regression 参数调优 一.Scikit Learn中有关logistics回归函数的介绍 1. 交叉 ...

  5. Scikit Learn: 在python中机器学习

    转自:http://my.oschina.net/u/175377/blog/84420#OSC_h2_23 Scikit Learn: 在python中机器学习 Warning 警告:有些没能理解的 ...

  6. A Survey of Shape Feature Extraction Techniques中文翻译

    Yang, Mingqiang, Kidiyo Kpalma, and Joseph Ronsin. "A survey of shape feature extraction techni ...

  7. 《Deep Feature Extraction and Classification of Hyperspectral Images Based on Convolutional Neural Networks》论文笔记

    论文题目<Deep Feature Extraction and Classification of Hyperspectral Images Based on Convolutional Ne ...

  8. Software: MPEG-7 Feature Extraction Library

    Software MPEG-7 Feature Extraction Library : This library is adapted from MPEG-7 XM Reference Softwa ...

  9. Feature Engineering versus Feature Extraction: Game On!

    Feature Engineering versus Feature Extraction: Game On! "Feature engineering" is a fancy t ...

随机推荐

  1. jenkins配置发送邮件

    1.打开系统管理->系统设置,找到邮件设置,如下: 2.SMTP或者其他方式的发送邮件,可自行配置,一下列出了qq邮箱和163邮箱设置的地方,如下图: qq邮箱: 往下拉,找到如下图: 163邮 ...

  2. 最新版浏览器报错net::ERR_INSECURE_RESPONSE原因

    访问的网址与接口请求的域名不一致,新版的chrome浏览器出于安全的考虑会将请求进行拦截,并报错net::ERR_INSECURE_RESPONSE

  3. Promise简单实现--摘抄

    Promise 看了些promise的介绍,还是感觉不够深入,这个在解决异步问题上是一个很好的解决方案,所以详细看一下,顺便按照自己的思路实现一个简单的Promise. Promise/A+规范: 首 ...

  4. x86 下的 struct 變數 member 擺放位置

    2 int main() 3 { 4 struct _test { 5 int a; 6 int b; 7 int c; 8 }; 9 10 struct _test test; 11 test.a ...

  5. url相关

    #测试网址: http://localhost/blog/testurl.php?id=5 //获取域名或主机地址 echo$_SERVER['HTTP_HOST']."<br> ...

  6. Oracle For 循环添加数据

    自己亲自使用的,绝对OK --添加数据declare i number; --用for实现 begin for i in 0 .. 500 loop insert into cust(custsn,t ...

  7. XSY1659 [HNOI2012]永无乡

    题面 Description 永无乡包含 n 座岛,编号从 1 到 n. 每座岛都有自己的独一无二的重要度,按照重要度可以将这n座岛排名,名次用 1到n来表示.某些岛之间由巨大的桥连接,通过桥可以从一 ...

  8. mc

    Description 小C在MC里有n个牧场,自西向东呈一字形排列(自西向东用1-n编号),于是他就烦恼了:为了控制这n个牧场,他需要在某些牧场上面建立控制站, 每个牧场上只能建立一个控制站,每个控 ...

  9. eclipse中通过search打开第二个文件时 第一个文件就自己关闭了

    原文:http://blog.csdn.net/u014079773/article/details/66971053 问题:eclipse中通过search打开第二个文件时第一个文件就自己关闭了 问 ...

  10. MongoDb 出现配置服务不同步的处理

    主要片方法就是用正常的配置文件的数据覆盖有问题的就行. 引用: http://dba.stackexchange.com/questions/48232/mongodb-config-servers- ...