# -*- coding: utf-8 -*-
"""
Created on Tue Aug 09 22:55:06 2016 @author: Administrator
"""
#方法1
from sklearn import svm
from sklearn.datasets import samples_generator
from sklearn.feature_selection import SelectKBest
from sklearn.feature_selection import f_regression
from sklearn.pipeline import Pipeline # 生成数据
X, y = samples_generator.make_classification(n_informative=5, n_redundant=0, random_state=42) # 定义Pipeline,先方差分析,再SVM
anova_filter = SelectKBest(f_regression, k=5)
clf = svm.SVC(kernel='linear')
pipe = Pipeline([('anova', anova_filter), ('svc', clf)]) # 设置anova的参数k=10,svc的参数C=0.1(用双下划线"__"连接!)
pipe.set_params(anova__k=10, svc__C=.1)
pipe.fit(X, y) prediction = pipe.predict(X) #管道怎么会预测,见文章末尾 pipe.score(X, y) # 得到 anova_filter 选出来的特征
s = pipe.named_steps['anova'].get_support()
print(s) #方法2
import numpy as np from sklearn import linear_model, decomposition, datasets
from sklearn.pipeline import Pipeline
from sklearn.grid_search import GridSearchCV digits = datasets.load_digits()
X_digits = digits.data
y_digits = digits.target # 定义管道,先降维(pca),再逻辑回归
pca = decomposition.PCA()
logistic = linear_model.LogisticRegression()
pipe = Pipeline(steps=[('pca', pca), ('logistic', logistic)]) # 把管道再作为grid_search的estimator
n_components = [20, 40, 64]
Cs = np.logspace(-4, 4, 3)
estimator = GridSearchCV(pipe, dict(pca__n_components=n_components, logistic__C=Cs)) estimator.fit(X_digits, y_digits)

#Pipeline 无预测函数,他用管道中最后一个预测函数

Applies transforms to the data, and the predict method of the final estimator. Valid only if the final estimator implements predict.

pipeline(管道的连续应用)的更多相关文章

  1. Java Redis的Pipeline管道,批量操作,节省大量网络往返时间 & Redis批量读写(hmset&hgetall) 使用Pipeline

    一般情况下,大家使用redis去put/get都是先拿到一个jedis实例,然后操作,然后释放连接:这种模式是 请求-响应,请求-响应 这种模式,下一次请求必须得等第一次请求响应回来之后才可以,因为r ...

  2. laravel5.5源码笔记(五、Pipeline管道模式)

    Pipeline管道模式,也有人叫它装饰模式.应该说管道是装饰模式的一个变种,虽然思想都是一样的,但这个是闭包的版本,实现方式与传统装饰模式也不太一样.在laravel的源码中算是一个比较核心的设计模 ...

  3. Python高级编程之生成器(Generator)与coroutine(三):coroutine与pipeline(管道)和Dataflow(数据流_

    原创作品,转载请注明出处:点我 在前两篇文章中,我们介绍了什么是Generator和coroutine,在这一篇文章中,我们会介绍coroutine在模拟pipeline(管道 )和控制Dataflo ...

  4. 使用pipeline管道执行redis命令

    pipeline管道可以减少后端与redis的连接次数,从而实现了优化. 原理如下: 使用方法: 未使用pipeline前: strict_redis = get_redis_connection(' ...

  5. 【spring boot】spring boot 基于redis pipeline 管道,批量操作redis命令

    spring boot 2.x 使用RedisTemplate 操作 =================================== 1.pom.xml <!--spring2.0集成r ...

  6. GPU上创建目标检测Pipeline管道

    GPU上创建目标检测Pipeline管道 Creating an Object Detection Pipeline for GPUs 今年3月早些时候,展示了retinanet示例,这是一个开源示例 ...

  7. Redis批量执行(如list批量添加)命令工具 —— pipeline管道应用

    前言 Redis使用的是客户端-服务器(CS)模型和请求/响应协议的TCP服务器.这意味着通常情况下一个请求会遵循以下步骤: 使用Redis管道提升性能 (1)客户端向服务端发送一个查询请求,并监听S ...

  8. scrapy框架之Pipeline管道类

    Item Pipeline简介 Item管道的主要责任是负责处理有蜘蛛从网页中抽取的Item,他的主要任务是清洗.验证和存储数据.当页面被蜘蛛解析后,将被发送到Item管道,并经过几个特定的次序处理数 ...

  9. 【redis】pipeline - 管道模型

    redis-pipeline 2020-02-10: 因为我把github相关的wiki删了,所以导致破图...待解决.(讲真github-wiki跟project是2个url,真的不好用) 因为用的 ...

随机推荐

  1. 碰到错误Could not load the Tomcat server configuration at \Servers\MyEclipse Tomcat v8.5-config. The Servers project is closed.

    本人用的myeclipse是2017版. 可能解决的方法是: 双击MyEclipse Tomcat v8.5,然后就会弹出以下窗口,

  2. review23

    文件的创建与删除 当使用File类创建一个文件对象后,例如 File file = new File("C:\\myletter", "letter.txt") ...

  3. liunx常用命令-----查找命令

    locate 根据文件名查找文件 根据数据库记录搜索,当天创建的搜不到 whereis which  搜索命令的命令   如 whereis ls find   /root   -name       ...

  4. hzau 1202 GCD(矩阵快速幂)

    1202: GCD Time Limit: 1 Sec  Memory Limit: 1280 MBSubmit: 201  Solved: 31[Submit][Status][Web Board] ...

  5. c# 打开第三方软件(如:电脑自带看图软件)

    嘿嘿,直接上示例代码 /// <summary> /// 利用第三方软件浏览加工图纸 /// </summary> /// <param name="fileP ...

  6. PHP用mysql_insert_id()函数获得刚插入数据或当前发布文章的ID

    向mysql 插入数据时,很多时候我们想知道刚刚插入数据的id,这对我们很有用.下面这篇文章就详细给大家介绍了利用mysql_insert_id()函数获得刚插入数据或当前发布文章的ID,有需要的朋友 ...

  7. BEC listen and translation exercise 11

    When you are in any contest you should work as if there were — to the very last minute — a chance to ...

  8. 1.Linux和Unix区别

    整理来源于网络:http://blog.csdn.net/xiaojianpitt/article/details/6377419 有很多初学Linux的人比较关心Linux和windows的区别,这 ...

  9. 解决Opencv高低版本不兼容问题

    目前OpenCV版本已更新到2.4...由此出现了一系列问题,解决如下: 1.cxcore.h等头文件找不到: 法一.将opencv1.0中的各种.h或者.lib文件拷到opencv2.3.1对应in ...

  10. java-05String课堂练习

    1.阅读以下代码查看输出结果 public class StringPool { public static void main(String args[]) { String s0="He ...