当我运行这段代码时:
from sklearn import cross_validation
bs = cross_validation.Bootstrap(9, random_state=0)我收到了这个弃用警告:
C:\Anaconda\envs\p33\lib\site-packages\sklearn\cross_validation.py:684: DeprecationWarning: Bootstrap will no longer be supported as a cross-validation method as of version 0.15 and will be removed in 0.17
"will be removed in 0.17", DeprecationWarning)我应该用什么代替bootstrap?
发布于 2015-01-20 01:27:41
来自the scikit-learn 0.15 release notes,在"API更改摘要“下
cross_validation.Bootstrap已弃用。建议使用cross_validation.KFold或cross_validation.ShuffleSplit。# See, e.g., http://youtu.be/BzHz0J9a6k0?t=9m38s for a motivation
# behind this deprecation
warnings.warn("Bootstrap will no longer be supported as a " +
"cross-validation method as of version 0.15 and " +
"will be removed in 0.17", DeprecationWarning)发布于 2017-07-21 22:18:21
您可以使用BaggingClassifier
bag = BaggingClassifier(base_estimator=your_estimator,
n_estimators=100,
max_samples=1.0,
bootstrap=True,
n_jobs=-1)
bag.fit(X, y)
recalls = []
for estimator, samples in zip(bag.estimators_, bag.estimators_samples_):
# compute predictions on out-of-bag samples
mask = ~samples
y_pred = estimator.predict(X[mask])
# compute some statistic
recalls.append(recall(y[mask], y_pred))
# Do something with stats, e.g. find confidence interval
print(np.percentile(recalls, [2.5, 97.5]))发布于 2021-03-05 07:53:23
我刚刚遇到了这个问题,我找到的解决方案(从scikit-learn 0.24开始)是使用重采样实用程序。
from sklearn.utils import resample这将为每个调用生成一个引导步骤,使用默认参数,这些参数通过替换进行采样。
https://scikit-learn.org/stable/modules/generated/sklearn.utils.resample.html
https://stackoverflow.com/questions/28030291
复制相似问题