问题 - 通用描述
在about_pipelines(help pipeline)的帮助中可以看到,powershell在管道¹下发送一个对象.因此Get-Process -Name notepad | Stop-Process,在管道下方发送一个进程.
假设我们有第三方CmdLet(Do-SomeStuff)无法以任何方式修改或更改.如果传递一个字符串数组或传递一个字符串对象,则Do-SomeStuff执行不同的操作.
DO-SomeStuff仅仅是一个例子,它可以被取代ForEach-Object,Select-Object,Write-Host(或任何其它小命令接受管道输入)
Do-SomeStuff将在此示例中一次处理数组中的各个项目.
$theArray = @("A", "B", "C")
$theArray | Do-SomeStuff
Run Code Online (Sandbox Code Playgroud)
如果我们想将完整数组作为一个对象发送到Do-SomeStuff,可能会尝试这样的事情
@($theArray) | Do-SomeStuff
Run Code Online (Sandbox Code Playgroud)
但由于PowerShell"忽略"了新的单项数组,因此它不会产生预期的结果.
那么,你如何"强制" $theArray作为单个数组对象传递给管道而不是当时的内容项?
问题 - 实际示例
如下所示,Write-Host如果传递一个数组或者它一次传递一个数组中的单个项,则输出是不同的.
PS C:\> $theArray = @("A", "B", "C")
PS C:\> Write-Host $theArray
A B C
PS C:\> $theArray | foreach{Write-Host $_}
A
B
C
PS C:\> @($theArray) | foreach{Write-Host $_}
A
B …Run Code Online (Sandbox Code Playgroud) 使用确定最佳参数后pipeline和GridSearchCV,我怎么pickle/ joblib后来这个过程中重新使用?当它是单个分类器时,我看到如何做到这一点......
from sklearn.externals import joblib
joblib.dump(clf, 'filename.pkl')
Run Code Online (Sandbox Code Playgroud)
但是,如何pipeline在执行和完成后用最佳参数保存整体gridsearch?
我试过了:
joblib.dump(grid, 'output.pkl') - 但是转储了每次网格搜索尝试(许多文件)joblib.dump(pipeline, 'output.pkl') - 但我不认为它包含最好的参数X_train = df['Keyword']
y_train = df['Ad Group']
pipeline = Pipeline([
('tfidf', TfidfVectorizer()),
('sgd', SGDClassifier())
])
parameters = {'tfidf__ngram_range': [(1, 1), (1, 2)],
'tfidf__use_idf': (True, False),
'tfidf__max_df': [0.25, 0.5, 0.75, 1.0],
'tfidf__max_features': [10, 50, 100, 250, 500, 1000, None],
'tfidf__stop_words': ('english', None),
'tfidf__smooth_idf': (True, False),
'tfidf__norm': ('l1', 'l2', None),
}
grid = …Run Code Online (Sandbox Code Playgroud) 我正在尝试使用Python/Pandas(作为学习练习)粗略地复制R中的dplyr包.我坚持的是"管道"功能.
在R/dplyr中,这是使用管道运算符完成的%>%,其中x %>% f(y)相当于f(x, y).如果可能,我想使用中缀语法复制它(参见此处).
为了说明,请考虑以下两个功能.
import pandas as pd
def select(df, *args):
cols = [x for x in args]
df = df[cols]
return df
def rename(df, **kwargs):
for name, value in kwargs.items():
df = df.rename(columns={'%s' % name: '%s' % value})
return df
Run Code Online (Sandbox Code Playgroud)
第一个函数采用数据帧并仅返回给定的列.第二个采用数据帧,并重命名给定的列.例如:
d = {'one' : [1., 2., 3., 4., 4.],
'two' : [4., 3., 2., 1., 3.]}
df = pd.DataFrame(d)
# Keep only the 'one' column.
df …Run Code Online (Sandbox Code Playgroud) 如何从项目管道访问settings.py中的scrapy设置.文档提到可以通过扩展中的爬虫访问它,但我没有看到如何访问管道中的爬虫.
我正在使用Python 2.7和sklearn 0.16 从O'Reilly的书" 使用Python 进行机器学习简介 "中实现一个示例.
我正在使用的代码:
pipe = make_pipeline(TfidfVectorizer(), LogisticRegression())
param_grid = {"logisticregression_C": [0.001, 0.01, 0.1, 1, 10, 100], "tfidfvectorizer_ngram_range": [(1,1), (1,2), (1,3)]}
grid = GridSearchCV(pipe, param_grid, cv=5)
grid.fit(X_train, y_train)
print("Best cross-validation score: {:.2f}".format(grid.best_score_))
Run Code Online (Sandbox Code Playgroud)
返回的错误归结为:
ValueError: Invalid parameter logisticregression_C for estimator Pipeline
Run Code Online (Sandbox Code Playgroud)
这是与从v.0.16使用Make_pipeline相关的错误吗?导致此错误的原因是什么?
Clojure中的 - >运算符(以及在Clojure中调用的运算符是什么?)相当于F#中的管道运算符|>?如果是这样,当(|>)被定义为时,为什么它需要这样一个复杂的宏定义
let inline (|>) x f = f x
Run Code Online (Sandbox Code Playgroud)
或者如果没有,F#的管道运算符是否存在于Clojure中,或者您将如何在Clojure中定义这样的运算符?
我喜欢在shell脚本中的函数之间使用类似生成器的模式.像这样的东西:
parse_commands /da/cmd/file | process_commands
Run Code Online (Sandbox Code Playgroud)
但是,这种模式的基本问题是,如果parse_command遇到错误,我发现通知process_command失败的唯一方法是通过显式告知它(例如echo"FILE_NOT_FOUND").这意味着必须对parse_command中的每个可能的错误操作进行隔离.
难道没有办法使用非零退出代码检测左侧是否退出?
现代CPU具有广泛的流水线操作,也就是说,它们在实际执行指令之前很久就会加载必要的指令和数据.
有时,加载到管道中的数据会失效,必须清除管道并重新加载新数据.重新填充管道所需的时间可能相当长,并导致性能下降.
如果我在C中调用一个函数指针,那么管道是否足够智能以实现管道中的指针是一个函数指针,并且它应该跟随该指针用于下一个指令?或者是否有一个函数指针导致管道清除并降低性能?
我在C中工作,但我想这在C++中更为重要,因为许多函数调用都是通过v-tables进行的.
要成为函数调用的真正性能,您调用的函数必须非常简短.如果您通过测量代码来观察这一点,那么您最终应该重新审视您的设计以允许内联调用
不幸的是,这可能是我陷入的陷阱.
出于性能原因,我编写了小而快的目标函数.
但是它被函数指针引用,因此它可以很容易地被其他函数替换(只需使指针引用一个不同的函数!).因为我通过函数指针引用它,所以我认为它不能内联.
所以,我有一个非常简短,没有内联的功能.
我有以下Haskell代码,实现了"cat"unix命令行实用程序的简单版本.在400MB文件上以"时间"测试性能,速度大约慢3倍.(我用来测试它的确切脚本在代码下面).
我的问题是:
关于问题2和3:我使用了GHC -prof,然后使用+ RTS -p运行,但我发现这里的输出有点无法提供信息.
来源(Main.hs)
module Main where
import System.IO
import System.Environment
import Data.ByteString as BS
import Control.Monad
-- Copied from cat source code
bufsize = 1024*128
go handle buf = do
hPut stdout buf
eof <- hIsEOF handle
unless eof $ do
buf <- hGetSome handle bufsize
go handle buf
main = do
file <- fmap Prelude.head getArgs
handle <- openFile file ReadMode
buf <- hGetSome handle bufsize
hSetBuffering stdin $ BlockBuffering (Just bufsize) …Run Code Online (Sandbox Code Playgroud) 我正在使用Scikit-Learn自定义管道(sklearn.pipeline.Pipeline)和RandomizedSearchCV超参数优化.这非常有效.
现在我想插入一个Keras模型作为管道的第一步.应优化模型的参数.然后,计算(拟合)的Keras模型应该在管道中通过其他步骤使用,因此我认为我必须将模型存储为全局变量,以便其他管道步骤可以使用它.这是正确的吗?
我知道Keras为Scikit-Learn API提供了一些包装器,但问题是这些包装器已经进行了分类/回归,但我只想计算Keras模型而没有别的.
如何才能做到这一点?
例如,我有一个返回模型的方法:
def create_model(file_path, argument2,...):
...
return model
Run Code Online (Sandbox Code Playgroud)
该方法需要一些固定的参数,如文件路径等,但不需要(或可以忽略)X和y.应优化模型的参数(层数等).
pipeline machine-learning scikit-learn hyperparameters keras