gpt4 book ai didi

python - 从 Scikit 学习的预测中抑制控制台消息

转载 作者:太空狗 更新时间:2023-10-30 00:55:07 26 4
gpt4 key购买 nike

我已经使用 Scikit learn 构建了预测模型。我已经用 Flask、joblib 部署了这个模型。每当我预测带有加载模型的新传入请求时,它都会在控制台上打印有关内核占用的总时间的消息。

现在,我想禁用此打印。我如何在模型预测新传入数据时抑制给定消息。

[Parallel(n_jobs=24)]: Done 117 out of 174 | elapsed:    0.0s remaining:    0.0s
[Parallel(n_jobs=24)]: Done 121 out of 179 | elapsed: 0.0s remaining: 0.0s
[Parallel(n_jobs=24)]: Done 122 out of 181 | elapsed: 0.0s remaining: 0.0s
[Parallel(n_jobs=24)]: Done 123 out of 183 | elapsed: 0.0s remaining: 0.0s
[Parallel(n_jobs=24)]: Done 125 out of 185 | elapsed: 0.0s remaining: 0.0s
[Parallel(n_jobs=24)]: Done 127 out of 188 | elapsed: 0.0s remaining: 0.0s
[Parallel(n_jobs=24)]: Done 128 out of 190 | elapsed: 0.0s remaining: 0.0s
[Parallel(n_jobs=24)]: Done 129 out of 192 | elapsed: 0.0s remaining: 0.0s
[Parallel(n_jobs=24)]: Done 132 out of 196 | elapsed: 0.0s remaining: 0.0s
[Parallel(n_jobs=24)]: Done 133 out of 198 | elapsed: 0.0s remaining: 0.0s
[Parallel(n_jobs=24)]: Done 135 out of 201 | elapsed: 0.0s remaining: 0.0s
[Parallel(n_jobs=24)]: Done 137 out of 204 | elapsed: 0.0s remaining: 0.0s
[Parallel(n_jobs=24)]: Done 138 out of 205 | elapsed: 0.0s remaining: 0.0s
[Parallel(n_jobs=24)]: Done 140 out of 208 | elapsed: 0.0s remaining: 0.0s
[Parallel(n_jobs=24)]: Done 143 out of 213 | elapsed: 0.0s remaining: 0.0s
[Parallel(n_jobs=24)]: Done 148 out of 220 | elapsed: 0.0s remaining: 0.0s
[Parallel(n_jobs=24)]: Done 149 out of 222 | elapsed: 0.0s remaining: 0.0s
[Parallel(n_jobs=24)]: Done 153 out of 228 | elapsed: 0.1s remaining: 0.0s
[Parallel(n_jobs=24)]: Done 155 out of 231 | elapsed: 0.1s remaining: 0.0s
[Parallel(n_jobs=24)]: Done 159 out of 237 | elapsed: 0.1s remaining: 0.0s
[Parallel(n_jobs=24)]: Done 165 out of 246 | elapsed: 0.1s remaining: 0.0s
[Parallel(n_jobs=24)]: Done 168 out of 250 | elapsed: 0.1s remaining: 0.0s
[Parallel(n_jobs=24)]: Done 169 out of 252 | elapsed: 0.1s remaining: 0.0s
[Parallel(n_jobs=24)]: Done 171 out of 255 | elapsed: 0.1s remaining: 0.0s
[Parallel(n_jobs=24)]: Done 173 out of 258 | elapsed: 0.1s remaining: 0.0s
[Parallel(n_jobs=24)]: Done 177 out of 264 | elapsed: 0.1s remaining: 0.0s
[Parallel(n_jobs=24)]: Done 181 out of 270 | elapsed: 0.1s remaining: 0.0s
[Parallel(n_jobs=24)]: Done 183 out of 273 | elapsed: 0.1s remaining: 0.0s
[Parallel(n_jobs=24)]: Done 185 out of 276 | elapsed: 0.1s remaining: 0.0s
[Parallel(n_jobs=24)]: Done 187 out of 279 | elapsed: 0.1s remaining: 0.0s
[Parallel(n_jobs=24)]: Done 335 out of 500 | elapsed: 0.3s remaining: 0.1s
[Parallel(n_jobs=24)]: Done 500 out of 500 | elapsed: 0.3s finished

最佳答案

我在使用 sklearn.linear_model.LinearRegression 时遇到了类似的提示。在这个方法中,我可以在 .fit() 方法或构造函数中找到没有冗长的参数。所以python代码:

import numpy as np
from sklearn.linear_model import LinearRegression as LR

lr = LR()
y = np.random.rand(100) + 0.01 * np.arange(100) # noisy line to fit
x = np.arange(100)
x = np.reshape(y,[100,1])
lr.fit(x,y)

我得到了烦人的输出:

LinearRegression(copy_X=True, fit_intercept=True, n_jobs=1, normalize=False)

因为 fit() 方法返回一个指向自身的指针,而这个文本代表那个对象。一种抑制这种情况的简单方法是将上面的代码修改为:

a = lr.fit(x,y)

从而将指针分配给某个变量而不是您的屏幕。

关于python - 从 Scikit 学习的预测中抑制控制台消息,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31252787/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com