我想将命令的输出通过管道传输到文件:
PS C:\Temp> create-png > binary.png
Run Code Online (Sandbox Code Playgroud)
我注意到 Powershell 更改了编码,并且我可以手动给出编码:
PS C:\Temp> create-png | Out-File "binary.png" -Encoding OEM
Run Code Online (Sandbox Code Playgroud)
然而,没有 RAW 编码选项,即使 OEM 选项也会将换行字节 ( 0xAresp 0xD) 更改为 Windows 换行字节序列 ( 0xD 0xA),从而破坏任何二进制格式。
如何防止 Powershell 在管道传输到文件时更改编码?
相关问题
我有两个阶段的数据:
import numpy as np
data_pre = np.array([[1., 2., 203.],
[0.5, np.nan, 208.]])
data_post = np.array([[2., 2., 203.],
[0.5, 2., 208.]])
Run Code Online (Sandbox Code Playgroud)
我还有两个预先存在的拟合估算器:
from sklearn.preprocessing import Imputer
from sklearn.ensemble import GradientBoostingRegressor
imp = Imputer(missing_values=np.nan, strategy='mean', axis=1).fit(data_pre)
gbm = GradientBoostingRegressor().fit(data_post[:,:2], data_post[:,2])
Run Code Online (Sandbox Code Playgroud)
我需要将一个合适的管道传递data_pre给另一个函数。
def the_function_i_need(estimators):
"""
"""
return fitted pipeline
fitted_pipeline = the_function_i_need([imp, gbm])
sweet_output = static_function(fitted_pipeline, data_pre)
Run Code Online (Sandbox Code Playgroud)
有没有办法将这两个现有的和拟合的模型对象组合到拟合的管道中,而无需重新拟合模型,还是我运气不好?
给定一个类似于“A|B|C|D|E”的管道,我想让步骤 C 以步骤 B 的结果为条件。如下所示:
A | B | if [ $? -ne 0 ]; then C; else cat; fi | D | E
Run Code Online (Sandbox Code Playgroud)
但这似乎不起作用;无论 B 的结果如何,C 都不会被执行。我正在寻找更好的解决方案。
据我了解,管道的每个步骤都在其自己的子 shell 中运行。所以我无法将环境变量传递回管道。但这个管道处于 Gnu Parallel 环境中,其中许多这样的管道同时运行,并且它们都不知道任何唯一值(它们只是处理数据流,不需要知道源,父脚本处理必要的分离)。这意味着使用临时文件也不实用,因为没有任何方法可以使文件名唯一。即使 $$ 似乎也没有给我每个步骤中相同的值。
我有一个保存的 PipelineModel:
pipe_model = pipe.fit(df_train)
pipe_model.write().overwrite().save("/user/pipe_text_2")
Run Code Online (Sandbox Code Playgroud)
现在我想向此管道添加一个新的已安装的 PipelineModel:
pipe_model = PipelineModel.load("/user/pipe_text_2")
df2 = pipe_model.transform(df1)
kmeans = KMeans(k=20)
pipe2 = Pipeline(stages=[kmeans])
pipe_model2 = pipe2.fit(df2)
Run Code Online (Sandbox Code Playgroud)
不用重新装也可以吗?为了获得一个新的PipelineModel但不是一个新的Pipeline。理想的情况如下:
pipe_model_new = pipe_model + pipe_model2
TypeError: unsupported operand type(s) for +: 'PipelineModel' and 'PipelineModel'
Run Code Online (Sandbox Code Playgroud)
我发现将两个 Spark mllib 管道连接在一起,但是使用此解决方案,您需要再次安装整个管道。这就是我试图避免的。
我试图通过管道将两个参数传递给函数,但它似乎没有按预期工作,我很难理解为什么。
function Test-Pipeline {
[CmdletBinding ()]
Param(
[Parameter(ValueFromPipeline=$true)][String]$Name,
[Parameter(ValueFromPipeline=$true)][String]$Value
)
Write-Host "Name: $Name"
Write-Host "Value: $Value"
}
"Name", "Value" | Test-Pipeline
Run Code Online (Sandbox Code Playgroud)
名称: 值
价值:价值
我尝试运行Trace-Command命令来查看发生了什么。在第 35 行我们可以看到Value绑定到$Parameter。
为什么 PowerShell 将第二个输入绑定到两个参数?如果这是预期的,为什么它只发生在第二个参数而不是第一个参数上?
DEBUG: ParameterBinding Information: 0 : BIND NAMED cmd line args [Test-Pipeline]
DEBUG: ParameterBinding Information: 0 : BIND POSITIONAL cmd line args [Test-Pipeline]
DEBUG: ParameterBinding Information: 0 : MANDATORY PARAMETER CHECK on cmdlet [Test-Pipeline]
DEBUG: ParameterBinding Information: 0 : BIND arg [] …Run Code Online (Sandbox Code Playgroud) 在 Azure DevOps 发布管道中使用 system.debug=true 运行 Azure Powershell 任务时,您将获得类似于以下内容的输出:
# anonymized
...
2019-09-05T12:19:41.8983585Z ##[debug]INPUT_CONNECTEDSERVICENAMEARM: '7dd40b2a-1c37-4c0a-803e-9b0044a8b54e'
2019-09-05T12:19:41.9156487Z ##[debug]ENDPOINT_URL_7dd40b2a-1c37-4c0a-803e-9b0044a8b54e: 'https://management.azure.com/'
2019-09-05T12:19:41.9188051Z ##[debug]ENDPOINT_AUTH_7dd40b2a-1c37-4c0a-803e-9b0044a8b54e: '********'
2019-09-05T12:19:41.9221892Z ##[debug]ENDPOINT_DATA_7dd40b2a-1c37-4c0a-803e-9b0044a8b54e: '{"subscriptionId":"b855f753-d5b3-48f4-b7cd-5beb58fb5508","subscriptionName":"Entenhausen","environment":"AzureCloud","creationMode":"Automatic","azureSpnRoleAssignmentId":"5ddcc3fe-f93c-4771-8041-50b49f76b828","azureSpnPermissions":"[{\"roleAssignmentId\":\"5ddcc3fe-f93c-4771-8041-50b49f76b828\",\"resourceProvider\":\"Microsoft.RoleAssignment\",\"provisioned\":true}]","spnObjectId":"76055cb6-3b75-4191-9309-306b32dad443","appObjectId":"e4b90b9d-7a73-42a3-ae6e-4daec910def4","environmentUrl":"https://management.azure.com/","galleryUrl":"https://gallery.azure.com/","serviceManagementUrl":"https://management.core.windows.net/","resourceManagerUrl":"https://management.azure.com/","activeDirectoryAuthority":"https://login.microsoftonline.com/","environmentAuthorityUrl":"https://login.windows.net/","graphUrl":"https://graph.windows.net/","managementPortalUrl":"https://manage.windowsazure.com/","armManagementPortalUrl":"https://portal.azure.com/","activeDirectoryServiceEndpointResourceId":"https://management.core.windows.net/","sqlDatabaseDnsSuffix":".database.windows.net","AzureKeyVaultDnsSuffix":"vault.azure.net","AzureKeyVaultServiceEndpointResourceId":"https://vault.azure.net","StorageEndpointSuffix":"core.windows.net","EnableAdfsAuthentication":"false"}'
2019-09-05T12:19:41.9284444Z ##[debug]AuthScheme ServicePrincipal
...
Run Code Online (Sandbox Code Playgroud)
我需要将 Azure DevOps 连接的 SPN 添加到资源。更改订阅或管道时,SPN 也会更改,我不想对该值进行硬编码。由于该值打印在 system.debug=true 输出中,我想知道如何在管道任务中访问我自己的 SPN。是否可以spnObjectId":"76055cb6-3b75-4191-9309-306b32dad443"使用 Powershell 以某种方式读出?
我可能在这里遗漏了一些非常基本的东西,但我无法弄清楚它是什么。
我有一些非常基本的代码如下:
let myList = [1; 3; 5; 7; 5; 3; 9; 5; 2; 5; 3; 8]
let fiveOrLess = myList |> List.choose (fun number ->
match number with
| number when number <= 5 -> Some number
| _ -> None)
Run Code Online (Sandbox Code Playgroud)
......正如预期的那样,效果很好。
但是,在下面的代码中,我将“myList”从管道移动到只是一个“普通”参数,我从编译器收到两条错误消息:
let myList = [1; 3; 5; 7; 5; 3; 9; 5; 2; 5; 3; 8]
let fiveOrLess = List.choose (fun number ->
match number with
| number when number <= 5 -> Some number
| _ …Run Code Online (Sandbox Code Playgroud) 我正在尝试在我的 Azure DevOps Pipeline 中在线发布详细报告,但我得到的只是一个下载此 Coverage 文件的链接。(自 Visual Studio 2019 以来,社区版本无法再读取该内容)

这是我的管道:
trigger:
branches:
include:
- '*'
pool:
vmImage: 'windows-2019'
steps:
- task: NuGetToolInstaller@0
displayName: Instal Nuget
inputs:
checkLatest: true
- task: NuGetCommand@2
displayName: Restore Nuget Packages
inputs:
restoreSolution: '**/*.sln'
- task: UseDotNet@2
displayName: 'Install .NET Core SDK'
inputs:
version: 3.1.x
performMultiLevelLookup: true
- task: DotNetCoreCLI@2
displayName: Build Tests
inputs:
command: 'build'
projects: '**/OneTienditaUnitTests/*.csproj'
arguments: '--configuration Release'
- script: dotnet test OneTienditaUnitTests --logger trx --collect "Code coverage"
- task: PublishTestResults@2 …Run Code Online (Sandbox Code Playgroud) pipeline code-coverage cobertura azure-devops azure-pipelines
我正在使用 sklearn 的管道转换器实现预处理管道。我的管道包括 sklearn 的 KNNImputer 估计器,我想用它来估算数据集中的分类特征。(我的问题类似于这个线程,但它不包含我的问题的答案:How to implement KNN to impute categorical features in a sklearn pipeline)
我知道分类特征必须在插补之前编码,这就是我遇到麻烦的地方。使用标准标签/序数/onehot 编码器,当尝试使用缺失值 (np.nan) 对分类特征进行编码时,您会收到以下错误:
ValueError: Input contains NaN
Run Code Online (Sandbox Code Playgroud)
我设法通过创建一个自定义编码器来“绕过”它,我将 np.nan 替换为“Missing”:
class CustomEncoder(BaseEstimator, TransformerMixin):
def __init__(self):
self.encoder = None
def fit(self, X, y=None):
self.encoder = OrdinalEncoder()
return self.encoder.fit(X.fillna('Missing'))
def transform(self, X, y=None):
return self.encoder.transform(X.fillna('Missing'))
def fit_transform(self, X, y=None, **fit_params):
self.encoder = OrdinalEncoder()
return self.encoder.fit_transform(X.fillna('Missing'))
preprocessor = ColumnTransformer([
('categoricals', CustomEncoder(), cat_features),
('numericals', StandardScaler(), num_features)],
remainder='passthrough'
)
pipeline = Pipeline([
('preprocessing', preprocessor), …Run Code Online (Sandbox Code Playgroud) 我在过滤模型中最不重要的变量时遇到了困难。我收到了一组包含 4,000 多个变量的数据,我被要求减少进入模型的变量数量。
我确实尝试过两种方法,但我失败了两次。
我尝试的第一件事是在建模后手动检查变量重要性,并在此基础上删除不重要的变量。
# reproducible example
data <- iris
# artificial class imbalancing
data <- iris %>%
mutate(Species = as.factor(ifelse(Species == "virginica", "1", "0")))
Run Code Online (Sandbox Code Playgroud)
使用 simple 时一切正常Learner:
# creating Task
task <- TaskClassif$new(id = "score", backend = data, target = "Species", positive = "1")
# creating Learner
lrn <- lrn("classif.xgboost")
# setting scoring as prediction type
lrn$predict_type = "prob"
lrn$train(task)
lrn$importance()
Petal.Width Petal.Length
0.90606304 0.09393696
Run Code Online (Sandbox Code Playgroud)
问题是数据高度不平衡,所以我决定使用GraphLearnerwithPipeOp运算符来对多数组进行欠采样,然后将其传递给AutoTuner:
我确实跳过了我认为对这种情况不重要的代码的某些部分,例如搜索空间、终止符、调谐器等。
# undersampling
po_under …Run Code Online (Sandbox Code Playgroud) pipeline ×10
powershell ×3
azure-devops ×2
encoding ×2
parameters ×2
scikit-learn ×2
apache-spark ×1
azure ×1
bash ×1
cobertura ×1
environment ×1
f# ×1
imputation ×1
mlr3 ×1
pipe ×1
pyspark ×1
python ×1
r ×1
xgboost ×1