python - 使用带有 sklearn 和 pickle 的随机森林循环预测
问题描述
我在 Python3.6 上使用 sci-kit learn,并且在从 Pickle 加载的随机森林循环中进行预测时遇到了一些运行时问题。
当我从具有 1 个估计器(树)的随机森林进行预测时,每个样本的运行时间约为 0.002 秒。但是,当我增加估计器的数量(>1)时,无论树的数量如何,运行时间都会增加到每个样本 0.1 秒。
这是我保存模型的代码:
clf = RandomForestClassifier(n_estimators=1, #or > 1
n_jobs=-1,
random_state=2,
max_depth=15,
min_samples_leaf=1,
verbose=0,
max_features='auto'
)
clf.fit(X_train, y_train)
with open('classifier.pkl', 'wb') as fid:
cPickle.dump(clf, fid)
这是我在循环中加载模型和预测的代码:
with open('classifier.pkl', 'rb') as fid:
clf = cPickle.load(fid)
for s in samples:
#my feature extraction method
pred = clf.predict(feature) #feature is a 1D np array containing features computed for the sample s
我不明白为什么运行时间与树的数量不成正比,以及为什么它增长得如此之快。这是一个错误还是我以错误的方式使用泡菜?
拜托,你能帮帮我吗?
CB
解决方案
推荐阅读
- ios - iOS 13 中的secondaryAudioShouldBeSilencedHint 问题
- mysql - 匹配所有值 "IN" sql 查询
- reactjs - 反应 .getBoundingClientRect 不起作用
- javascript - 为什么我的输出是 NaN?在 excel 上,程序输出一个有限的数字。调用所有数学奇才
- html - 安装 React Bootstrap 后如何删除边距
- javascript - 具有这种路由结构时如何将道具传递给每个组件
- javascript - JavaScript/JQuery 发布订阅不在两个页面之间工作,但在下面代码中的页面内工作
- android - 无法摆脱 Crashlytics 在复杂项目中引发的错误
- azure - 设置逻辑应用时错误请求无效主机
- spotfire - 配置 Spotfire 7.02 显示引擎