gpt4 book ai didi

Python 随机森林 sklearn : stuck for a few hours, 是怎么回事?

转载 作者:太空宇宙 更新时间:2023-11-04 10:03:49 25 4
gpt4 key购买 nike

我有一个很大的输入向量。目前,它一直停留在运行 calibrated_clf.fit(x_train, y_train) 几个小时。我不知道程序是死了还是什么。在 calibrated_clf.fit(x_train, y_train) 函数调用中运行时,如何打印出某种进度?

clf = ensemble.RandomForestClassifier(criterion = 'entropy', n_estimators = 350, max_features = 200,n_jobs=-1)
calibrated_clf = CalibratedClassifierCV(clf, method='isotonic')
print "Here 1"
calibrated_clf.fit(x_train, y_train)
print "Here 2"

x_train 是一个大小为 (51733, 250) 的向量。我在打印输出上停留在“这里 1”几个小时。

最佳答案

您可以简单地将 verbose 设置为高于 0 的值。

来自

from sklearn.externals import joblib
help(joblib.parallel)

verbose: int, optional The verbosity level: if non zero, progress messages are printed. Above 50, the output is sent to stdout. The frequency of the messages increases with the verbosity level. If it more than 10, all iterations are reported.

RandomForestClassifier 使用 joblib 库中的 parallel 函数。

import numpy
from sklearn.datasets import make_blobs
from sklearn.ensemble import RandomForestClassifier

n = 1000

X, y = make_blobs(n_samples=n)
X_train, y_train = X[0:n // 2], y[0:n // 2]
X_valid, y_valid = X[n // 2:], y[n // 2:]

clf = RandomForestClassifier(n_estimators=350, verbose=100)
clf.fit(X_train, y_train)

输出

building tree 1 of 350
[Parallel(n_jobs=1)]: Done 1 out of 1 | elapsed: 0.0s remaining: 0.0s
building tree 2 of 350
[Parallel(n_jobs=1)]: Done 2 out of 2 | elapsed: 0.0s remaining: 0.0s
building tree 3 of 350
[Parallel(n_jobs=1)]: Done 3 out of 3 | elapsed: 0.0s remaining: 0.0s
building tree 4 of 350
[Parallel(n_jobs=1)]: Done 4 out of 4 | elapsed: 0.0s remaining: 0.0s
building tree 5 of 350

[...]

building tree 100 of 350
building tree 101 of 350
building tree 102 of 350
building tree 103 of 350
building tree 104 of 350
[...]
building tree 350 of 350
[Parallel(n_jobs=1)]: Done 350 out of 350 | elapsed: 1.6s finished

关于Python 随机森林 sklearn : stuck for a few hours, 是怎么回事?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42036780/

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