保存没有数据集的 scikit-learn 模型

发布于 2025-01-16 16:54:47 字数 298 浏览 3 评论 0原文

我已经使用 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

滥情空心 2025-01-23 16:54:47

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文