pipeline(管道的连续应用)
# -*- 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(管道的连续应用)的更多相关文章
- Java Redis的Pipeline管道,批量操作,节省大量网络往返时间 & Redis批量读写(hmset&hgetall) 使用Pipeline
一般情况下,大家使用redis去put/get都是先拿到一个jedis实例,然后操作,然后释放连接:这种模式是 请求-响应,请求-响应 这种模式,下一次请求必须得等第一次请求响应回来之后才可以,因为r ...
- laravel5.5源码笔记(五、Pipeline管道模式)
Pipeline管道模式,也有人叫它装饰模式.应该说管道是装饰模式的一个变种,虽然思想都是一样的,但这个是闭包的版本,实现方式与传统装饰模式也不太一样.在laravel的源码中算是一个比较核心的设计模 ...
- Python高级编程之生成器(Generator)与coroutine(三):coroutine与pipeline(管道)和Dataflow(数据流_
原创作品,转载请注明出处:点我 在前两篇文章中,我们介绍了什么是Generator和coroutine,在这一篇文章中,我们会介绍coroutine在模拟pipeline(管道 )和控制Dataflo ...
- 使用pipeline管道执行redis命令
pipeline管道可以减少后端与redis的连接次数,从而实现了优化. 原理如下: 使用方法: 未使用pipeline前: strict_redis = get_redis_connection(' ...
- 【spring boot】spring boot 基于redis pipeline 管道,批量操作redis命令
spring boot 2.x 使用RedisTemplate 操作 =================================== 1.pom.xml <!--spring2.0集成r ...
- GPU上创建目标检测Pipeline管道
GPU上创建目标检测Pipeline管道 Creating an Object Detection Pipeline for GPUs 今年3月早些时候,展示了retinanet示例,这是一个开源示例 ...
- Redis批量执行(如list批量添加)命令工具 —— pipeline管道应用
前言 Redis使用的是客户端-服务器(CS)模型和请求/响应协议的TCP服务器.这意味着通常情况下一个请求会遵循以下步骤: 使用Redis管道提升性能 (1)客户端向服务端发送一个查询请求,并监听S ...
- scrapy框架之Pipeline管道类
Item Pipeline简介 Item管道的主要责任是负责处理有蜘蛛从网页中抽取的Item,他的主要任务是清洗.验证和存储数据.当页面被蜘蛛解析后,将被发送到Item管道,并经过几个特定的次序处理数 ...
- 【redis】pipeline - 管道模型
redis-pipeline 2020-02-10: 因为我把github相关的wiki删了,所以导致破图...待解决.(讲真github-wiki跟project是2个url,真的不好用) 因为用的 ...
随机推荐
- elasticsearch中如何手动控制全文检索结果的精准度
1.为帖子数据增加标题字段 POST /forum/article/_bulk{ "update": { "_id": "1"} }{ &q ...
- 并发Socket程序设计
1. 非阻塞并发模型 直接将socket设置为非阻塞, 轮询处理连接和接收. 缺点: 极大消耗CPU资源,不适合实际应用. 2. 信号驱动模型 当Socket文件描述符准备就绪后 内核会给进程发送一个 ...
- QT 中文乱码问题
1. 在main函数中创建完 QApplication对象后马上添加 QTextCodec::setCodecForTr(QTextCodec::codecForName("UTF-8&qu ...
- SPFA算法O(kE)
SPFA算法O(kE) Dijkstra和Floyed是不断的试点.Dijkstra试最优点,Floyed试所有点. Bellman-Ford和SPFA是不断的试边.Bellman-Ford是盲目的试 ...
- 20个面试题让你真正了解jQuery
1. jQuery 库中的 $() 是什么?(答案如下) $() 函数是 jQuery() 函数的别称, $() 函数用于将任何对象包裹成 jQuery 对象,接着你就被允许调用定义在 jQuery ...
- 从virustotal上下载病毒样本
#!/usr/bin/env python import os import csv #import Queue import zipfile import requests import argpa ...
- skynet源码阅读<5>--协程调度模型
注:为方便理解,本文贴出的代码部分经过了缩减或展开,与实际skynet代码可能会有所出入. 作为一个skynet actor,在启动脚本被加载的过程中,总是要调用skynet.start和sky ...
- OpenCV教程【001 Mat显示图片】
#include <opencv2\opencv.hpp> #include <iostream> #include <string> using namespac ...
- 做什么职业,也别做程序员,尤其是Java程序员
千万别做程序员,尤其别做Java这种门槛低,入门快的程序员(别跟我说Java搞精通了也很牛之类的,原因不解释,做5年以上就知道了),程序员本来就是我见过最坑爹的职业了...Java程序员更是,现在满地 ...
- windows下matplotlib的安装
在上一篇中我想用matplotlib,无奈一直装不上,就在卸了又装装了又卸,反反复复之后,终于装好了. 初学python,首先就装了numpy,倒也没有多复杂,有需要的朋友可以直接http://sou ...