保存没有数据集的 scikit-learn 模型
我已经使用 sklearn 库训练了 RandomForestClassifier 模型,并将其保存在 joblib 中。现在,我有一个近 1GB 的 joblib 文件,正在将其部署在 Nginx/Flask/Guincorn 堆栈上。问题是我必须找到一种有效的方法来从文件加载此模型并服务 API 请求。执行以下操作时是否可以在没有数据集的情况下保存模型:
joblib.dump(model, '/kaggle/working/mymodel.joblib')
print("random classifier saved")
I've trained a RandomForestClassifier model with the sklearn library and saved it with joblib. Now, I have a joblib file of nearly 1GB which I'm deploying on a Nginx/Flask/Guincorn stack. The issue is I have to find an efficient way to load this model from file and serve API requests. Is it possible to save the model without the datasets when doing:
joblib.dump(model, '/kaggle/working/mymodel.joblib')
print("random classifier saved")
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
Scikit-Learn 估计器的持久表示不包含任何训练数据。
谈到决策树及其集合(例如随机森林),估计器对象的大小与决策树的深度(即 max_depth 参数)呈二次方缩放。之所以如此,是因为决策树配置是使用
(max_depth, max_depth)
矩阵(float64
数据类型)表示的。您可以通过限制
max_depth
参数来缩小随机森林对象。如果您担心预测性能可能会下降,则可以增加子估计器的数量。从长远来看,您可能希望探索 Scikit-Learn 模型的替代表示形式。例如,使用 SkLearn2PMML 包将它们转换为 PMML 数据格式。
The persistent representation of Scikit-Learn estimators DOES NOT include any training data.
Speaking about decision trees and their ensembles (such as random forests), then the size of the estimator object scales quadratically to the depth of decision trees (ie. the
max_depth
parameter). This is so, because decision tree configuration is represented using(max_depth, max_depth)
matrices (float64
data type).You can make your random forest objects smaller by limiting the
max_depth
parameter. If you're worried about potential loss of predictive performance, you may increase the number of child estimators.Longer term, you may wish to explore alternative representations for Scikit-Learn models. For example, converting them to PMML data format using the SkLearn2PMML package.