我有一个非常简单的代码,如下所示.刮痧是可以的,我可以看到所有print语句生成正确的数据.在Pipeline,初始化工作正常.但是,process_item函数不会被调用,因为print函数开头的语句永远不会被执行.
蜘蛛:comosham.py
import scrapy
from scrapy.spider import Spider
from scrapy.selector import Selector
from scrapy.http import Request
from activityadvisor.items import ComoShamLocation
from activityadvisor.items import ComoShamActivity
from activityadvisor.items import ComoShamRates
import re
class ComoSham(Spider):
name = "comosham"
allowed_domains = ["www.comoshambhala.com"]
start_urls = [
"http://www.comoshambhala.com/singapore/classes/schedules",
"http://www.comoshambhala.com/singapore/about/location-contact",
"http://www.comoshambhala.com/singapore/rates-and-offers/rates-classes",
"http://www.comoshambhala.com/singapore/rates-and-offers/rates-classes/rates-private-classes"
]
def parse(self, response):
category = (response.url)[39:44]
print 'in parse'
if category == 'class':
pass
"""self.gen_req_class(response)"""
elif category == 'about':
print 'about to call parse_location'
self.parse_location(response)
elif …Run Code Online (Sandbox Code Playgroud) 我有以下脚本/tmp无限期地监视目录,如果该目录中有任何文件操作,则文件名由while循环读取,文件名中的第一个a字符替换为b字符,并将此修改后的文件名记录到test.log文件中:
#!/bin/bash
trap ':' HUP
trap 'kill $(jobs -p)' EXIT
/usr/local/bin/inotifywait -q -m /tmp --format %f |
while IFS= read -r filename; do
echo "$filename" | sed 's/a/b/' > test.log
done
Run Code Online (Sandbox Code Playgroud)
这是实际脚本的简化版本.我上面的脚本也有一个Sys-V类型的init脚本,因为我希望保持LSB兼容,我的init脚本有force-reload(如果服务支持,则重新加载配置.否则,重新启动服务.)选项它将HUP信号发送到脚本.现在在执行之前执行force-reload,killproc -HUP test.sh输出pstree如下:
# pstree -Ap 4424
test.sh(4424)-+-inotifywait(4425)
`-test.sh(4426)
#
Run Code Online (Sandbox Code Playgroud)
执行后strace killproc -HUP test.sh,子shell终止:
# pstree -Ap 4424
test.sh(4424)---inotifywait(4425)
#
Run Code Online (Sandbox Code Playgroud)
据strace,killproc发送SIGHUP到过程4424和 …
类似于如何在scikit中仅将参数传递给管道对象的一部分?我想将参数传递给管道的一部分.通常,它应该工作正常,如:
estimator = XGBClassifier()
pipeline = Pipeline([
('clf', estimator)
])
Run Code Online (Sandbox Code Playgroud)
并执行像
pipeline.fit(X_train, y_train, clf__early_stopping_rounds=20)
Run Code Online (Sandbox Code Playgroud)
但它失败了:
/usr/local/lib/python3.5/site-packages/sklearn/pipeline.py in fit(self, X, y, **fit_params)
114 """
115 Xt, yt, fit_params = self._pre_transform(X, y, **fit_params)
--> 116 self.steps[-1][-1].fit(Xt, yt, **fit_params)
117 return self
118
/usr/local/lib/python3.5/site-packages/xgboost-0.6-py3.5.egg/xgboost/sklearn.py in fit(self, X, y, sample_weight, eval_set, eval_metric, early_stopping_rounds, verbose)
443 early_stopping_rounds=early_stopping_rounds,
444 evals_result=evals_result, obj=obj, feval=feval,
--> 445 verbose_eval=verbose)
446
447 self.objective = xgb_options["objective"]
/usr/local/lib/python3.5/site-packages/xgboost-0.6-py3.5.egg/xgboost/training.py in train(params, dtrain, num_boost_round, evals, obj, feval, maximize, early_stopping_rounds, evals_result, verbose_eval, learning_rates, xgb_model, …Run Code Online (Sandbox Code Playgroud) 这是我的代码:
df <- df %>%
filter(conditions x, y, and z) %>%
str_replace_all(string, pattern, replacement)
Run Code Online (Sandbox Code Playgroud)
这样做时,我收到错误:
Error in str_replace_all(., string, pattern, replacement) :
unused argument("")
Run Code Online (Sandbox Code Playgroud)
我知道代码在复制方面一点用处都没有,正如我之前所说,我不能共享数据,但假设输入是正确的(我已经通过改变变量来让它工作)。替换是一个空字符串,但据我所知,这应该无关紧要。
我只是好奇为什么 str_replace_all 在管道中不起作用,有人有任何见解吗?
有没有办法制作一个可以播放任何视频文件的管道(也包含音频)?我试过链接元素,如:
filesrc -> decodebin
Run Code Online (Sandbox Code Playgroud)
随着
queue -> audioconvert -> autoaudiosink
Run Code Online (Sandbox Code Playgroud)
和
queue -> autovideoconvert -> autovideosink
Run Code Online (Sandbox Code Playgroud)
这会导致两个问题:
queue不能链接到autovideoconvert."pad-added"事件实现pad ,特别是当管道同时支持音频和视频时.我想知道如何在不需要的情况下做到这一点gst.parse_launch.另外,我希望pieline能够使用我抛出的任何格式(如playbin),但不能使用playbin,因为我需要链接其他元素(level和volume).
或者,有没有办法将元素(如level)连接到播放箱?
如何通过管道立即捕获ping命令的输出?
这是我的代码:
int main ()
{
FILE *cmd = popen ( "ping -c 3 google.com | grep icmp", "r" );//ping google
char *s = malloc ( sizeof ( char ) * 200 );
while ( 1 )
{
fgets ( s, sizeof ( char )*200, cmd );
printf ( "%s", s);//show outcome
if ( strstr ( s, "icmp_req=3" ) != 0 )
break;
}
pclose ( cmd );
return 0;
}
Run Code Online (Sandbox Code Playgroud)
程序完成后,将同时显示输出.但我想在程序执行时立即读取输出.
我有一个语料库:
X_train = [ ['this is an dummy example']
['in reality this line is very long']
...
['here is a last text in the training set']
]
Run Code Online (Sandbox Code Playgroud)
和一些标签:
y_train = [1, 5, ... , 3]
Run Code Online (Sandbox Code Playgroud)
我想使用Pipeline和GridSearch如下:
pipeline = Pipeline([
('vect', CountVectorizer()),
('tfidf', TfidfTransformer()),
('reg', SGDRegressor())
])
parameters = {
'vect__max_df': (0.5, 0.75, 1.0),
'tfidf__use_idf': (True, False),
'reg__alpha': (0.00001, 0.000001),
}
grid_search = GridSearchCV(pipeline, parameters, n_jobs=1, verbose=1)
grid_search.fit(X_train, y_train)
Run Code Online (Sandbox Code Playgroud)
当我运行这个时,我收到一个错误说AttributeError: lower not found.
我在这里搜索并发现了一个关于这个错误的问题,这让我相信我的文本没有被标记化存在问题(这听起来就像它击中了头部,因为我使用列表列表作为输入数据,其中每个列表包含一个单个不间断的字符串).
我制作了一个快速而肮脏的标记器来测试这个理论:
def my_tokenizer(X): …Run Code Online (Sandbox Code Playgroud) 简介:我想在命令行上编写类似于bash脚本的python脚本,但是我还想在python中轻松地将它们连接在一起.我遇到麻烦的地方是制造后者的胶水.
所以,想象一下我写了两个剧本,script1.py和script2.py我能管他们在一起就像这样:
echo input_string | ./script1.py -a -b | ./script2.py -c -d
Run Code Online (Sandbox Code Playgroud)
如何从另一个python文件中获取此行为? 这是我所知道的方式,但我不喜欢:
arg_string_1 = convert_to_args(param_1, param_2)
arg_string_2 = convert_to_args(param_3, param_4)
output_string = subprocess.check_output("echo " + input_string + " | ./script1.py " + arg_string_1 + " | ./script2.py " + arg_string_2)
Run Code Online (Sandbox Code Playgroud)
如果我不想利用多线程,我可以做这样的事情(?):
input1 = StringIO(input_string)
output1 = StringIO()
script1.main(param_1, param_2, input1, output1)
input2 = StringIO(output1.get_value())
output2 = StringIO()
script2.main(param_3, param_4, input2, output2)
Run Code Online (Sandbox Code Playgroud)
这是我尝试的方法,但我坚持写胶水.我很感激学习如何完成下面的方法,或建议更好的设计/方法!
我的方法:我写了script1.py,script2.py看起来像:
#!/usr/bin/python3
... # import sys and …Run Code Online (Sandbox Code Playgroud) from mlxtend.regressor import StackingRegressor
from sklearn.ensemble.forest import RandomForestRegressor as RFR
from sklearn.ensemble import GradientBoostingRegressor as GBR
import xgboost as xgb
rfr = RFR(n_estimators=500, n_jobs=cc.ncpu, random_state=0)
gbr = GBR(n_estimators=1000, random_state=0)
xgr = xgb.XGBRegressor()
mtr = RFR() # meta regressor
regressors = [rfr, gbr, xgr]
model = StackingRegressor(regressors=regressors, meta_regressor=mtr)
param_grid = {
'fs__threshold': ['median'],
'fs__estimator__max_features': ['log2'],
'clf__rfr__max_features': ['auto', 'log2'],
'clf__gbr__learning_rate': [0.05, 0.02, 0.01],
'clf__gbr__max_depth': [4, 5, 6, 7],
'clf__gbr__max_features': ['auto', 'log2'],
'clf__gbr__n_estimators': [500, 1000, 2000],
'clf__xgr__learning_rate': [0.001, 0.05, 0.1, 0.2],
'clf__xgr__max_depth': [2, …Run Code Online (Sandbox Code Playgroud) 我正在使用一个sklearn.pipeline.Pipeline对象来进行聚类.
pipe = sklearn.pipeline.Pipeline([('transformer1': transformer1),
('transformer2': transformer2),
('clusterer': clusterer)])
Run Code Online (Sandbox Code Playgroud)
然后我通过使用轮廓分数来评估结果.
sil = preprocessing.silhouette_score(X, y)
Run Code Online (Sandbox Code Playgroud)
我想知道如何X从管道获取或转换数据,因为它只返回clusterer.fit_predict(X).
我知道我可以通过将管道拆分为:
pipe = sklearn.pipeline.Pipeline([('transformer1': transformer1),
('transformer2': transformer2)])
X = pipe.fit_transform(data)
res = clusterer.fit_predict(X)
sil = preprocessing.silhouette_score(X, res)
Run Code Online (Sandbox Code Playgroud)
但我想在一个管道中完成所有工作.